UNPKG

@vivliostyle/vfm

Version:

Custom Markdown syntax specialized in book authoring.

82 lines (81 loc) 2.83 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var fs_1 = __importDefault(require("fs")); var meow_1 = __importDefault(require("meow")); var readline_1 = __importDefault(require("readline")); var _1 = require("."); var cli = (0, meow_1.default)("\n Usage\n $ vfm <filename>\n $ echo <string> | vfm\n \n Options\n --style, -s Custom stylesheet path/URL\n --partial, -p Output markdown fragments\n --title Document title (ignored in partial mode)\n --language Document language (ignored in partial mode)\n --hard-line-breaks Add <br> at the position of hard line breaks, without needing spaces\n --disable-format-html Disable automatic HTML format\n --disable-math Disable math syntax\n \n Examples\n $ vfm input.md\n", { flags: { style: { type: 'string', alias: 's', isMultiple: true, }, partial: { type: 'boolean', alias: 'p', }, title: { type: 'string', }, language: { type: 'string', }, hardLineBreaks: { type: 'boolean', }, disableFormatHtml: { type: 'boolean', }, disableMath: { type: 'boolean', }, }, }); function compile(input) { // eslint-disable-next-line no-console console.log((0, _1.stringify)(input, { partial: cli.flags.partial, style: cli.flags.style, title: cli.flags.title, language: cli.flags.language, hardLineBreaks: cli.flags.hardLineBreaks, disableFormatHtml: cli.flags.disableFormatHtml, math: cli.flags.disableMath === undefined ? true : !cli.flags.disableMath, })); } function main(cli) { try { var filepath = cli.input[0]; if (filepath) { return compile(fs_1.default.readFileSync(filepath).toString()); } var buffer_1 = ''; var rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout, terminal: false, }); rl.on('pause', function () { compile(buffer_1); buffer_1 = ''; }); rl.on('line', function (line) { if (line === 'EOD') { compile(buffer_1); buffer_1 = ''; return; } buffer_1 += line + '\n'; }); } catch (err) { // eslint-disable-next-line no-console console.log(err); } } main(cli);