#!/usr/bin/env node
import {marked} from 'marked'
import hljs from 'highlight.js'
import fs from 'node:fs'
import path from 'node:path'
import run from './html2pdf.mjs'
// import 'highlight.js/styles/github.css';
marked.setOptions({
renderer: new marked.Renderer(),
highlight: function(code, lang) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(code, { language }).value;
},
langPrefix: 'hljs language-', // highlight.js css expects a top-level 'hljs' class.
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
});
const filePath = `${process.argv[3]}`
const markdownString = fs.readFileSync(filePath, 'utf8')
const fileName = `${filePath}`.replace('.md','.html')
console.log(fileName)
let html = marked.parse(markdownString)
html = `
${html}`
try {
fs.unlinkSync(fileName);
} catch ( e ) {
console.log(e)
}
fs.writeFile(fileName, html, { flag: 'a+' }, (err) => {
if (err) throw err;
run(fileName)
})
// console.log(marked.parse(markdownString));
// import github from 'highlight.js/styles/github.css'
// const github = fs.readFileSync('highlight.js/styles/github.css', 'utf8')
// console.log(github)