md4x 0.0.2 → 0.0.4
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/lib/cli.mjs +36 -18
- package/lib/napi.d.mts +2 -1
- package/lib/napi.mjs +5 -1
- package/lib/wasm.d.mts +2 -1
- package/lib/wasm.mjs +5 -1
- package/package.json +1 -1
package/lib/cli.mjs
CHANGED
|
@@ -22,26 +22,44 @@ const { values, positionals } = parseArgs({
|
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
+
const _tty = process.stderr.isTTY;
|
|
26
|
+
const c = (code) => (s) => _tty ? `\x1b[${code}m${s}\x1b[0m` : s;
|
|
27
|
+
const _b = c(1);
|
|
28
|
+
const _d = c(2);
|
|
29
|
+
const _c = c(36);
|
|
30
|
+
const _g = c(32);
|
|
31
|
+
|
|
25
32
|
function usage() {
|
|
26
33
|
process.stderr.write(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
`${_b("md4x")} — Markdown renderer
|
|
35
|
+
|
|
36
|
+
${_g("Usage:")} ${_b("md4x")} ${_d("[OPTION]... [FILE]")}
|
|
37
|
+
|
|
38
|
+
${_g("General options:")}
|
|
39
|
+
${_c("-o")}, ${_c("--output")}=${_d("FILE")} Output file ${_d("(default: stdout)")}
|
|
40
|
+
${_c("-t")}, ${_c("--format")}=${_d("FORMAT")} Output format: html, json, ansi ${_d("(default: ansi for TTY, html otherwise)")}
|
|
41
|
+
${_c("-s")}, ${_c("--stat")} Measure parsing time
|
|
42
|
+
${_c("-h")}, ${_c("--help")} Display this help and exit
|
|
43
|
+
${_c("-v")}, ${_c("--version")} Display version and exit
|
|
44
|
+
|
|
45
|
+
${_g("Input:")}
|
|
46
|
+
File path, ${_c("-")} for stdin, HTTP/HTTPS URL, or shorthand:
|
|
47
|
+
${_c("gh:")}${_d("<owner>/<repo>[/path]")} GitHub raw content
|
|
48
|
+
${_c("npm:")}${_d("<package>[@version][/path]")} npm package via unpkg
|
|
49
|
+
|
|
50
|
+
${_g("HTML options:")}
|
|
51
|
+
${_c("-f")}, ${_c("--full-html")} Full HTML document with header
|
|
52
|
+
${_c("--html-title")}=${_d("TITLE")} Document title
|
|
53
|
+
${_c("--html-css")}=${_d("URL")} CSS link
|
|
54
|
+
|
|
55
|
+
${_g("Examples:")}
|
|
56
|
+
${_d("$")} ${_b("md4x")} README.md ${_d("# Render to terminal")}
|
|
57
|
+
${_d("$")} ${_b("md4x")} ${_c("-t html")} doc.md ${_d("# HTML output")}
|
|
58
|
+
${_d("$")} ${_b("md4x")} ${_c("-t json")} doc.md ${_d("# JSON AST output")}
|
|
59
|
+
${_d("$")} ${_b("md4x")} ${_c("gh:")}pi0/md4x ${_d("# GitHub repo README")}
|
|
60
|
+
${_d("$")} ${_b("md4x")} ${_c("npm:")}vue@3 ${_d("# npm package README")}
|
|
61
|
+
${_d("$")} echo "# Hello" | ${_b("md4x")} ${_d("# Pipe from stdin")}
|
|
62
|
+
${_d("$")} ${_b("md4x")} ${_c("-f --html-css")}=style.css doc.md ${_d("# Full HTML with CSS")}
|
|
45
63
|
`,
|
|
46
64
|
);
|
|
47
65
|
}
|
package/lib/napi.d.mts
CHANGED
|
@@ -3,5 +3,6 @@ import type { ComarkTree } from "./types.js";
|
|
|
3
3
|
export type { ComarkTree, ComarkNode, ComarkElement, ComarkText, ComarkElementAttributes } from "./types.js";
|
|
4
4
|
|
|
5
5
|
export declare function renderToHtml(input: string): string;
|
|
6
|
-
export declare function renderToJson(input: string):
|
|
6
|
+
export declare function renderToJson(input: string): string;
|
|
7
|
+
export declare function parseAST(input: string): ComarkTree;
|
|
7
8
|
export declare function renderToAnsi(input: string): string;
|
package/lib/napi.mjs
CHANGED
|
@@ -19,7 +19,11 @@ export function renderToHtml(input) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function renderToJson(input) {
|
|
22
|
-
return
|
|
22
|
+
return binding.renderToJson(input);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseAST(input) {
|
|
26
|
+
return JSON.parse(renderToJson(input));
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export function renderToAnsi(input) {
|
package/lib/wasm.d.mts
CHANGED
|
@@ -4,5 +4,6 @@ export type { ComarkTree, ComarkNode, ComarkElement, ComarkText, ComarkElementAt
|
|
|
4
4
|
|
|
5
5
|
export declare function initWasm(input?: ArrayBuffer | Uint8Array | WebAssembly.Module | Response | Promise<Response>): Promise<void>;
|
|
6
6
|
export declare function renderToHtml(input: string): string;
|
|
7
|
-
export declare function renderToJson(input: string):
|
|
7
|
+
export declare function renderToJson(input: string): string;
|
|
8
|
+
export declare function parseAST(input: string): ComarkTree;
|
|
8
9
|
export declare function renderToAnsi(input: string): string;
|
package/lib/wasm.mjs
CHANGED
|
@@ -45,7 +45,11 @@ export function renderToHtml(input) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function renderToJson(input) {
|
|
48
|
-
return
|
|
48
|
+
return render(getExports(), getExports().md4x_to_json, input);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function parseAST(input) {
|
|
52
|
+
return JSON.parse(renderToJson(input));
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
export function renderToAnsi(input) {
|