upkram 1.0.7 → 1.0.9
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/README.md +42 -3063
- package/bin/cli.js +96 -6
- package/package.json +16 -1
- package/upkram-all.css +2 -6
- package/upkram-all.js +8 -1
- package/upkram-fa.css +1 -5
- package/upkram-ni.js +2 -1
- package/upkram-nofa.css +1 -1
- package/upkram.d.ts +1 -1
package/bin/cli.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* upkram input.md > out.html
|
|
6
6
|
* cat input.md | upkram > out.html
|
|
7
7
|
* upkram input.md --preset gfm -o out.html
|
|
8
|
+
* upkram lint input.md [--rules r1,r2] [--json] [--quiet]
|
|
9
|
+
* upkram input.md --check # render + lint; exit 1 on error findings
|
|
8
10
|
*
|
|
9
11
|
* Zero dependencies. Requires Node.js >= 14.
|
|
10
12
|
*/
|
|
@@ -20,10 +22,8 @@ var HELP = [
|
|
|
20
22
|
'UpKram ' + VERSION + ' — Markdown / GFM renderer',
|
|
21
23
|
'',
|
|
22
24
|
'Usage',
|
|
23
|
-
' upkram [options] [file]',
|
|
24
|
-
'',
|
|
25
|
-
' Reads Markdown from <file>, or from stdin when <file> is omitted or "-",',
|
|
26
|
-
' and writes rendered HTML to stdout.',
|
|
25
|
+
' upkram [options] [file] Render Markdown to HTML (stdin when no file)',
|
|
26
|
+
' upkram lint [options] <file> Lint a Markdown file',
|
|
27
27
|
'',
|
|
28
28
|
'Options',
|
|
29
29
|
' -o, --output <file> Write to <file> instead of stdout',
|
|
@@ -33,13 +33,38 @@ var HELP = [
|
|
|
33
33
|
' -s, --standalone Wrap the fragment in a complete HTML document',
|
|
34
34
|
' --title <text> <title> for --standalone (default: input file name)',
|
|
35
35
|
' --css <href> Stylesheet link for --standalone',
|
|
36
|
+
' --check Also lint; exit 1 when any error-level finding appears',
|
|
36
37
|
' -h, --help Show this help',
|
|
37
38
|
' -v, --version Print the version',
|
|
38
39
|
'',
|
|
40
|
+
'Lint subcommand options',
|
|
41
|
+
' --rules <list> Comma-separated rule ids to run (default: all)',
|
|
42
|
+
' --json Print diagnostics as JSON',
|
|
43
|
+
' --quiet Suppress output; exit code still reflects findings',
|
|
44
|
+
'',
|
|
39
45
|
'Examples',
|
|
40
46
|
' upkram README.md > README.html',
|
|
41
47
|
' upkram post.md --preset gfm -s --title "Post" --css upkram-all.css -o post.html',
|
|
42
48
|
' echo "# hi" | upkram --preset commonmark',
|
|
49
|
+
' upkram lint README.md --rules ref-invalid-list,qr-sensitive-url',
|
|
50
|
+
' upkram README.md --check > /dev/null # pre-commit gate',
|
|
51
|
+
''
|
|
52
|
+
].join('\n');
|
|
53
|
+
|
|
54
|
+
var LINT_HELP = [
|
|
55
|
+
'UpKram ' + VERSION + ' — Markdown linter',
|
|
56
|
+
'',
|
|
57
|
+
'Usage',
|
|
58
|
+
' upkram lint [options] <file>',
|
|
59
|
+
'',
|
|
60
|
+
' Reads Markdown from <file> (or stdin with "-") and prints lint findings.',
|
|
61
|
+
' Exits 1 when any error-level finding exists, 0 otherwise.',
|
|
62
|
+
'',
|
|
63
|
+
'Options',
|
|
64
|
+
' --rules <list> Comma-separated rule ids (default: all)',
|
|
65
|
+
' --json Print diagnostics as JSON',
|
|
66
|
+
' --quiet Suppress output; exit code still reflects findings',
|
|
67
|
+
' -h, --help Show this help',
|
|
43
68
|
''
|
|
44
69
|
].join('\n');
|
|
45
70
|
|
|
@@ -55,7 +80,8 @@ function parseArgs(argv) {
|
|
|
55
80
|
preset: null,
|
|
56
81
|
standalone: false,
|
|
57
82
|
title: null,
|
|
58
|
-
css: null
|
|
83
|
+
css: null,
|
|
84
|
+
check: false
|
|
59
85
|
};
|
|
60
86
|
var rest = [];
|
|
61
87
|
|
|
@@ -68,6 +94,8 @@ function parseArgs(argv) {
|
|
|
68
94
|
opts.version = true;
|
|
69
95
|
} else if (arg === '-s' || arg === '--standalone') {
|
|
70
96
|
opts.standalone = true;
|
|
97
|
+
} else if (arg === '--check') {
|
|
98
|
+
opts.check = true;
|
|
71
99
|
} else if (arg === '--gfm') {
|
|
72
100
|
opts.preset = 'gfm';
|
|
73
101
|
} else if (arg === '--commonmark') {
|
|
@@ -153,7 +181,65 @@ function standalone(body, opts, sourceName) {
|
|
|
153
181
|
].join('\n');
|
|
154
182
|
}
|
|
155
183
|
|
|
184
|
+
/** Run error-diagnostic gate; write findings to stderr so stdout stays clean HTML. */
|
|
185
|
+
function checkMarkdown(markdown) {
|
|
186
|
+
if (typeof upkram.lintMarkdown !== 'function') return 0;
|
|
187
|
+
var diags;
|
|
188
|
+
try { diags = upkram.lintMarkdown(markdown, {}) || []; }
|
|
189
|
+
catch (e) { process.stderr.write('upkram: lint failed: ' + e.message + '\n'); return 1; }
|
|
190
|
+
var errors = diags.filter(function (d) { return d && d.severity === 'error'; });
|
|
191
|
+
errors.forEach(function (d) {
|
|
192
|
+
var loc = d.position ? d.position.start.line + ':' + d.position.start.column : '-';
|
|
193
|
+
process.stderr.write(loc + '\terror\t' + d.rule + '\t' + d.message + '\n');
|
|
194
|
+
});
|
|
195
|
+
return errors.length ? 1 : 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** `upkram lint <file>` — lint diagnostics with exit-code gate. */
|
|
199
|
+
function lintMain(argv) {
|
|
200
|
+
var opts = { file: null, rules: null, json: false, quiet: false, help: false };
|
|
201
|
+
for (var i = 0; i < argv.length; i++) {
|
|
202
|
+
var a = argv[i];
|
|
203
|
+
if (a === '-h' || a === '--help') opts.help = true;
|
|
204
|
+
else if (a === '--json') opts.json = true;
|
|
205
|
+
else if (a === '--quiet') opts.quiet = true;
|
|
206
|
+
else if (a === '-') opts.file = '-';
|
|
207
|
+
else if (a.indexOf('--rules=') === 0) opts.rules = a.slice(8).split(',').filter(Boolean);
|
|
208
|
+
else if (a === '--rules') {
|
|
209
|
+
var v = argv[++i];
|
|
210
|
+
if (v === undefined) { fail('missing value for --rules'); return; }
|
|
211
|
+
opts.rules = v.split(',').filter(Boolean);
|
|
212
|
+
} else if (a.charAt(0) === '-') { fail('unknown lint option ' + a); process.stderr.write('\n' + LINT_HELP); return; }
|
|
213
|
+
else if (opts.file === null) opts.file = a;
|
|
214
|
+
else { fail('expected at most one input file, got ' + a); return; }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (opts.help) { process.stdout.write(LINT_HELP); return; }
|
|
218
|
+
if (!opts.file) { process.stderr.write(LINT_HELP); process.exitCode = 2; return; }
|
|
219
|
+
|
|
220
|
+
var markdown;
|
|
221
|
+
try { markdown = readInput(opts.file); }
|
|
222
|
+
catch (err) { fail(err.message); return; }
|
|
223
|
+
|
|
224
|
+
var diags;
|
|
225
|
+
try {
|
|
226
|
+
diags = upkram.lintMarkdown(markdown, {}, opts.rules ? { rules: opts.rules } : undefined) || [];
|
|
227
|
+
} catch (err) { fail('lint failed: ' + err.message); return; }
|
|
228
|
+
|
|
229
|
+
if (opts.json) console.log(JSON.stringify(diags, null, 2));
|
|
230
|
+
else if (!opts.quiet) {
|
|
231
|
+
diags.forEach(function (d) {
|
|
232
|
+
var loc = d.position ? d.position.start.line + ':' + d.position.start.column : '-';
|
|
233
|
+
console.log(loc + '\t' + d.severity + '\t' + d.rule + '\t' + d.message);
|
|
234
|
+
});
|
|
235
|
+
if (!diags.length) console.log('OK: no lint findings');
|
|
236
|
+
}
|
|
237
|
+
process.exitCode = diags.some(function (d) { return d && d.severity === 'error'; }) ? 1 : 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
156
240
|
function main(argv) {
|
|
241
|
+
// 子命令分流:不触碰原有渲染参数解析,保证渲染行为零回归。
|
|
242
|
+
if (argv[0] === 'lint') { lintMain(argv.slice(1)); return; }
|
|
157
243
|
var opts;
|
|
158
244
|
try {
|
|
159
245
|
opts = parseArgs(argv);
|
|
@@ -203,6 +289,10 @@ function main(argv) {
|
|
|
203
289
|
}
|
|
204
290
|
|
|
205
291
|
process.stdout.write(html);
|
|
292
|
+
if (opts.check) {
|
|
293
|
+
var rc = checkMarkdown(markdown);
|
|
294
|
+
if (rc) process.exitCode = 1;
|
|
295
|
+
}
|
|
206
296
|
}
|
|
207
297
|
|
|
208
298
|
if (require.main === module) {
|
|
@@ -213,4 +303,4 @@ if (require.main === module) {
|
|
|
213
303
|
main(process.argv.slice(2));
|
|
214
304
|
}
|
|
215
305
|
|
|
216
|
-
module.exports = { main: main, parseArgs: parseArgs, VERSION: VERSION };
|
|
306
|
+
module.exports = { main: main, lintMain: lintMain, parseArgs: parseArgs, VERSION: VERSION };
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "upkram",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "A serious Markdown/GFM engine with 100% CommonMark and GFM conformance, plugin API, lint engine and source-positioned AST.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./upkram-ni.js",
|
|
7
7
|
"browser": "./upkram-all.js",
|
|
8
8
|
"types": "./upkram.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
10
11
|
".": {
|
|
11
12
|
"types": "./upkram.d.ts",
|
|
12
13
|
"import": "./upkram.mjs",
|
|
@@ -65,13 +66,27 @@
|
|
|
65
66
|
"url": "https://github.com/cuizihang1145/UpKram/issues"
|
|
66
67
|
},
|
|
67
68
|
"homepage": "https://github.com/cuizihang1145/UpKram#readme",
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"commonmark": "0.31.2",
|
|
71
|
+
"markdown-it": "15.0.3",
|
|
72
|
+
"marked": "18.3.0",
|
|
73
|
+
"micromark": "4.0.3",
|
|
74
|
+
"parse5": "8.1.1",
|
|
75
|
+
"showdown": "2.1.0",
|
|
76
|
+
"typescript": "5.6.3"
|
|
77
|
+
},
|
|
68
78
|
"scripts": {
|
|
79
|
+
"test": "node bench/test.js",
|
|
80
|
+
"test:quick": "node bench/test.js --quick",
|
|
81
|
+
"spec:fetch": "node bench/fetch-specs.js",
|
|
82
|
+
"test:types": "tsc --project tsconfig.json",
|
|
69
83
|
"lint": "node bench/lint.js",
|
|
70
84
|
"test:spec": "node bench/spec-test.js",
|
|
71
85
|
"test:gfm": "node bench/gfm-test.js",
|
|
72
86
|
"test:determinism": "node bench/determinism.js",
|
|
73
87
|
"test:extra": "node bench/extra.js",
|
|
74
88
|
"test:diff": "node bench/differential.js",
|
|
89
|
+
"test:speed": "node bench/speed.js",
|
|
75
90
|
"report": "node bench/report.js",
|
|
76
91
|
"version": "node scripts/version.js --write --stage",
|
|
77
92
|
"version:check": "node scripts/version.js",
|