md4x 0.0.4 → 0.0.7

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
package/build/md4x.wasm CHANGED
Binary file
Binary file
Binary file
package/lib/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { parseArgs } from "node:util";
4
4
  import { readFileSync, writeFileSync } from "node:fs";
5
- import { renderToHtml, renderToAnsi, renderToJson } from "./napi.mjs";
5
+ import { renderToHtml, renderToAnsi, renderToAST } from "./napi.mjs";
6
6
 
7
7
  const { values, positionals } = parseArgs({
8
8
  allowPositionals: true,
@@ -23,7 +23,7 @@ const { values, positionals } = parseArgs({
23
23
  });
24
24
 
25
25
  const _tty = process.stderr.isTTY;
26
- const c = (code) => (s) => _tty ? `\x1b[${code}m${s}\x1b[0m` : s;
26
+ const c = (code) => (s) => (_tty ? `\x1b[${code}m${s}\x1b[0m` : s);
27
27
  const _b = c(1);
28
28
  const _d = c(2);
29
29
  const _c = c(36);
@@ -147,7 +147,7 @@ switch (format) {
147
147
  output = renderToHtml(input);
148
148
  break;
149
149
  case "json":
150
- output = JSON.stringify(renderToJson(input));
150
+ output = JSON.stringify(renderToAST(input));
151
151
  break;
152
152
  case "ansi":
153
153
  output = renderToAnsi(input);
package/lib/napi.d.mts CHANGED
@@ -1,8 +1,14 @@
1
1
  import type { ComarkTree } from "./types.js";
2
2
 
3
- export type { ComarkTree, ComarkNode, ComarkElement, ComarkText, ComarkElementAttributes } from "./types.js";
3
+ export type {
4
+ ComarkTree,
5
+ ComarkNode,
6
+ ComarkElement,
7
+ ComarkText,
8
+ ComarkElementAttributes,
9
+ } from "./types.js";
4
10
 
5
11
  export declare function renderToHtml(input: string): string;
6
- export declare function renderToJson(input: string): string;
12
+ export declare function renderToAST(input: string): string;
7
13
  export declare function parseAST(input: string): ComarkTree;
8
14
  export declare function renderToAnsi(input: string): string;
package/lib/napi.mjs CHANGED
@@ -4,12 +4,7 @@ import { arch, platform } from "node:process";
4
4
  const require = createRequire(import.meta.url);
5
5
 
6
6
  function loadBinding() {
7
- const name = `md4x.${platform}-${arch}`;
8
- try {
9
- return require(`../build/${name}.node`);
10
- } catch {
11
- return require("../build/md4x.node");
12
- }
7
+ return require(`../build/md4x.${platform}-${arch}.node`);
13
8
  }
14
9
 
15
10
  const binding = loadBinding();
@@ -18,12 +13,12 @@ export function renderToHtml(input) {
18
13
  return binding.renderToHtml(input);
19
14
  }
20
15
 
21
- export function renderToJson(input) {
22
- return binding.renderToJson(input);
16
+ export function renderToAST(input) {
17
+ return binding.renderToAST(input);
23
18
  }
24
19
 
25
20
  export function parseAST(input) {
26
- return JSON.parse(renderToJson(input));
21
+ return JSON.parse(renderToAST(input));
27
22
  }
28
23
 
29
24
  export function renderToAnsi(input) {
package/lib/wasm.d.mts CHANGED
@@ -1,9 +1,22 @@
1
1
  import type { ComarkTree } from "./types.js";
2
2
 
3
- export type { ComarkTree, ComarkNode, ComarkElement, ComarkText, ComarkElementAttributes } from "./types.js";
3
+ export type {
4
+ ComarkTree,
5
+ ComarkNode,
6
+ ComarkElement,
7
+ ComarkText,
8
+ ComarkElementAttributes,
9
+ } from "./types.js";
4
10
 
5
- export declare function initWasm(input?: ArrayBuffer | Uint8Array | WebAssembly.Module | Response | Promise<Response>): Promise<void>;
11
+ export declare function initWasm(
12
+ input?:
13
+ | ArrayBuffer
14
+ | Uint8Array
15
+ | WebAssembly.Module
16
+ | Response
17
+ | Promise<Response>,
18
+ ): Promise<void>;
6
19
  export declare function renderToHtml(input: string): string;
7
- export declare function renderToJson(input: string): string;
20
+ export declare function renderToAST(input: string): string;
8
21
  export declare function parseAST(input: string): ComarkTree;
9
22
  export declare function renderToAnsi(input: string): string;
package/lib/wasm.mjs CHANGED
@@ -2,7 +2,9 @@ let _instance;
2
2
 
3
3
  function getExports() {
4
4
  if (!_instance) {
5
- throw new Error("md4x: WASM not initialized. Call `await initWasm()` first.");
5
+ throw new Error(
6
+ "md4x: WASM not initialized. Call `await initWasm()` first.",
7
+ );
6
8
  }
7
9
  return _instance.exports;
8
10
  }
@@ -18,7 +20,10 @@ export async function initWasm(input) {
18
20
  });
19
21
  _instance = instance;
20
22
  return;
21
- } else if (input instanceof Response || (typeof input === "object" && typeof input.then === "function")) {
23
+ } else if (
24
+ input instanceof Response ||
25
+ (typeof input === "object" && typeof input.then === "function")
26
+ ) {
22
27
  const response = await input;
23
28
  if (response instanceof Response) {
24
29
  bytes = await response.arrayBuffer();
@@ -26,12 +31,14 @@ export async function initWasm(input) {
26
31
  bytes = response;
27
32
  }
28
33
  } else {
29
- const fsp = globalThis.process?.getBuiltinModule?.("fs/promises")
34
+ const fsp = globalThis.process?.getBuiltinModule?.("fs/promises");
30
35
  if (fsp) {
31
36
  const wasmPath = new URL("../build/md4x.wasm", import.meta.url);
32
- bytes = await fsp.readFile(wasmPath);
37
+ bytes = await fsp.readFile(wasmPath);
33
38
  } else {
34
- bytes = await fetch(await import("../build/md4x.wasm?url").then(m => m.default)).then(r => r.arrayBuffer())
39
+ bytes = await fetch(
40
+ await import("../build/md4x.wasm?url").then((m) => m.default),
41
+ ).then((r) => r.arrayBuffer());
35
42
  }
36
43
  }
37
44
  const { instance } = await WebAssembly.instantiate(bytes, {
@@ -44,12 +51,12 @@ export function renderToHtml(input) {
44
51
  return render(getExports(), getExports().md4x_to_html, input);
45
52
  }
46
53
 
47
- export function renderToJson(input) {
48
- return render(getExports(), getExports().md4x_to_json, input);
54
+ export function renderToAST(input) {
55
+ return render(getExports(), getExports().md4x_to_ast, input);
49
56
  }
50
57
 
51
58
  export function parseAST(input) {
52
- return JSON.parse(renderToJson(input));
59
+ return JSON.parse(renderToAST(input));
53
60
  }
54
61
 
55
62
  export function renderToAnsi(input) {
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "md4x",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
+ "repository": "pi0/md4x",
6
7
  "bin": {
7
8
  "md4x": "./lib/cli.mjs"
8
9
  },
@@ -21,19 +22,18 @@
21
22
  "default": "./lib/napi.mjs"
22
23
  }
23
24
  },
25
+ "scripts": {
26
+ "prepack": "cd ../.. && zig build --verbose"
27
+ },
24
28
  "files": [
25
29
  "build",
26
30
  "lib",
27
31
  "README.md"
28
32
  ],
29
33
  "devDependencies": {
30
- "@milkdown/crepe": "^7.18.0",
31
- "ansi-html": "^0.0.9",
32
34
  "markdown-it": "^14.1.1",
35
+ "markdown-it-mdc": "^0.2.12",
33
36
  "md4w": "^0.2.7",
34
- "mitata": "^1.0.34",
35
- "shiki": "^3.22.0",
36
- "vite": "^6.3.5",
37
- "vitest": "^4.0.18"
37
+ "mitata": "^1.0.34"
38
38
  }
39
39
  }
package/build/.gitkeep DELETED
File without changes