md4x 0.0.21 → 0.0.23

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
@@ -6,6 +6,7 @@ import {
6
6
  renderToHtml,
7
7
  renderToAnsi,
8
8
  renderToText,
9
+ renderToMarkdown,
9
10
  parseAST,
10
11
  parseMeta,
11
12
  heal,
@@ -47,7 +48,7 @@ ${_g("Usage:")} ${_b("md4x")} ${_d("[OPTION]... [FILE]")}
47
48
 
48
49
  ${_g("General options:")}
49
50
  ${_c("-o")}, ${_c("--output")}=${_d("FILE")} Output file ${_d("(default: stdout)")}
50
- ${_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)")}
51
+ ${_c("-t")}, ${_c("--format")}=${_d("FORMAT")} Output format: ${_c("html")}, ${_c("text")}, ${_c("ast")}, ${_c("ansi")}, ${_c("meta")}, ${_c("markdown")}, ${_c("heal")} ${_d("(default: ansi for TTY, text otherwise)")}
51
52
  ${_c("--heal")} Heal incomplete markdown before rendering
52
53
  ${_c("--show-urls")} Show link URLs after link text ${_d("(ANSI only)")}
53
54
  ${_c("--show-frontmatter")} Show frontmatter content ${_d("(ANSI only)")}
@@ -96,7 +97,15 @@ if (values.version) {
96
97
  process.exit(0);
97
98
  }
98
99
 
99
- const supportedFormats = ["html", "ast", "ansi", "text", "meta", "heal"];
100
+ const supportedFormats = [
101
+ "html",
102
+ "ast",
103
+ "ansi",
104
+ "text",
105
+ "meta",
106
+ "markdown",
107
+ "heal",
108
+ ];
100
109
  const format = values.format;
101
110
  if (!supportedFormats.includes(format)) {
102
111
  process.stderr.write(`Unknown format: ${format}\n`);
@@ -184,6 +193,9 @@ switch (format) {
184
193
  case "meta":
185
194
  output = JSON.stringify(parseMeta(input, healOpt), null, 2);
186
195
  break;
196
+ case "markdown":
197
+ output = renderToMarkdown(input, healOpt);
198
+ break;
187
199
  case "heal":
188
200
  output = heal(input);
189
201
  break;
package/lib/napi.d.mts CHANGED
@@ -29,6 +29,7 @@ export interface NAPIBinding {
29
29
  renderToAnsiMeta(input: string): Buffer;
30
30
  renderToMeta(input: string, flags?: number): string;
31
31
  renderToText(input: string, flags?: number): string;
32
+ renderToMarkdown(input: string, flags?: number): string;
32
33
  heal(input: string): string;
33
34
  }
34
35
 
@@ -59,4 +60,8 @@ export declare function renderToText(
59
60
  input: string,
60
61
  opts?: RenderOptions,
61
62
  ): string;
63
+ export declare function renderToMarkdown(
64
+ input: string,
65
+ opts?: RenderOptions,
66
+ ): string;
62
67
  export declare function heal(input: string): string;
package/lib/napi.mjs CHANGED
@@ -89,6 +89,11 @@ export function renderToText(input, opts) {
89
89
  return getBinding().renderToText(str(input), flags);
90
90
  }
91
91
 
92
+ export function renderToMarkdown(input, opts) {
93
+ const flags = opts?.heal ? HEAL_FLAG : 0;
94
+ return getBinding().renderToMarkdown(str(input), flags);
95
+ }
96
+
92
97
  export function parseMeta(input, opts) {
93
98
  const meta = JSON.parse(renderToMeta(input, opts));
94
99
  if (!meta.title && meta.headings?.[0]) {
@@ -27,9 +27,17 @@ export function _getExports() {
27
27
  export const _imports = {
28
28
  wasi_snapshot_preview1: {
29
29
  fd_close: () => 0,
30
+ fd_filestat_get: () => 0,
31
+ fd_pwrite: () => 0,
32
+ fd_read: () => 0,
30
33
  fd_seek: () => 0,
31
34
  fd_write: () => 0,
32
35
  proc_exit: () => {},
36
+ random_get: (buf, len) => {
37
+ const bytes = new Uint8Array(_instance.exports.memory.buffer, buf, len);
38
+ crypto.getRandomValues(bytes);
39
+ return 0;
40
+ },
33
41
  },
34
42
  };
35
43
 
@@ -138,6 +146,12 @@ export function renderToText(input, opts) {
138
146
  return render(exports, exports.md4x_to_text, input, flags);
139
147
  }
140
148
 
149
+ export function renderToMarkdown(input, opts) {
150
+ const flags = opts?.heal ? HEAL_FLAG : 0;
151
+ const exports = _getExports();
152
+ return render(exports, exports.md4x_to_markdown, input, flags);
153
+ }
154
+
141
155
  export function parseMeta(input, opts) {
142
156
  const meta = JSON.parse(renderToMeta(input, opts));
143
157
  if (!meta.title && meta.headings?.[0]) {
@@ -6,6 +6,7 @@ export {
6
6
  parseMeta,
7
7
  renderToMeta,
8
8
  renderToText,
9
+ renderToMarkdown,
9
10
  heal,
10
11
  } from "./common.mjs";
11
12
 
@@ -51,4 +51,8 @@ export declare function renderToText(
51
51
  input: string,
52
52
  opts?: RenderOptions,
53
53
  ): string;
54
+ export declare function renderToMarkdown(
55
+ input: string,
56
+ opts?: RenderOptions,
57
+ ): string;
54
58
  export declare function heal(input: string): string;
@@ -6,6 +6,7 @@ export {
6
6
  parseMeta,
7
7
  renderToMeta,
8
8
  renderToText,
9
+ renderToMarkdown,
9
10
  heal,
10
11
  } from "./common.mjs";
11
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md4x",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "repository": "unjs/md4x",
5
5
  "license": "MIT",
6
6
  "type": "module",