forked from KaTeX/KaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·32 lines (26 loc) · 935 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
// Simple CLI for KaTeX.
// Reads TeX from stdin, outputs HTML to stdout.
/* eslint no-console:0 */
const katex = require("./");
let input = "";
// Skip the first two args, which are just "node" and "cli.js"
const args = process.argv.slice(2);
if (args.indexOf("--help") !== -1) {
console.log(process.argv[0] + " " + process.argv[1] +
" [ --help ]" +
" [ --display-mode ]");
console.log("\n" +
"Options:");
console.log(" --help Display this help message");
console.log(" --display-mode Render in display mode (not inline mode)");
process.exit();
}
process.stdin.on("data", function(chunk) {
input += chunk.toString();
});
process.stdin.on("end", function() {
const options = { displayMode: args.indexOf("--display-mode") !== -1 };
const output = katex.renderToString(input, options);
console.log(output);
});