nizel 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/nizel.mjs +81 -0
- package/dist/browser/nizel.iife.js +4 -0
- package/dist/browser/nizel.js +4 -0
- package/dist/options.js +4 -0
- package/dist/options.js.map +1 -1
- package/package.json +6 -2
package/cli/nizel.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import { useNizel } from '../dist/index.js';
|
|
6
|
+
|
|
7
|
+
const HELP = `Usage: npx nizel <input.md> [options]
|
|
8
|
+
|
|
9
|
+
Options:
|
|
10
|
+
-o, --output <file> Write HTML to a file instead of stdout
|
|
11
|
+
--fragment Output the rendered HTML fragment only (default)
|
|
12
|
+
--document Wrap output in a complete HTML document
|
|
13
|
+
--title <title> Override the document title used with --document
|
|
14
|
+
-h, --help Show this help
|
|
15
|
+
-v, --version Show the installed Nizel version
|
|
16
|
+
|
|
17
|
+
Examples:
|
|
18
|
+
npx nizel report.md
|
|
19
|
+
npx nizel report.md -o report.html --document
|
|
20
|
+
cat report.md | npx nizel - --document > report.html
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
function parseArgs(argv) {
|
|
24
|
+
const options = { input: null, output: null, document: false, title: null };
|
|
25
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
26
|
+
const arg = argv[index];
|
|
27
|
+
if (arg === '-h' || arg === '--help') return { ...options, help: true };
|
|
28
|
+
if (arg === '-v' || arg === '--version') return { ...options, version: true };
|
|
29
|
+
if (arg === '--document') { options.document = true; continue; }
|
|
30
|
+
if (arg === '--fragment') { options.document = false; continue; }
|
|
31
|
+
if (arg === '-o' || arg === '--output') { options.output = argv[++index]; continue; }
|
|
32
|
+
if (arg === '--title') { options.title = argv[++index]; continue; }
|
|
33
|
+
if (arg.startsWith('-') && arg !== '-') throw new Error(`Unknown option: ${arg}`);
|
|
34
|
+
if (options.input) throw new Error('Only one input file is supported.');
|
|
35
|
+
options.input = arg;
|
|
36
|
+
}
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function escapeHtml(value) {
|
|
41
|
+
return String(value)
|
|
42
|
+
.replaceAll('&', '&')
|
|
43
|
+
.replaceAll('<', '<')
|
|
44
|
+
.replaceAll('>', '>')
|
|
45
|
+
.replaceAll('"', '"');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function wrapDocument(html, title) {
|
|
49
|
+
return `<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>${escapeHtml(title || 'Nizel document')}</title>\n</head>\n<body>\n${html}\n</body>\n</html>\n`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function readStdin() {
|
|
53
|
+
const chunks = [];
|
|
54
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
55
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function main() {
|
|
59
|
+
const options = parseArgs(process.argv.slice(2));
|
|
60
|
+
if (options.help) { process.stdout.write(HELP); return; }
|
|
61
|
+
if (options.version) {
|
|
62
|
+
const pkg = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
63
|
+
process.stdout.write(`${pkg.version}\n`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!options.input) throw new Error(`Missing input file.\n\n${HELP}`);
|
|
67
|
+
|
|
68
|
+
const markdown = options.input === '-' ? await readStdin() : await readFile(options.input, 'utf8');
|
|
69
|
+
const rendered = await useNizel()(markdown);
|
|
70
|
+
const html = options.document
|
|
71
|
+
? wrapDocument(rendered.html, options.title || rendered.title || rendered.meta?.title)
|
|
72
|
+
: rendered.html;
|
|
73
|
+
|
|
74
|
+
if (options.output) await writeFile(options.output, html, 'utf8');
|
|
75
|
+
else process.stdout.write(html.endsWith('\n') ? html : `${html}\n`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
main().catch((error) => {
|
|
79
|
+
process.stderr.write(`nizel: ${error.message}\n`);
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
});
|
package/dist/browser/nizel.js
CHANGED
|
@@ -2354,6 +2354,10 @@ function mergeOptions(left, right) {
|
|
|
2354
2354
|
...left.variables ?? {},
|
|
2355
2355
|
...right.variables ?? {}
|
|
2356
2356
|
},
|
|
2357
|
+
meta: {
|
|
2358
|
+
...left.meta ?? {},
|
|
2359
|
+
...right.meta ?? {}
|
|
2360
|
+
},
|
|
2357
2361
|
elements: {
|
|
2358
2362
|
...left.elements ?? {},
|
|
2359
2363
|
...right.elements ?? {}
|
package/dist/options.js
CHANGED
package/dist/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,cAAmC,EAAE,EACrC,iBAAsC,EAAE;IAExC,MAAM,OAAO,GAAG;QACd,GAAG,CAAE,WAAW,CAAC,OAAqC,IAAI,EAAE,CAAC;QAC7D,GAAG,CAAE,cAAc,CAAC,OAAqC,IAAI,EAAE,CAAC;KACjE,CAAC;IAEF,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;QACpE,MAAM,cAAc,GAAG,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACrG,OAAO,YAAY,CAAC,MAAM,EAAE;YAC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KAAK,CAAC,MAAM,IAAI,EAAE,CAAC;SACxB;QACD,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QACrE,QAAQ,EAAE,oBAAoB,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC;KAC9D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAC3B,IAA8B,EAC9B,KAA+B;IAE/B,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAClC,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACxD,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAChD,IAAI,IAAI,KAAK,KAAK;QAAE,IAAI,GAAG,EAAE,CAAC;IAC9B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,KAAK,GAAG,EAAE,CAAC;IACtD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS;QAAE,IAAI,GAAG,EAAE,CAAC;IAEnD,OAAO;QACL,GAAG,IAAI;QACP,GAAG,KAAK;QACR,OAAO,EAAE;YACP,GAAG,cAAc;YACjB,GAAG,IAAI,CAAC,OAAO;YACf,GAAG,KAAK,CAAC,OAAO;SACjB;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nizel",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Markdown content processor for modern applications.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
+
"bin": {
|
|
13
|
+
"nizel": "./cli/nizel.mjs"
|
|
14
|
+
},
|
|
12
15
|
"exports": {
|
|
13
16
|
".": {
|
|
14
17
|
"types": "./dist/index.d.ts",
|
|
@@ -20,7 +23,8 @@
|
|
|
20
23
|
}
|
|
21
24
|
},
|
|
22
25
|
"files": [
|
|
23
|
-
"dist"
|
|
26
|
+
"dist",
|
|
27
|
+
"cli"
|
|
24
28
|
],
|
|
25
29
|
"dependencies": {
|
|
26
30
|
"@sil/case": "^1.0.0",
|