md4x 0.0.16 → 0.0.18

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.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/build/md4x.wasm CHANGED
Binary file
Binary file
Binary file
package/lib/cli.mjs CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  renderToText,
9
9
  parseAST,
10
10
  parseMeta,
11
+ heal,
11
12
  } from "./napi.mjs";
12
13
 
13
14
  const { values, positionals } = parseArgs({
@@ -22,6 +23,7 @@ const { values, positionals } = parseArgs({
22
23
  "full-html": { type: "boolean", short: "f", default: false },
23
24
  "html-title": { type: "string" },
24
25
  "html-css": { type: "string" },
26
+ heal: { type: "boolean", default: false },
25
27
  stat: { type: "boolean", short: "s", default: false },
26
28
  help: { type: "boolean", short: "h", default: false },
27
29
  version: { type: "boolean", short: "v", default: false },
@@ -43,7 +45,8 @@ ${_g("Usage:")} ${_b("md4x")} ${_d("[OPTION]... [FILE]")}
43
45
 
44
46
  ${_g("General options:")}
45
47
  ${_c("-o")}, ${_c("--output")}=${_d("FILE")} Output file ${_d("(default: stdout)")}
46
- ${_c("-t")}, ${_c("--format")}=${_d("FORMAT")} Output format: ${_c("html")}, ${_c("text")}, ${_c("ast")}, ${_c("ansi")}, ${_c("meta")} ${_d("(default: ansi for TTY, text otherwise)")}
48
+ ${_c("-t")}, ${_c("--format")}=${_d("FORMAT")} Output format: ${_c("html")}, ${_c("text")}, ${_c("ast")}, ${_c("ansi")}, ${_c("meta")}, ${_c("heal")} ${_d("(default: ansi for TTY, text otherwise)")}
49
+ ${_c("--heal")} Heal incomplete markdown before rendering
47
50
  ${_c("-s")}, ${_c("--stat")} Measure parsing time
48
51
  ${_c("-h")}, ${_c("--help")} Display this help and exit
49
52
  ${_c("-v")}, ${_c("--version")} Display version and exit
@@ -89,7 +92,7 @@ if (values.version) {
89
92
  process.exit(0);
90
93
  }
91
94
 
92
- const supportedFormats = ["html", "ast", "ansi", "text", "meta"];
95
+ const supportedFormats = ["html", "ast", "ansi", "text", "meta", "heal"];
93
96
  const format = values.format;
94
97
  if (!supportedFormats.includes(format)) {
95
98
  process.stderr.write(`Unknown format: ${format}\n`);
@@ -154,22 +157,27 @@ if (!inputPath || inputPath === "-") {
154
157
 
155
158
  const t0 = values.stat ? performance.now() : 0;
156
159
 
160
+ const healOpt = values.heal ? { heal: true } : undefined;
161
+
157
162
  let output;
158
163
  switch (format) {
159
164
  case "html":
160
- output = renderToHtml(input);
165
+ output = renderToHtml(input, healOpt);
161
166
  break;
162
167
  case "ansi":
163
- output = renderToAnsi(input);
168
+ output = renderToAnsi(input, healOpt);
164
169
  break;
165
170
  case "text":
166
- output = renderToText(input);
171
+ output = renderToText(input, healOpt);
167
172
  break;
168
173
  case "ast":
169
- output = JSON.stringify(parseAST(input), null, 2);
174
+ output = JSON.stringify(parseAST(input, healOpt), null, 2);
170
175
  break;
171
176
  case "meta":
172
- output = JSON.stringify(parseMeta(input), null, 2);
177
+ output = JSON.stringify(parseMeta(input, healOpt), null, 2);
178
+ break;
179
+ case "heal":
180
+ output = heal(input);
173
181
  break;
174
182
  }
175
183
 
package/lib/napi.d.mts CHANGED
@@ -1,4 +1,9 @@
1
- import type { ComarkTree, ComarkMeta, HtmlOptions } from "./types.mjs";
1
+ import type {
2
+ ComarkTree,
3
+ ComarkMeta,
4
+ HtmlOptions,
5
+ RenderOptions,
6
+ } from "./types.mjs";
2
7
 
3
8
  export type {
4
9
  ComarkTree,
@@ -9,14 +14,16 @@ export type {
9
14
  ComarkHeading,
10
15
  ComarkMeta,
11
16
  HtmlOptions,
17
+ RenderOptions,
12
18
  } from "./types.mjs";
13
19
 
14
20
  export interface NAPIBinding {
15
21
  renderToHtml(input: string, flags?: number): string;
16
- renderToAST(input: string): string;
17
- renderToAnsi(input: string): string;
18
- renderToMeta(input: string): string;
19
- renderToText(input: string): string;
22
+ renderToAST(input: string, flags?: number): string;
23
+ renderToAnsi(input: string, flags?: number): string;
24
+ renderToMeta(input: string, flags?: number): string;
25
+ renderToText(input: string, flags?: number): string;
26
+ heal(input: string): string;
20
27
  }
21
28
 
22
29
  export interface InitOptions {
@@ -25,9 +32,28 @@ export interface InitOptions {
25
32
 
26
33
  export declare function init(opts?: InitOptions): Promise<void>;
27
34
  export declare function renderToHtml(input: string, opts?: HtmlOptions): string;
28
- export declare function renderToAST(input: string): string;
29
- export declare function parseAST(input: string): ComarkTree;
30
- export declare function renderToAnsi(input: string): string;
31
- export declare function renderToMeta(input: string): string;
32
- export declare function parseMeta(input: string): ComarkMeta;
33
- export declare function renderToText(input: string): string;
35
+ export declare function renderToAST(
36
+ input: string,
37
+ opts?: RenderOptions,
38
+ ): string;
39
+ export declare function parseAST(
40
+ input: string,
41
+ opts?: RenderOptions,
42
+ ): ComarkTree;
43
+ export declare function renderToAnsi(
44
+ input: string,
45
+ opts?: RenderOptions,
46
+ ): string;
47
+ export declare function renderToMeta(
48
+ input: string,
49
+ opts?: RenderOptions,
50
+ ): string;
51
+ export declare function parseMeta(
52
+ input: string,
53
+ opts?: RenderOptions,
54
+ ): ComarkMeta;
55
+ export declare function renderToText(
56
+ input: string,
57
+ opts?: RenderOptions,
58
+ ): string;
59
+ export declare function heal(input: string): string;
package/lib/napi.mjs CHANGED
@@ -28,35 +28,46 @@ export function init(opts) {
28
28
  }
29
29
  }
30
30
 
31
+ const HEAL_FLAG = 0x0100;
32
+
31
33
  export function renderToHtml(input, opts) {
32
- const flags = opts?.full ? 0x0008 : 0;
34
+ let flags = opts?.full ? 0x0008 : 0;
35
+ if (opts?.heal) flags |= HEAL_FLAG;
33
36
  return getBinding().renderToHtml(input, flags);
34
37
  }
35
38
 
36
- export function renderToAST(input) {
37
- return getBinding().renderToAST(input);
39
+ export function renderToAST(input, opts) {
40
+ const flags = opts?.heal ? HEAL_FLAG : 0;
41
+ return getBinding().renderToAST(input, flags);
38
42
  }
39
43
 
40
- export function parseAST(input) {
41
- return JSON.parse(renderToAST(input));
44
+ export function parseAST(input, opts) {
45
+ return JSON.parse(renderToAST(input, opts));
42
46
  }
43
47
 
44
- export function renderToAnsi(input) {
45
- return getBinding().renderToAnsi(input);
48
+ export function renderToAnsi(input, opts) {
49
+ const flags = opts?.heal ? HEAL_FLAG : 0;
50
+ return getBinding().renderToAnsi(input, flags);
46
51
  }
47
52
 
48
- export function renderToMeta(input) {
49
- return getBinding().renderToMeta(input);
53
+ export function renderToMeta(input, opts) {
54
+ const flags = opts?.heal ? HEAL_FLAG : 0;
55
+ return getBinding().renderToMeta(input, flags);
50
56
  }
51
57
 
52
- export function renderToText(input) {
53
- return getBinding().renderToText(input);
58
+ export function renderToText(input, opts) {
59
+ const flags = opts?.heal ? HEAL_FLAG : 0;
60
+ return getBinding().renderToText(input, flags);
54
61
  }
55
62
 
56
- export function parseMeta(input) {
57
- const meta = JSON.parse(renderToMeta(input));
63
+ export function parseMeta(input, opts) {
64
+ const meta = JSON.parse(renderToMeta(input, opts));
58
65
  if (!meta.title && meta.headings?.[0]) {
59
66
  meta.title = meta.headings[0].text;
60
67
  }
61
68
  return meta;
62
69
  }
70
+
71
+ export function heal(input) {
72
+ return getBinding().heal(input);
73
+ }
package/lib/types.d.mts CHANGED
@@ -29,7 +29,12 @@ export type ComarkMeta = {
29
29
  [key: string]: unknown;
30
30
  };
31
31
 
32
- export interface HtmlOptions {
32
+ export interface RenderOptions {
33
+ /** Heal incomplete/streaming Markdown before rendering. */
34
+ heal?: boolean;
35
+ }
36
+
37
+ export interface HtmlOptions extends RenderOptions {
33
38
  /** Generate a full HTML document with `<!DOCTYPE html>`, `<head>`, and `<body>`. */
34
39
  full?: boolean;
35
40
  }
@@ -48,40 +48,52 @@ function render(exports, fn, input, ...extra) {
48
48
  return result;
49
49
  }
50
50
 
51
+ const HEAL_FLAG = 0x0100;
52
+
51
53
  export function renderToHtml(input, opts) {
52
- const flags = opts?.full ? 0x0008 : 0;
54
+ let flags = opts?.full ? 0x0008 : 0;
55
+ if (opts?.heal) flags |= HEAL_FLAG;
53
56
  const exports = _getExports();
54
57
  return render(exports, exports.md4x_to_html, input, flags);
55
58
  }
56
59
 
57
- export function renderToAST(input) {
60
+ export function renderToAST(input, opts) {
61
+ const flags = opts?.heal ? HEAL_FLAG : 0;
58
62
  const exports = _getExports();
59
- return render(exports, exports.md4x_to_ast, input);
63
+ return render(exports, exports.md4x_to_ast, input, flags);
60
64
  }
61
65
 
62
- export function parseAST(input) {
63
- return JSON.parse(renderToAST(input));
66
+ export function parseAST(input, opts) {
67
+ return JSON.parse(renderToAST(input, opts));
64
68
  }
65
69
 
66
- export function renderToAnsi(input) {
70
+ export function renderToAnsi(input, opts) {
71
+ const flags = opts?.heal ? HEAL_FLAG : 0;
67
72
  const exports = _getExports();
68
- return render(exports, exports.md4x_to_ansi, input);
73
+ return render(exports, exports.md4x_to_ansi, input, flags);
69
74
  }
70
75
 
71
- export function renderToMeta(input) {
76
+ export function renderToMeta(input, opts) {
77
+ const flags = opts?.heal ? HEAL_FLAG : 0;
72
78
  const exports = _getExports();
73
- return render(exports, exports.md4x_to_meta, input);
79
+ return render(exports, exports.md4x_to_meta, input, flags);
74
80
  }
75
81
 
76
- export function renderToText(input) {
82
+ export function renderToText(input, opts) {
83
+ const flags = opts?.heal ? HEAL_FLAG : 0;
77
84
  const exports = _getExports();
78
- return render(exports, exports.md4x_to_text, input);
85
+ return render(exports, exports.md4x_to_text, input, flags);
79
86
  }
80
87
 
81
- export function parseMeta(input) {
82
- const meta = JSON.parse(renderToMeta(input));
88
+ export function parseMeta(input, opts) {
89
+ const meta = JSON.parse(renderToMeta(input, opts));
83
90
  if (!meta.title && meta.headings?.[0]) {
84
91
  meta.title = meta.headings[0].text;
85
92
  }
86
93
  return meta;
87
94
  }
95
+
96
+ export function heal(input) {
97
+ const exports = _getExports();
98
+ return render(exports, exports.md4x_heal, input);
99
+ }
@@ -6,6 +6,7 @@ export {
6
6
  parseMeta,
7
7
  renderToMeta,
8
8
  renderToText,
9
+ heal,
9
10
  } from "./common.mjs";
10
11
 
11
12
  import { _setInstance, _imports, _hasInstance } from "./common.mjs";
@@ -0,0 +1,55 @@
1
+ import type {
2
+ ComarkTree,
3
+ ComarkMeta,
4
+ HtmlOptions,
5
+ RenderOptions,
6
+ } from "../types.mjs";
7
+
8
+ export type {
9
+ ComarkTree,
10
+ ComarkNode,
11
+ ComarkElement,
12
+ ComarkText,
13
+ ComarkElementAttributes,
14
+ ComarkHeading,
15
+ ComarkMeta,
16
+ HtmlOptions,
17
+ RenderOptions,
18
+ } from "../types.mjs";
19
+
20
+ export interface InitOptions {
21
+ wasm?:
22
+ | ArrayBuffer
23
+ | Uint8Array
24
+ | WebAssembly.Module
25
+ | Response
26
+ | Promise<Response>;
27
+ }
28
+
29
+ export declare function init(opts?: InitOptions): Promise<void>;
30
+ export declare function renderToHtml(input: string, opts?: HtmlOptions): string;
31
+ export declare function renderToAST(
32
+ input: string,
33
+ opts?: RenderOptions,
34
+ ): string;
35
+ export declare function parseAST(
36
+ input: string,
37
+ opts?: RenderOptions,
38
+ ): ComarkTree;
39
+ export declare function renderToAnsi(
40
+ input: string,
41
+ opts?: RenderOptions,
42
+ ): string;
43
+ export declare function renderToMeta(
44
+ input: string,
45
+ opts?: RenderOptions,
46
+ ): string;
47
+ export declare function parseMeta(
48
+ input: string,
49
+ opts?: RenderOptions,
50
+ ): ComarkMeta;
51
+ export declare function renderToText(
52
+ input: string,
53
+ opts?: RenderOptions,
54
+ ): string;
55
+ export declare function heal(input: string): string;
@@ -6,6 +6,7 @@ export {
6
6
  parseMeta,
7
7
  renderToMeta,
8
8
  renderToText,
9
+ heal,
9
10
  } from "./common.mjs";
10
11
 
11
12
  import { _setInstance, _hasInstance, _imports } from "./common.mjs";
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "md4x",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "repository": "pi0/md4x",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  "./wasm": {
9
+ "types": "./lib/wasm/index.d.mts",
9
10
  "unwasm": "./lib/wasm/unwasm.mjs",
10
11
  "default": "./lib/wasm/defult.mjs"
11
12
  },
package/lib/wasm.d.mts DELETED
@@ -1,30 +0,0 @@
1
- import type { ComarkTree, ComarkMeta, HtmlOptions } from "./types.mjs";
2
-
3
- export type {
4
- ComarkTree,
5
- ComarkNode,
6
- ComarkElement,
7
- ComarkText,
8
- ComarkElementAttributes,
9
- ComarkHeading,
10
- ComarkMeta,
11
- HtmlOptions,
12
- } from "./types.mjs";
13
-
14
- export interface InitOptions {
15
- wasm?:
16
- | ArrayBuffer
17
- | Uint8Array
18
- | WebAssembly.Module
19
- | Response
20
- | Promise<Response>;
21
- }
22
-
23
- export declare function init(opts?: InitOptions): Promise<void>;
24
- export declare function renderToHtml(input: string, opts?: HtmlOptions): string;
25
- export declare function renderToAST(input: string): string;
26
- export declare function parseAST(input: string): ComarkTree;
27
- export declare function renderToAnsi(input: string): string;
28
- export declare function renderToMeta(input: string): string;
29
- export declare function parseMeta(input: string): ComarkMeta;
30
- export declare function renderToText(input: string): string;