#!/usr/bin/env node const fs = require('fs'); const argparse = require('argparse'); const markdownIt = require('markdown-it'); const markdownItTaskCheckbox = require('markdown-it-task-checkbox'); const markdownItEmoji = require('markdown-it-emoji'); const markdownItHeaderAnchors = require('./markdown-it-header-anchors'); const Prism = require('prismjs'); const loadPrismLanguages = require('prismjs/components/'); let parser = new argparse.ArgumentParser(); parser.addArgument('inputFile', { nargs: argparse.Const.OPTIONAL, metavar: 'INPUT_FILE', help: '(stdin by default)', }); parser.addArgument('outputFile', { nargs: argparse.Const.OPTIONAL, metavar: 'OUTPUT_FILE', help: '(stdout by default)', }); let args = parser.parseArgs(); let md = markdownIt({ html: true, linkify: true, highlight: (str, lang) => { if (lang.length > 0) { loadPrismLanguages([lang]); if (Object.prototype.hasOwnProperty.call(Prism.languages, lang)) { return Prism.highlight(str, Prism.languages[lang], lang); } } return str; }, }); md.use(markdownItTaskCheckbox); md.use(markdownItEmoji); md.use(markdownItHeaderAnchors); let markdownDocument = fs.readFileSync(args.get('inputFile', 0), 'utf-8'); let renderedMarkdown = md.render(markdownDocument); let githubMarkdownCSS = fs.readFileSync( require.resolve('github-markdown-css/github-markdown.css'), ); let syntaxHighlightingThemeCSS = fs.readFileSync( require.resolve('prismjs/themes/prism.css'), ); let renderedHtmlDocument = `