This repository has been archived on 2025-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
noteApp/compile.js
2020-07-28 15:31:39 +02:00

41 lines
900 B
JavaScript
Executable File

const fs = require('fs')
module.exports = compile
function compile(page, fn){
switch(page.type){
case 'md':
compileMD(page.file, fn)
break;
default:
fn(-2)
}
}
/* =============================================================
* === Markdown ================================================
* =============================================================
*/
const showdown = require('showdown')
const MDCompile = new showdown.Converter({tables: true})
function compileMD(file, fn){
fs.readFile(file, 'utf-8', function(err, markdown){
if(err){
console.error("ERROR: could not read file:", file)
if(typeof fn == 'function')
fn(-1)
}
html = MDCompile.makeHtml(markdown);
if(typeof fn == 'function')
fn(html)
else
fs.writeFile(fn, html, function(err){
if(err)
console.error(err)
})
})
}