mausmark 0.4.1 → 0.5.0
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 +54 -18
- package/RELEASE-NOTES.md +27 -0
- package/dist/abi.d.ts +18 -2
- package/dist/abi.js +16 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/core.d.ts +11 -8
- package/dist/core.js +4 -4
- package/dist/mausmark.wasm +0 -0
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dom-example.js +49 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,6 +72,40 @@ the document so that you could reproduce it exactly (minus whitespace).
|
|
|
72
72
|
Raw HTML is returned as `NodeType.HTML_BLOCK` or `NodeType.HTML_INLINE`;
|
|
73
73
|
sanitize it when parsing untrusted input.
|
|
74
74
|
|
|
75
|
+
Both Markdown and CommonMark support pipe tables starting at a block
|
|
76
|
+
boundary with a header and a matching GFM-style divider row. Leave a
|
|
77
|
+
blank line before a table that follows a paragraph. Colons on the
|
|
78
|
+
divider set left, center, or right column alignment. Body rows must
|
|
79
|
+
contain a structural pipe; HTML rendering treats missing cells as empty
|
|
80
|
+
and ignores excess cells; the tree and formatter retain excess source
|
|
81
|
+
cells. Escape a literal pipe within a table as `\|`, including inside
|
|
82
|
+
code spans. Outside tables the Markdown dialect preserves the backslash
|
|
83
|
+
in `\|`. A following line without a structural pipe ends the table and
|
|
84
|
+
is parsed as ordinary block content. Valid Markdown block openers,
|
|
85
|
+
including reference definitions, also take precedence. Use a leading `|`
|
|
86
|
+
to keep definition-shaped text in a cell. Backtick fences open blocks in
|
|
87
|
+
CommonMark; in the Markdown dialect a custom block opens with `{` alone
|
|
88
|
+
on its line. Native HTML rendering emits alignment as `align`
|
|
89
|
+
attributes. In right-aligned columns, the formatter lines up numeric
|
|
90
|
+
body cells by decimal point, treating integers as having an implied
|
|
91
|
+
point after the last digit. It measures the Markdown source, counting
|
|
92
|
+
combining marks as zero columns and wide/fullwidth characters as two.
|
|
93
|
+
Widths are per Unicode scalar; an editor that displays a multi-character
|
|
94
|
+
emoji as one glyph can differ. This is a bounded subset, not full GFM or
|
|
95
|
+
MultiMarkdown table support. Pass `--no-table` to disable recognition in
|
|
96
|
+
either dialect (`--cm --no-table` for plain CommonMark). In JS use
|
|
97
|
+
`ParseMode.NO_TABLE` alone for Markdown, or
|
|
98
|
+
`ParseMode.COMMONMARK | ParseMode.NO_TABLE` for CommonMark. C uses the
|
|
99
|
+
same bitmask: `MM_PARSE_COMMONMARK | MM_PARSE_NO_TABLE`.
|
|
100
|
+
|
|
101
|
+
In the tree, a `TABLE` contains `TABLE_ROW` nodes, header first; rows
|
|
102
|
+
contain `TABLE_CELL` nodes. Header cell `level()` records a
|
|
103
|
+
`TableAlignment`: `DEFAULT` (0), `LEFT` (1), `CENTER` (2), or `RIGHT`
|
|
104
|
+
(3). Body rows preserve their original cell counts, so renderers should
|
|
105
|
+
apply the header width when presenting a rectangular table. A short
|
|
106
|
+
plain cell stores its text directly on the cell node. For rich content,
|
|
107
|
+
walk the cell's inline children.
|
|
108
|
+
|
|
75
109
|
In the default Markdown dialect, `{text **bold** text}` is a
|
|
76
110
|
`NodeType.BRACE_SPAN` with parsed inline children. `text(index)` returns
|
|
77
111
|
the exact original interior, `text **bold** text`, excluding its outer
|
|
@@ -160,8 +194,10 @@ Things to decide when building a richer renderer:
|
|
|
160
194
|
render arbitrary inline markup. In CommonMark, a `LITERAL_TEXT` leaf
|
|
161
195
|
must not be entity-decoded with its neighboring `TEXT`.
|
|
162
196
|
- `link(index)` works on `LINK`, `IMAGE`, and `REF_DEF` and returns
|
|
163
|
-
**raw** URL, title, label, and `ReferenceStyle`.
|
|
164
|
-
|
|
197
|
+
**raw** URL, title, label, and `ReferenceStyle`. In table cells the
|
|
198
|
+
table-syntax backslash before an escaped pipe is removed, including
|
|
199
|
+
in these fields; other escapes and entities remain raw. Destinations
|
|
200
|
+
and titles over 65,535 bytes are kept as field-child text chunks;
|
|
165
201
|
`link()` joins them without truncation. Inline links and autolinks
|
|
166
202
|
already have destinations; `FULL`, `COLLAPSED`, and `SHORTCUT` need
|
|
167
203
|
a definition lookup. Scan all node indexes for `REF_DEF` (including
|
|
@@ -188,17 +224,17 @@ Things to decide when building a richer renderer:
|
|
|
188
224
|
|
|
189
225
|
## Performance
|
|
190
226
|
|
|
191
|
-
The SIMD WebAssembly parser build is
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
Bun 1.4.2, compiled with Clang 22.1.7 at `-Os` with LTO:
|
|
227
|
+
The SIMD WebAssembly parser build is 74,348 bytes uncompressed or 26,982
|
|
228
|
+
bytes with Brotli (quality 11, offline precompression). Source-to-AST
|
|
229
|
+
measurements on November 20, 2026, on an Apple M3 Pro, Node.js 26.3.1
|
|
230
|
+
and Bun 1.4.2, compiled with Clang 22.1.7 at `-Os` with LTO:
|
|
195
231
|
|
|
196
232
|
| Input | Node (µs) | Bun (µs) | Node (GB/s) | Bun (GB/s) |
|
|
197
233
|
| ---------------------- | --------: | -------: | ----------: | ---------: |
|
|
198
|
-
| Moby-Dick (1.2 MB) | ~
|
|
199
|
-
| Line-wrapped Moby-Dick | ~
|
|
200
|
-
| Pro Git chapters |
|
|
201
|
-
| tldr pages | 1.
|
|
234
|
+
| Moby-Dick (1.2 MB) | ~307 | ~245 | 3.9 | 4.9 |
|
|
235
|
+
| Line-wrapped Moby-Dick | ~404 | ~287 | 3 | 4.2 |
|
|
236
|
+
| Pro Git chapters | 34.2 | 27.3 | 1.63 | 2.04 |
|
|
237
|
+
| tldr pages | 1.4 | 1.23 | 0.4 | 0.46 |
|
|
202
238
|
|
|
203
239
|
These are warmed parser-export timings with preloaded UTF-8 input and a
|
|
204
240
|
reused arena, including JavaScript iteration and export-call overhead.
|
|
@@ -206,23 +242,23 @@ They exclude initialization, input encoding/copying, AST snapshot
|
|
|
206
242
|
copying, and rendering; they are not end-to-end timings of the package’s
|
|
207
243
|
`parse()` method. The corpus rows (Pro Git, tldr) report average time
|
|
208
244
|
per document; figures are medians across three alternating passes, each
|
|
209
|
-
with five timing samples.
|
|
210
|
-
|
|
211
|
-
bytes.
|
|
245
|
+
with five timing samples. Both Moby-Dick inputs and Pro Git use
|
|
246
|
+
Markdown; tldr uses CommonMark. GB/s uses decimal bytes.
|
|
212
247
|
|
|
213
248
|
## Notes
|
|
214
249
|
|
|
215
250
|
- Input is limited to 64 MiB; parser arena growth is limited to 512
|
|
216
251
|
MiB.
|
|
217
|
-
- Two input dialects. `Dialect.MARKDOWN` (the default)
|
|
218
|
-
Markdown
|
|
219
|
-
|
|
252
|
+
- Two input dialects. `Dialect.MARKDOWN` (the default) extends
|
|
253
|
+
original Markdown with brace syntax and pipe tables;
|
|
254
|
+
`Dialect.COMMONMARK` is based on CommonMark 0.31.2, currently
|
|
255
|
+
649/652 (99.5%) of its spec suite byte-exact. Three
|
|
220
256
|
definition-dependent reference-link cases are intentionally
|
|
221
257
|
unresolved.
|
|
222
258
|
- Unlike CommonMark, an image description is plain alt text, not
|
|
223
259
|
inline content.
|
|
224
|
-
- No GFM
|
|
225
|
-
|
|
260
|
+
- No full GFM dialect: strikethrough, task lists and autolink literals
|
|
261
|
+
are not supported.
|
|
226
262
|
|
|
227
263
|
The npm package contains ESM bindings, TypeScript declarations,
|
|
228
264
|
precompiled WebAssembly, and the renderer example. The implementation
|
package/RELEASE-NOTES.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
# Mausmark v0.5.0
|
|
2
|
+
|
|
3
|
+
- Both dialects now recognize pipe tables. Custom renderers can handle
|
|
4
|
+
`TABLE`, `TABLE_ROW` and `TABLE_CELL`; header cells carry column
|
|
5
|
+
alignment.
|
|
6
|
+
- The formatter pads table columns to a common width, counting wide
|
|
7
|
+
characters as two columns and combining marks as zero. Numbers in
|
|
8
|
+
right-aligned columns line up on the decimal point.
|
|
9
|
+
- WASM ABI is now 7. Deploy the matching JS bindings and WASM
|
|
10
|
+
together. Node records remain 16 bytes.
|
|
11
|
+
- Faster WASM parsing of adjacent backslash escapes and faster
|
|
12
|
+
native/WASM HTML rendering of code chunks that are contiguous in the
|
|
13
|
+
source.
|
|
14
|
+
- Fixed native HTML escaping for multiline reference titles on links
|
|
15
|
+
and images when using the CommonMark parser with default HTML
|
|
16
|
+
output.
|
|
17
|
+
- Faster parsing of deeply nested brackets and consecutive quoted
|
|
18
|
+
reference definitions in CommonMark.
|
|
19
|
+
- Faster Markdown formatting for long paragraphs where wrapping would
|
|
20
|
+
turn text into a list or another block. Existing line breaks chosen
|
|
21
|
+
by the formatter are preserved.
|
|
22
|
+
- Migration: CommonMark input now parses a pipe header followed by a
|
|
23
|
+
divider row as a table, where v0.4 produced paragraphs. To keep the
|
|
24
|
+
previous output, use `ParseMode.COMMONMARK | ParseMode.NO_TABLE`, or
|
|
25
|
+
`--cm --no-table` in the CLI. Existing `Dialect` constants still
|
|
26
|
+
work.
|
|
27
|
+
|
|
1
28
|
# Mausmark v0.4.1
|
|
2
29
|
|
|
3
30
|
- Simplified the DOM renderer example and fixed rendering of email
|
package/dist/abi.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ export declare const NodeType: Readonly<{
|
|
|
25
25
|
readonly TITLE: 23;
|
|
26
26
|
readonly LABEL: 24;
|
|
27
27
|
readonly BRACE_SPAN: 25;
|
|
28
|
+
readonly TABLE: 26;
|
|
29
|
+
readonly TABLE_ROW: 27;
|
|
30
|
+
readonly TABLE_CELL: 28;
|
|
28
31
|
}>;
|
|
29
32
|
export type NodeType = (typeof NodeType)[keyof typeof NodeType];
|
|
30
33
|
export declare const ReferenceStyle: Readonly<{
|
|
@@ -42,6 +45,13 @@ export declare const Join: Readonly<{
|
|
|
42
45
|
readonly NL: 2;
|
|
43
46
|
}>;
|
|
44
47
|
export type Join = (typeof Join)[keyof typeof Join];
|
|
48
|
+
export declare const TableAlignment: Readonly<{
|
|
49
|
+
readonly DEFAULT: 0;
|
|
50
|
+
readonly LEFT: 1;
|
|
51
|
+
readonly CENTER: 2;
|
|
52
|
+
readonly RIGHT: 3;
|
|
53
|
+
}>;
|
|
54
|
+
export type TableAlignment = (typeof TableAlignment)[keyof typeof TableAlignment];
|
|
45
55
|
export declare const ListFlags: Readonly<{
|
|
46
56
|
readonly ORDERED: 1;
|
|
47
57
|
readonly LOOSE: 2;
|
|
@@ -52,13 +62,19 @@ export declare const Dialect: Readonly<{
|
|
|
52
62
|
readonly COMMONMARK: 1;
|
|
53
63
|
}>;
|
|
54
64
|
export type Dialect = (typeof Dialect)[keyof typeof Dialect];
|
|
65
|
+
export declare const ParseMode: Readonly<{
|
|
66
|
+
readonly MARKDOWN: 0;
|
|
67
|
+
readonly COMMONMARK: 1;
|
|
68
|
+
readonly NO_TABLE: 2;
|
|
69
|
+
}>;
|
|
70
|
+
export type ParseMode = number;
|
|
55
71
|
export declare const HtmlMode: Readonly<{
|
|
56
72
|
readonly FULL: 0;
|
|
57
73
|
readonly FRAGMENT: 1;
|
|
58
74
|
readonly COMMONMARK: 2;
|
|
59
75
|
}>;
|
|
60
76
|
export type HtmlMode = (typeof HtmlMode)[keyof typeof HtmlMode];
|
|
61
|
-
export declare const NODE_TYPE_MAX:
|
|
77
|
+
export declare const NODE_TYPE_MAX: 28;
|
|
62
78
|
export declare const NODE_SIZE = 16;
|
|
63
79
|
export declare const NodeLayout: Readonly<{
|
|
64
80
|
TYPE: 0;
|
|
@@ -68,4 +84,4 @@ export declare const NodeLayout: Readonly<{
|
|
|
68
84
|
OFFSET: 8;
|
|
69
85
|
LENGTH: 12;
|
|
70
86
|
}>;
|
|
71
|
-
export declare const ABI_VERSION =
|
|
87
|
+
export declare const ABI_VERSION = 7;
|
package/dist/abi.js
CHANGED
|
@@ -26,6 +26,9 @@ export const NodeType = Object.freeze({
|
|
|
26
26
|
TITLE: 23,
|
|
27
27
|
LABEL: 24,
|
|
28
28
|
BRACE_SPAN: 25,
|
|
29
|
+
TABLE: 26,
|
|
30
|
+
TABLE_ROW: 27,
|
|
31
|
+
TABLE_CELL: 28,
|
|
29
32
|
});
|
|
30
33
|
export const ReferenceStyle = Object.freeze({
|
|
31
34
|
INLINE: 0,
|
|
@@ -40,6 +43,12 @@ export const Join = Object.freeze({
|
|
|
40
43
|
SPACE: 1,
|
|
41
44
|
NL: 2,
|
|
42
45
|
});
|
|
46
|
+
export const TableAlignment = Object.freeze({
|
|
47
|
+
DEFAULT: 0,
|
|
48
|
+
LEFT: 1,
|
|
49
|
+
CENTER: 2,
|
|
50
|
+
RIGHT: 3,
|
|
51
|
+
});
|
|
43
52
|
export const ListFlags = Object.freeze({
|
|
44
53
|
ORDERED: 1,
|
|
45
54
|
LOOSE: 2,
|
|
@@ -48,15 +57,20 @@ export const Dialect = Object.freeze({
|
|
|
48
57
|
MARKDOWN: 0,
|
|
49
58
|
COMMONMARK: 1,
|
|
50
59
|
});
|
|
60
|
+
export const ParseMode = Object.freeze({
|
|
61
|
+
MARKDOWN: 0,
|
|
62
|
+
COMMONMARK: 1,
|
|
63
|
+
NO_TABLE: 2,
|
|
64
|
+
});
|
|
51
65
|
export const HtmlMode = Object.freeze({
|
|
52
66
|
FULL: 0,
|
|
53
67
|
FRAGMENT: 1,
|
|
54
68
|
COMMONMARK: 2,
|
|
55
69
|
});
|
|
56
|
-
export const NODE_TYPE_MAX = NodeType.
|
|
70
|
+
export const NODE_TYPE_MAX = NodeType.TABLE_CELL;
|
|
57
71
|
export const NODE_SIZE = 16;
|
|
58
72
|
export const NodeLayout = Object.freeze({
|
|
59
73
|
TYPE: 0, LEVEL: 1, FLAGS: 2, SUBTREE_END: 4,
|
|
60
74
|
OFFSET: 8, LENGTH: 12,
|
|
61
75
|
});
|
|
62
|
-
export const ABI_VERSION =
|
|
76
|
+
export const ABI_VERSION = 7;
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ReferenceStyle, } from './core.js';
|
|
1
|
+
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode, ReferenceStyle, TableAlignment, } from './core.js';
|
|
2
2
|
export type { LinkFields, MausmarkDocument, MausmarkParser } from './core.js';
|
|
3
3
|
/** Fetch and initialize the package-relative WASM parser in a browser. */
|
|
4
4
|
export declare function createParser(): Promise<import('./core.js').MausmarkParser>;
|
package/dist/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parserFromInstance } from './core.js';
|
|
2
|
-
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ReferenceStyle, } from './core.js';
|
|
2
|
+
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode, ReferenceStyle, TableAlignment, } from './core.js';
|
|
3
3
|
/** Fetch and initialize the package-relative WASM parser in a browser. */
|
|
4
4
|
export async function createParser() {
|
|
5
5
|
const response = await fetch(new URL('./mausmark.wasm', import.meta.url));
|
package/dist/core.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NodeType, ParseMode } from './abi.js';
|
|
2
2
|
import type { ReferenceStyle } from './abi.js';
|
|
3
|
-
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ReferenceStyle } from './abi.js';
|
|
4
|
-
/** Raw, unresolved LINK/IMAGE/REF_DEF fields.
|
|
5
|
-
*
|
|
3
|
+
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode, ReferenceStyle, TableAlignment } from './abi.js';
|
|
4
|
+
/** Raw, unresolved LINK/IMAGE/REF_DEF fields. In table cells the table-syntax
|
|
5
|
+
* backslash before an escaped pipe is removed, including in these fields.
|
|
6
|
+
* Absent and empty fields are `''`; a leading TITLE node distinguishes an
|
|
7
|
+
* explicit empty title from no title. */
|
|
6
8
|
export interface LinkFields {
|
|
7
|
-
/** Destination as written: backslash escapes and entities are not processed. */
|
|
9
|
+
/** Destination as written: other backslash escapes and entities are not processed. */
|
|
8
10
|
readonly url: string;
|
|
9
11
|
/** Title as written, without its quotes. */
|
|
10
12
|
readonly title: string;
|
|
@@ -26,7 +28,8 @@ export interface MausmarkDocument {
|
|
|
26
28
|
type(index: number): NodeType;
|
|
27
29
|
/**
|
|
28
30
|
* Type-specific value: the heading level on HEADING, the `ReferenceStyle` on
|
|
29
|
-
* LINK and IMAGE, the `Join` code on TEXT/LITERAL_TEXT, the marker on LIST
|
|
31
|
+
* LINK and IMAGE, the `Join` code on TEXT/LITERAL_TEXT, the marker on LIST,
|
|
32
|
+
* or `TableAlignment` on a header TABLE_CELL.
|
|
30
33
|
*/
|
|
31
34
|
level(index: number): number;
|
|
32
35
|
/** `ListFlags` bits on LIST and LIST_ITEM. Other bits and nodes are internal. */
|
|
@@ -56,8 +59,8 @@ export interface MausmarkDocument {
|
|
|
56
59
|
}
|
|
57
60
|
/** A synchronously usable parser after its WASM module has initialized. */
|
|
58
61
|
export interface MausmarkParser {
|
|
59
|
-
/** Parse `markdown
|
|
60
|
-
parse(markdown: string,
|
|
62
|
+
/** Parse `markdown` with combinable ParseMode flags (default: Markdown). */
|
|
63
|
+
parse(markdown: string, mode?: ParseMode): MausmarkDocument;
|
|
61
64
|
}
|
|
62
65
|
/** @internal Shared loader validation used by the Node and browser entry points. */
|
|
63
66
|
export declare function parserFromInstance(instance: WebAssembly.Instance, createDecoder?: SourceDecoderFactory): MausmarkParser;
|
package/dist/core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ABI_VERSION,
|
|
2
|
-
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ReferenceStyle } from './abi.js';
|
|
1
|
+
import { ABI_VERSION, Join, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode } from './abi.js';
|
|
2
|
+
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode, ReferenceStyle, TableAlignment } from './abi.js';
|
|
3
3
|
const PAGE_SIZE = 64 * 1024;
|
|
4
4
|
const ALIGNMENT = 16;
|
|
5
5
|
const MAX_INPUT_BYTES = 64 * 1024 * 1024;
|
|
@@ -159,7 +159,7 @@ class WasmParser {
|
|
|
159
159
|
this.#wasm = wasm;
|
|
160
160
|
this.#createSourceDecoder = createDecoder;
|
|
161
161
|
}
|
|
162
|
-
parse(markdown,
|
|
162
|
+
parse(markdown, mode = ParseMode.MARKDOWN) {
|
|
163
163
|
if (typeof markdown !== 'string')
|
|
164
164
|
throw new TypeError('mausmark: markdown must be a string');
|
|
165
165
|
const source = new TextEncoder().encode(markdown);
|
|
@@ -173,7 +173,7 @@ class WasmParser {
|
|
|
173
173
|
const required = checkedAdd(arenaPointer, arenaSize, 'input and arena exceed the WASM address limit');
|
|
174
174
|
this.ensureMemory(required);
|
|
175
175
|
new Uint8Array(this.#wasm.memory.buffer, inputPointer, source.byteLength).set(source);
|
|
176
|
-
const headerPointer = this.#wasm.parseDom(inputPointer, source.byteLength, arenaPointer, arenaSize,
|
|
176
|
+
const headerPointer = this.#wasm.parseDom(inputPointer, source.byteLength, arenaPointer, arenaSize, mode);
|
|
177
177
|
if (headerPointer >= 0)
|
|
178
178
|
return this.copyDocument(source, headerPointer);
|
|
179
179
|
if (arenaSize >= MAX_ARENA_BYTES) {
|
package/dist/mausmark.wasm
CHANGED
|
Binary file
|
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ReferenceStyle, } from './core.js';
|
|
1
|
+
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode, ReferenceStyle, TableAlignment, } from './core.js';
|
|
2
2
|
export type { LinkFields, MausmarkDocument, MausmarkParser } from './core.js';
|
|
3
3
|
/** Load the package's WASM parser for Node.js. */
|
|
4
4
|
export declare function createParser(): Promise<import('./core.js').MausmarkParser>;
|
package/dist/node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import { parserFromInstance } from './core.js';
|
|
4
|
-
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ReferenceStyle, } from './core.js';
|
|
4
|
+
export { ABI_VERSION, Dialect, HtmlMode, Join, ListFlags, NODE_SIZE, NODE_TYPE_MAX, NodeLayout, NodeType, ParseMode, ReferenceStyle, TableAlignment, } from './core.js';
|
|
5
5
|
function createSourceDecoder(source) {
|
|
6
6
|
// Share the document's owned bytes, not WASM memory or the input string.
|
|
7
7
|
const buffer = Buffer.from(source.buffer, source.byteOffset, source.byteLength);
|
package/dom-example.js
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|
import {Join, ListFlags, NodeType, ReferenceStyle} from "mausmark";
|
|
25
25
|
|
|
26
|
+
const tableAlign = ["", "left", "center", "right"];
|
|
27
|
+
|
|
26
28
|
/** @import {MausmarkDocument} from "mausmark" */
|
|
27
29
|
/** @import {LinkFields} from "mausmark" */
|
|
28
30
|
|
|
@@ -54,6 +56,12 @@ export function renderToDom(doc, parent) {
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/** @param {number} index @param {ParentNode} into */
|
|
60
|
+
function tableCellContent(index, into) {
|
|
61
|
+
if (doc.subtreeEnd(index) > index + 1) children(index, into);
|
|
62
|
+
else text(doc.text(index), into);
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
/** @param {string} tag @param {number} index @param {ParentNode} into */
|
|
58
66
|
function element(tag, index, into) {
|
|
59
67
|
const el = document.createElement(tag);
|
|
@@ -91,6 +99,47 @@ export function renderToDom(doc, parent) {
|
|
|
91
99
|
element("blockquote", index, into);
|
|
92
100
|
return;
|
|
93
101
|
|
|
102
|
+
case NodeType.TABLE: {
|
|
103
|
+
const table = document.createElement("table");
|
|
104
|
+
const rows = doc.children(index)[Symbol.iterator]();
|
|
105
|
+
const first = rows.next();
|
|
106
|
+
if (!first.done) {
|
|
107
|
+
const columns = Array.from(doc.children(first.value));
|
|
108
|
+
const head = document.createElement("thead");
|
|
109
|
+
const header = document.createElement("tr");
|
|
110
|
+
for (const column of columns) {
|
|
111
|
+
const cell = document.createElement("th");
|
|
112
|
+
const align = tableAlign[doc.level(column)];
|
|
113
|
+
if (align) cell.setAttribute("align", align);
|
|
114
|
+
tableCellContent(column, cell);
|
|
115
|
+
header.appendChild(cell);
|
|
116
|
+
}
|
|
117
|
+
head.appendChild(header);
|
|
118
|
+
table.appendChild(head);
|
|
119
|
+
let row = rows.next();
|
|
120
|
+
if (!row.done) {
|
|
121
|
+
const body = document.createElement("tbody");
|
|
122
|
+
do {
|
|
123
|
+
const tr = document.createElement("tr");
|
|
124
|
+
const cells = doc.children(row.value)[Symbol.iterator]();
|
|
125
|
+
for (const column of columns) {
|
|
126
|
+
const cell = document.createElement("td");
|
|
127
|
+
const align = tableAlign[doc.level(column)];
|
|
128
|
+
if (align) cell.setAttribute("align", align);
|
|
129
|
+
const source = cells.next();
|
|
130
|
+
if (!source.done) tableCellContent(source.value, cell);
|
|
131
|
+
tr.appendChild(cell);
|
|
132
|
+
}
|
|
133
|
+
body.appendChild(tr);
|
|
134
|
+
row = rows.next();
|
|
135
|
+
} while (!row.done);
|
|
136
|
+
table.appendChild(body);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
into.appendChild(table);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
94
143
|
case NodeType.LIST: {
|
|
95
144
|
const list = element((doc.flags(index) & ListFlags.ORDERED) ? "ol" : "ul", index, into);
|
|
96
145
|
// CommonMark ordered lists retain their starting digits.
|