mausmark 0.6.0 → 0.7.1

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 CHANGED
@@ -18,10 +18,10 @@ Browser bundlers must emit the package-relative `.wasm` asset.
18
18
  ## Usage
19
19
 
20
20
  import {createParser, NodeType} from "mausmark";
21
-
21
+
22
22
  const parser = await createParser();
23
23
  const doc = parser.parse("# Hello\n\nThis is **Mausmark**.");
24
-
24
+
25
25
  for (let i = 0; i < doc.nodeCount; i++) {
26
26
  if (doc.type(i) === NodeType.HEADING) {
27
27
  console.log(doc.joinedText(i)); // "Hello"
@@ -68,7 +68,8 @@ numeric values.
68
68
  breaks. For nested markup, walk the children instead.
69
69
  - `blockRange(index)` gives the source range of the whole block,
70
70
  including its Markdown syntax. The end is exclusive. Nodes without a
71
- block range return `undefined`.
71
+ block range return `undefined`. Table cell ranges exclude delimiter
72
+ pipes and surrounding whitespace but include inline Markdown syntax.
72
73
  - `link(index)` returns the raw URL, title, label, and reference style
73
74
  for a link, image, or reference definition.
74
75
  - `level(index)` carries type-specific values such as heading depth,
@@ -92,21 +93,23 @@ schemes and sanitize any raw HTML you choose to emit.
92
93
 
93
94
  ## Performance
94
95
 
95
- The v0.6.0 parser is 71 KB of WebAssembly (31 KB gzipped). On an Apple
96
- M3 Pro with Node.js 26.3.1 and Bun 1.4.2, warmed source-to-AST
97
- throughput was:
98
-
99
- | Input | Node (GB/s) | Bun (GB/s) |
100
- | ---------------------- | ----------: | ---------: |
101
- | Moby-Dick (1.2 MB) | 4.18 | 4.96 |
102
- | Line-wrapped Moby-Dick | 3.05 | 4.26 |
103
- | Pro Git chapters | 1.60 | 2.05 |
104
- | tldr pages | 0.41 | 0.46 |
105
-
106
- The two Moby-Dick inputs and Pro Git use Markdown; tldr uses CommonMark.
107
- Each figure is the median of three passes with preloaded UTF-8 input and
108
- a reused parser arena. These timings exclude initialization, input
109
- encoding and copying, snapshot copying, and rendering.
96
+ Built with Clang 22, the WebAssembly module in the npm package is 70.1 KiB
97
+ (30.7 KiB with gzip, 26.9 KiB with Brotli). On an Apple M3 Pro with
98
+ Node.js 26.3.1 and Bun 1.4.2, warmed source-to-AST throughput was:
99
+
100
+ | Input | Node (GB/s) | Bun (GB/s) |
101
+ | ------------------------ | ----------: | ---------: |
102
+ | Moby-Dick (1.2 MB) | 4.71 | 5.10 |
103
+ | Line-wrapped Moby-Dick | 3.30 | 4.19 |
104
+ | Pro Git (9 chapters) | 1.78 | 2.12 |
105
+ | curl docs (910 files) | 0.67 | 0.76 |
106
+ | tldr pages (5,519 files) | 0.47 | 0.55 |
107
+
108
+ The two Moby-Dick inputs and Pro Git use Markdown; curl and tldr use
109
+ CommonMark. Each figure is the median of five samples with preloaded
110
+ UTF-8 input and a reused parser arena. These timings exclude
111
+ initialization, input encoding and copying, snapshot copying, and
112
+ rendering.
110
113
 
111
114
  ## License
112
115
 
package/RELEASE-NOTES.md CHANGED
@@ -1,22 +1,52 @@
1
- # Mausmark v0.6.0
1
+ # v0.7.1
2
2
 
3
- - `blockRange(index)` returns the complete syntax of supported blocks, including
4
- lists and list items, as a half-open UTF-8 byte range. `text(list)` still
5
- returns the CommonMark starting digits, including leading zeroes.
6
- - Migration for table renderers: walk `children(cell)` for both plain and rich
7
- cells. `text(cell)` is now empty; plain text lives in a `TEXT` child.
8
- - Contiguous text and metadata no longer split at 65,535 bytes. Line joins and
9
- discontinuous fields still use chunks.
10
- - WASM ABI is **8**. Deploy the JS bindings and WASM together. Records remain
11
- 16 bytes; the last word is now a 32-bit payload length or exclusive block end.
12
- - Fixed indented CommonMark HTML block termination and CRLF handling for list
13
- markers, fences, setext headings, table delimiters and Markdown custom blocks.
3
+ - The WebAssembly module in the npm package now fits the existing gzip
4
+ and Brotli size budgets. The parser API and WASM ABI are unchanged
5
+ from v0.7.0.
14
6
 
15
- # Mausmark v0.5.1
7
+ # v0.7.0
8
+
9
+ - `blockRange(cell)` now covers the trimmed cell syntax, excluding
10
+ delimiter pipes. An empty cell has a zero-length range.
11
+ - CRLF and bare CR are parsed like LF. Source ranges still address the
12
+ original UTF-8 bytes.
13
+ - Renderer migration: code and custom block lines no longer include
14
+ their line endings. Join their content chunks and append a final
15
+ newline if there was at least one content line. Multiline HTML
16
+ blocks may now have empty `text(index)`; use `joinedText(index)`.
17
+ Multiline inline HTML uses sibling chunks with `Join.NL` on
18
+ continuation lines.
19
+ - WASM ABI is 9 now. Deploy the matching JS bindings and WASM
20
+ together.
21
+ - Native C callers: use `MmParseMode` in place of `MmDialect`, and
22
+ `mm_parse` followed by `mm_render_html` in place of the native
23
+ `mm_to_html` helper.
24
+ - The CLI `format` command no longer reparses its output to check for
25
+ changes in meaning or formatting stability before emitting it.
26
+
27
+ # v0.6.0
28
+
29
+ - `blockRange(index)` returns the complete syntax of supported blocks,
30
+ including lists and list items, as a half-open UTF-8 byte range.
31
+ `text(list)` still returns the CommonMark starting digits, including
32
+ leading zeroes.
33
+ - Migration for table renderers: walk `children(cell)` for both plain
34
+ and rich cells. `text(cell)` is now empty; plain text lives in a
35
+ `TEXT` child.
36
+ - Contiguous text and metadata no longer split at 65,535 bytes. Line
37
+ joins and discontinuous fields still use chunks.
38
+ - WASM ABI is **8**. Deploy the JS bindings and WASM together. Records
39
+ remain 16 bytes; the last word is now a 32-bit payload length or
40
+ exclusive block end.
41
+ - Fixed indented CommonMark HTML block termination and CRLF handling
42
+ for list markers, fences, setext headings, table delimiters and
43
+ Markdown custom blocks.
44
+
45
+ # v0.5.1
16
46
 
17
47
  - Faster parsing of tab-indented CommonMark input.
18
48
 
19
- # Mausmark v0.5.0
49
+ # v0.5.0
20
50
 
21
51
  - Both dialects now recognize pipe tables. Custom renderers can handle
22
52
  `TABLE`, `TABLE_ROW` and `TABLE_CELL`; header cells carry column
@@ -43,7 +73,7 @@
43
73
  `--cm --no-table` in the CLI. Existing `Dialect` constants still
44
74
  work.
45
75
 
46
- # Mausmark v0.4.1
76
+ # v0.4.1
47
77
 
48
78
  - Simplified the DOM renderer example and fixed rendering of email
49
79
  autolinks and literal-text line joins.
@@ -54,7 +84,7 @@
54
84
  tooling.
55
85
  - Package exports and WASM ABI remain unchanged.
56
86
 
57
- # Mausmark v0.4.0
87
+ # v0.4.0
58
88
 
59
89
  - Image descriptions are alt text, not inline formatting. CommonMark
60
90
  keeps the text between the markup (`![a *b*](/i)` → `a b`); Markdown
package/dist/abi.d.ts CHANGED
@@ -85,4 +85,4 @@ export declare const NodeLayout: Readonly<{
85
85
  LENGTH: 12;
86
86
  BLOCK_END: 12;
87
87
  }>;
88
- export declare const ABI_VERSION = 8;
88
+ export declare const ABI_VERSION = 9;
package/dist/abi.js CHANGED
@@ -73,4 +73,4 @@ export const NodeLayout = Object.freeze({
73
73
  TYPE: 0, LEVEL: 1, FLAGS: 2, SUBTREE_END: 4,
74
74
  OFFSET: 8, LENGTH: 12, BLOCK_END: 12,
75
75
  });
76
- export const ABI_VERSION = 8;
76
+ export const ABI_VERSION = 9;
package/dist/core.d.ts CHANGED
@@ -40,7 +40,7 @@ export interface MausmarkDocument {
40
40
  offset(index: number): number;
41
41
  /** UTF-8 byte length of the node's text slice. */
42
42
  length(index: number): number;
43
- /** Complete syntax for paragraphs, headings, thematic breaks, quotes, lists/items, code, HTML, custom blocks, reference definitions/groups and tables/rows; UTF-8 bytes, end exclusive. */
43
+ /** Complete syntax for paragraphs, headings, thematic breaks, quotes, lists/items, code, HTML, custom blocks, reference definitions/groups and tables/rows/cells; UTF-8 bytes, end exclusive. */
44
44
  blockRange(index: number): {
45
45
  start: number;
46
46
  end: number;
package/dist/core.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import { ABI_VERSION, Join, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode } from './abi.js';
2
2
  export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode, ReferenceStyle, TableAlignment } from './abi.js';
3
+ const PARSE_MODE_FLAGS = ParseMode.COMMONMARK | ParseMode.NO_TABLE;
3
4
  const PAGE_SIZE = 64 * 1024;
4
5
  const ALIGNMENT = 16;
5
6
  const MAX_INPUT_BYTES = 64 * 1024 * 1024;
6
7
  const MAX_ARENA_BYTES = 512 * 1024 * 1024;
7
8
  const MAX_WASM_ADDRESS = 0x7fffffff;
9
+ const encoder = new TextEncoder();
8
10
  const decoder = new TextDecoder('utf-8', { ignoreBOM: true });
9
11
  function hasBlockRange(type) {
10
12
  return (type >= NodeType.PARAGRAPH && type <= NodeType.REF_DEF) || type === NodeType.CUSTOM ||
11
- type === NodeType.TABLE || type === NodeType.TABLE_ROW;
13
+ type === NodeType.TABLE || type === NodeType.TABLE_ROW || type === NodeType.TABLE_CELL;
12
14
  }
13
15
  function align(value) {
14
16
  if (!Number.isSafeInteger(value) || value < 0 || value > MAX_WASM_ADDRESS - (ALIGNMENT - 1)) {
@@ -67,7 +69,7 @@ class PackedDocument {
67
69
  const type = this.type(index);
68
70
  if (type === NodeType.HTML_BLOCK) {
69
71
  const base = index * NODE_SIZE, aux = this.#view.getInt16(base + NodeLayout.FLAGS, true);
70
- return aux < 0 ? 0 : this.#view.getUint32(base + NodeLayout.OFFSET, true) + (aux & 3);
72
+ return aux < 0 ? 0 : this.#view.getUint32(base + NodeLayout.OFFSET, true) + aux;
71
73
  }
72
74
  if (hasBlockRange(type) && (type !== NodeType.LIST || !this.length(index)))
73
75
  return 0;
@@ -81,7 +83,7 @@ class PackedDocument {
81
83
  if (type === NodeType.HTML_BLOCK) {
82
84
  const base = index * NODE_SIZE, aux = this.#view.getInt16(base + NodeLayout.FLAGS, true);
83
85
  return aux < 0 ? 0 : this.#view.getUint32(base + NodeLayout.BLOCK_END, true) -
84
- this.#view.getUint32(base + NodeLayout.OFFSET, true) - (aux & 3) + (aux >> 2) - 1;
86
+ this.#view.getUint32(base + NodeLayout.OFFSET, true) - aux;
85
87
  }
86
88
  if (hasBlockRange(type))
87
89
  return 0;
@@ -180,15 +182,13 @@ class PackedDocument {
180
182
  const offset = view.getUint32(base + NodeLayout.OFFSET, true);
181
183
  if (hasBlockRange(type)) {
182
184
  const blockEnd = view.getUint32(base + NodeLayout.BLOCK_END, true);
183
- if (blockEnd > sourceLength || offset >= blockEnd) {
185
+ if (blockEnd > sourceLength || offset > blockEnd || (offset === blockEnd && type !== NodeType.TABLE_CELL)) {
184
186
  throw new Error(`mausmark: malformed block range on node ${index}`);
185
187
  }
186
188
  if (type === NodeType.HTML_BLOCK) {
187
189
  const aux = view.getInt16(base + NodeLayout.FLAGS, true);
188
- // Most leaves have exactly the syntax extent; only adjusted slices need bounds checks.
189
- const payloadEnd = blockEnd + (aux >> 2) - 1;
190
- const valid = end === index + 1 ? aux === 4 || (aux >= 0 && aux <= 15 &&
191
- offset + (aux & 3) < payloadEnd && payloadEnd <= sourceLength) : aux === -1;
190
+ // A leaf's payload skips aux (0-3) indent bytes and ends with the block.
191
+ const valid = end === index + 1 ? aux >= 0 && aux <= 3 && offset + aux < blockEnd : aux === -1;
192
192
  if (!valid)
193
193
  throw new Error(`mausmark: malformed HTML payload on node ${index}`);
194
194
  }
@@ -216,17 +216,20 @@ class WasmParser {
216
216
  parse(markdown, mode = ParseMode.MARKDOWN) {
217
217
  if (typeof markdown !== 'string')
218
218
  throw new TypeError('mausmark: markdown must be a string');
219
- const source = new TextEncoder().encode(markdown);
219
+ // A typo such as 'cm' must not silently parse as Markdown.
220
+ if (!Number.isInteger(mode) || (mode & ~PARSE_MODE_FLAGS) !== 0) {
221
+ throw new TypeError('mausmark: mode must be a combination of ParseMode flags');
222
+ }
223
+ const source = encoder.encode(markdown);
220
224
  if (source.byteLength > MAX_INPUT_BYTES) {
221
225
  throw new RangeError(`mausmark: input exceeds the ${MAX_INPUT_BYTES / 1024 / 1024} MiB limit`);
222
226
  }
223
227
  const inputPointer = align(this.#wasm.heapBase);
224
228
  const arenaPointer = align(checkedAdd(inputPointer, source.byteLength, 'input address exceeds the WASM address limit'));
225
229
  let arenaSize = initialArenaSize(source.byteLength);
230
+ this.ensureMemory(checkedAdd(arenaPointer, arenaSize, 'input and arena exceed the WASM address limit'));
231
+ new Uint8Array(this.#wasm.memory.buffer, inputPointer, source.byteLength).set(source);
226
232
  while (true) {
227
- const required = checkedAdd(arenaPointer, arenaSize, 'input and arena exceed the WASM address limit');
228
- this.ensureMemory(required);
229
- new Uint8Array(this.#wasm.memory.buffer, inputPointer, source.byteLength).set(source);
230
233
  const headerPointer = this.#wasm.parseDom(inputPointer, source.byteLength, arenaPointer, arenaSize, mode);
231
234
  if (headerPointer >= 0)
232
235
  return this.copyDocument(source, headerPointer);
@@ -234,6 +237,7 @@ class WasmParser {
234
237
  throw new RangeError(`mausmark: parsing requires more than the ${MAX_ARENA_BYTES / 1024 / 1024} MiB arena limit`);
235
238
  }
236
239
  arenaSize = Math.min(MAX_ARENA_BYTES, arenaSize * 2);
240
+ this.ensureMemory(checkedAdd(arenaPointer, arenaSize, 'input and arena exceed the WASM address limit'));
237
241
  }
238
242
  }
239
243
  ensureMemory(required) {
Binary file
package/dom-example.js CHANGED
@@ -174,7 +174,16 @@ export function renderToDom(doc, parent) {
174
174
  }
175
175
  }
176
176
 
177
- code.textContent = doc.joinedText(index);
177
+ // Lines carry no line ending; the last one's is implied.
178
+ let content = "";
179
+ let lines = false;
180
+ for (const child of doc.children(index)) {
181
+ if (doc.type(child) === NodeType.LABEL) continue;
182
+ const join = doc.level(child);
183
+ content += (join === Join.NL ? "\n" : (join === Join.SPACE ? " " : "")) + doc.text(child);
184
+ lines = true;
185
+ }
186
+ code.textContent = lines ? content + "\n" : "";
178
187
  const pre = document.createElement("pre");
179
188
  pre.appendChild(code);
180
189
  into.appendChild(pre);
@@ -260,9 +269,13 @@ export function renderToDom(doc, parent) {
260
269
 
261
270
  case NodeType.HTML_BLOCK:
262
271
  case NodeType.HTML_INLINE:
272
+ // Other source-backed content stays text; customize as needed. A
273
+ // tag spanning lines is one chunk per line, later ones led by Join.NL.
274
+ text((doc.level(index) === Join.NL ? "\n" : "") + doc.joinedText(index), into);
275
+ return;
263
276
  case NodeType.CUSTOM:
264
- // Other source-backed content stays text; customize as needed.
265
- text(doc.joinedText(index), into);
277
+ // Lines carry no line ending; the last one's is implied.
278
+ text(doc.subtreeEnd(index) > index + 1 ? doc.joinedText(index) + "\n" : "", into);
266
279
  return;
267
280
 
268
281
  case NodeType.TEXT:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mausmark",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "A fast, dependency-free Markdown parser compiled to WebAssembly",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,23 +27,23 @@
27
27
  "HTML-LICENSE.txt"
28
28
  ],
29
29
  "scripts": {
30
- "clean": "rm -rf dist",
31
- "build:wasm": "./build.sh wasm --ast-only",
32
- "build:js": "./build.sh codegen && tsc -p tsconfig.json",
33
30
  "build": "npm run clean && npm run build:wasm && npm run build:js",
34
- "check:wasm-size": "node test/wasm_size.mjs",
35
- "test:package": "node --test test/npm-package.test.mjs test/dom-example.test.mjs test/text-decoding.test.mjs test/webdriver.test.mjs test/browser-benchmark.test.mjs test/wasm-size.test.mjs test/source-retention.test.mjs test/test-registration.test.mjs test/reference-matching.test.mjs",
36
- "test:types": "tsc -p tsconfig.test.json --noEmit && tsc -p tsconfig.references.json",
37
- "test:browser": "node test/browser/run.mjs",
31
+ "build:js": "./build.sh codegen && tsc -p tsconfig.json",
32
+ "build:wasm": "./build.sh wasm --ast-only",
38
33
  "bench:browser": "npm run build && ./build.sh wasm && node benchmark/browser/run.mjs",
34
+ "check:entities": "node tools/entities.mjs --check",
35
+ "check:unicode": "node tools/unicode.mjs --check && node tools/case-fold.mjs --check",
36
+ "check:wasm-size": "node test/wasm_size.mjs",
39
37
  "setup:chrome": "node test/browser/setup-chrome.mjs",
40
- "test:layers": "node --test test/layers.test.mjs",
38
+ "test": "npm run test:build && npm run test:layers && npm run build && npm run check:wasm-size && npm run test:package && npm run test:types && npm run test:browser",
39
+ "test:browser": "node test/browser/run.mjs",
41
40
  "test:build": "node --test test/build.test.mjs",
42
- "check:unicode": "node tools/unicode.mjs --check && node tools/case-fold.mjs --check",
43
- "test:unicode": "node --test test/unicode.test.mjs test/case-fold.test.mjs",
44
- "check:entities": "node tools/entities.mjs --check",
45
41
  "test:entities": "node --test test/entities.test.mjs",
46
- "test": "npm run test:build && npm run test:layers && npm run build && npm run check:wasm-size && npm run test:package && npm run test:types && npm run test:browser",
42
+ "test:layers": "node --test test/layers.test.mjs",
43
+ "test:package": "node --test test/npm-package.test.mjs test/dom-example.test.mjs test/text-decoding.test.mjs test/webdriver.test.mjs test/browser-benchmark.test.mjs test/wasm-size.test.mjs test/source-retention.test.mjs test/test-registration.test.mjs test/reference-matching.test.mjs",
44
+ "test:types": "tsc -p tsconfig.test.json --noEmit && tsc -p tsconfig.references.json",
45
+ "test:unicode": "node --test test/unicode.test.mjs test/case-fold.test.mjs",
46
+ "clean": "rm -rf dist",
47
47
  "prepack": "npm test"
48
48
  },
49
49
  "engines": {