diff --git a/script-resources/markdown2htmldoc/.eslintrc.yml b/script-resources/markdown2htmldoc/.eslintrc.yml
new file mode 100644
index 0000000..6497cae
--- /dev/null
+++ b/script-resources/markdown2htmldoc/.eslintrc.yml
@@ -0,0 +1,5 @@
+extends:
+ - eslint-config-dmitmel/presets/node
+ - eslint-config-dmitmel/presets/formatting
+rules:
+ node/shebang: off
diff --git a/script-resources/markdown2htmldoc/github-markdown-additions.css b/script-resources/markdown2htmldoc/github-markdown-additions.css
new file mode 100644
index 0000000..15b26fd
--- /dev/null
+++ b/script-resources/markdown2htmldoc/github-markdown-additions.css
@@ -0,0 +1,11 @@
+html,
+body {
+ padding: 0;
+ margin: 0;
+}
+
+.markdown-body {
+ max-width: 882px;
+ margin: 0 auto;
+ padding: 32px;
+}
diff --git a/script-resources/markdown2htmldoc/main.js b/script-resources/markdown2htmldoc/main.js
index e69d911..53fe9dc 100755
--- a/script-resources/markdown2htmldoc/main.js
+++ b/script-resources/markdown2htmldoc/main.js
@@ -7,19 +7,48 @@ 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 PRISM_COMPONENTS = require('prismjs/components.js');
const loadPrismLanguages = require('prismjs/components/');
+// TODO: integrate
+const PRISM_THEMES = Object.keys(PRISM_COMPONENTS.themes).filter(
+ (k) => k !== 'meta',
+);
+
let parser = new argparse.ArgumentParser();
-parser.addArgument('inputFile', {
+
+parser.addArgument('INPUT_FILE', {
nargs: argparse.Const.OPTIONAL,
- metavar: 'INPUT_FILE',
help: '(stdin by default)',
});
-parser.addArgument('outputFile', {
+parser.addArgument('OUTPUT_FILE', {
nargs: argparse.Const.OPTIONAL,
- metavar: 'OUTPUT_FILE',
help: '(stdout by default)',
});
+
+parser.addArgument('--input-encoding', {
+ defaultValue: 'utf-8',
+ help: '(utf-8 by default)',
+});
+parser.addArgument('--output-encoding', {
+ defaultValue: 'utf-8',
+ help: '(utf-8 by default)',
+});
+
+parser.addArgument('--no-default-stylesheets', {
+ nargs: argparse.Const.SUPPRESS,
+});
+parser.addArgument('--syntax-theme', {
+ choices: PRISM_THEMES,
+});
+
+parser.addArgument('--stylesheet', {
+ nargs: argparse.Const.ZERO_OR_MORE,
+});
+parser.addArgument('--script', {
+ nargs: argparse.Const.ZERO_OR_MORE,
+});
+
let args = parser.parseArgs();
let md = markdownIt({
@@ -39,14 +68,47 @@ md.use(markdownItTaskCheckbox);
md.use(markdownItEmoji);
md.use(markdownItHeaderAnchors);
-let markdownDocument = fs.readFileSync(args.get('inputFile', 0), 'utf-8');
+let markdownDocument = fs.readFileSync(
+ args.get('INPUT_FILE', 0),
+ args.get('input_encoding'),
+);
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 stylesheetsTexts = [];
+let scriptsTexts = [];
+let syntaxThemeName = null;
+
+if (!args.get('no_default_stylesheets')) {
+ syntaxThemeName = 'prism';
+ stylesheetsTexts.push(
+ fs.readFileSync(
+ require.resolve('github-markdown-css/github-markdown.css'),
+ 'utf-8',
+ ),
+ fs.readFileSync(
+ require.resolve('./github-markdown-additions.css'),
+ 'utf-8',
+ ),
+ );
+}
+
+syntaxThemeName = args.get('syntax_theme') || syntaxThemeName;
+if (syntaxThemeName) {
+ stylesheetsTexts.push(
+ fs.readFileSync(
+ require.resolve(`prismjs/themes/${syntaxThemeName}.css`),
+ 'utf-8',
+ ),
+ );
+}
+
+for (let stylesheetPath of args.get('stylesheet', [])) {
+ stylesheetsTexts.push(fs.readFileSync(stylesheetPath));
+}
+
+for (let scriptPath of args.get('script', [])) {
+ scriptsTexts.push(fs.readFileSync(scriptPath));
+}
let renderedHtmlDocument = `
@@ -55,43 +117,19 @@ let renderedHtmlDocument = `
-
-
-
+${stylesheetsTexts.map((s) => ``).join('\n')}
${renderedMarkdown}
+${scriptsTexts.map((s) => ``).join('\n')}