mausmark 0.1.0-alpha.0 → 0.1.0-alpha.2
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 +53 -156
- package/dist/mausmark.wasm +0 -0
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -1,176 +1,73 @@
|
|
|
1
1
|
# Mausmark
|
|
2
2
|
|
|
3
|
-
A fast,
|
|
3
|
+
A fast, renderer-agnostic Markdown parser.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Alpha: still in active development the API may change.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
much is used, and the parser runs anywhere a C function can be called —
|
|
13
|
-
including `wasm32` with no runtime shims.
|
|
14
|
-
- **No build system** Single translation unit, one compiler invocation,
|
|
15
|
-
no build system or link step. The same source compiles to native or wasm.
|
|
16
|
-
- **Fast.** A real-world article (~7 KB) parses and renders in ~4 µs; a book
|
|
17
|
-
(Moby-Dick, 1.2 MB) in ~0.33 ms on an M3 Pro. See
|
|
18
|
-
[Performance](#performance).
|
|
19
|
-
|
|
20
|
-
## Quick start
|
|
21
|
-
|
|
22
|
-
./build.sh cli # builds ./mausmark
|
|
23
|
-
./mausmark README.md # markdown file -> HTML on stdout
|
|
24
|
-
cat README.md | ./mausmark # or read stdin
|
|
25
|
-
./mausmark format file.md # reformat markdown -> markdown
|
|
26
|
-
|
|
27
|
-
Default output is an HTML fragment; `--full` emits a complete document.
|
|
28
|
-
|
|
29
|
-
## npm package
|
|
30
|
-
|
|
31
|
-
The alpha npm package exposes the parser's indexed AST without imposing a
|
|
32
|
-
renderer. It is ESM-only and includes TypeScript declarations.
|
|
33
|
-
|
|
34
|
-
npm install mausmark@alpha
|
|
9
|
+
```sh
|
|
10
|
+
npm install mausmark@alpha
|
|
11
|
+
```
|
|
35
12
|
|
|
36
|
-
|
|
13
|
+
## Usage
|
|
37
14
|
|
|
38
15
|
```ts
|
|
39
|
-
import {createParser,
|
|
16
|
+
import {createParser, NodeType} from 'mausmark'
|
|
40
17
|
|
|
41
18
|
const parser = await createParser()
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
function render(index: number): string {
|
|
47
|
-
const children = () => [...doc.children(index)].map(render).join('')
|
|
48
|
-
switch (doc.type(index)) {
|
|
49
|
-
case NodeType.DOC:
|
|
50
|
-
case NodeType.SPAN:
|
|
51
|
-
return children()
|
|
52
|
-
case NodeType.HEADER:
|
|
53
|
-
return `<h${doc.level(index)}>${children()}</h${doc.level(index)}>`
|
|
54
|
-
case NodeType.PARAGRAPH:
|
|
55
|
-
return `<p>${children()}</p>`
|
|
56
|
-
case NodeType.LIST: {
|
|
57
|
-
const tag = doc.flags(index) & ListFlags.ORDERED ? 'ol' : 'ul'
|
|
58
|
-
return `<${tag}>${children()}</${tag}>`
|
|
59
|
-
}
|
|
60
|
-
case NodeType.LIST_ITEM:
|
|
61
|
-
return `<li>${children()}</li>`
|
|
19
|
+
const document = parser.parse('# Hello\n\nThis is **Mausmark**.')
|
|
20
|
+
|
|
21
|
+
function visit(index: number): unknown {
|
|
22
|
+
switch (document.type(index)) {
|
|
62
23
|
case NodeType.TEXT:
|
|
63
|
-
return
|
|
24
|
+
return document.text(index)
|
|
64
25
|
default:
|
|
65
|
-
return children()
|
|
26
|
+
return [...document.children(index)].map(visit)
|
|
66
27
|
}
|
|
67
28
|
}
|
|
68
29
|
|
|
69
|
-
const
|
|
30
|
+
const result = visit(0)
|
|
70
31
|
```
|
|
71
32
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
- Inputs are limited to 4 GB (offsets are 32-bit by design).
|
|
112
|
-
- The HTML renderer allocates its scratch into the parse arena, so parse
|
|
113
|
-
and render currently share one arena’s lifetime and budget.
|
|
114
|
-
- No tables yet.
|
|
115
|
-
|
|
116
|
-
TODO:
|
|
117
|
-
|
|
118
|
-
- A link url/title/label that spans a soft-wrap seam renders empty, so a
|
|
119
|
-
multi-line reference definition fails its lookup. Now that these are child
|
|
120
|
-
nodes they could carry the value as several chunks, the way link text
|
|
121
|
-
already does.
|
|
122
|
-
|
|
123
|
-
## Embedding
|
|
124
|
-
|
|
125
|
-
The API is not settled yet; embedding docs will come once it is. For now the
|
|
126
|
-
public surface is `src/parser.h`, and the consumer roots (`src/mausmark.c`,
|
|
127
|
-
`src/wasm.c`, `test/test.c`) show the include layout.
|
|
128
|
-
|
|
129
|
-
## Building
|
|
130
|
-
|
|
131
|
-
`build.sh` is the whole build system. Each target is one `gcc`/`clang`
|
|
132
|
-
invocation; there is no library to install.
|
|
133
|
-
|
|
134
|
-
./build.sh test # build + run the test harness
|
|
135
|
-
./build.sh spec # CommonMark conformance (gated; needs node)
|
|
136
|
-
./build.sh bench [input-file] # build + run the benchmark (default: mobydick.md)
|
|
137
|
-
./build.sh cli # build ./mausmark
|
|
138
|
-
./build.sh wasm # build web/mausmark.wasm (browser demo in web/)
|
|
139
|
-
./build.sh wasm-core # build dist/mausmark.wasm (AST-only npm artifact)
|
|
140
|
-
./build.sh wasm-check # SIMD vs scalar wasm + JS-DOM equivalence
|
|
141
|
-
npm test # build and test the npm package + its types
|
|
142
|
-
|
|
143
|
-
On macOS, the wasm targets use Homebrew `llvm` + `lld` (Apple clang ships no
|
|
144
|
-
wasm backend). Elsewhere they use `clang` + `wasm-ld`; override with `WASM_CC`
|
|
145
|
-
/ `WASM_LD_DIR`.
|
|
146
|
-
|
|
147
|
-
Strict mode (lint + Address/UB sanitizers, warnings as errors):
|
|
148
|
-
|
|
149
|
-
CC=clang SANITIZE=1 WERROR=1 ./build.sh test
|
|
150
|
-
|
|
151
|
-
## Performance
|
|
152
|
-
|
|
153
|
-
Measured on an M3 Pro over cache-resident inputs (`./build.sh bench <file>`
|
|
154
|
-
reproduces; sanitizer-free build, median of 5).
|
|
155
|
-
|
|
156
|
-
| Input | to AST | to HTML | vs memcpy |
|
|
157
|
-
|------------------------------------------------------|---------:|--------------------:|----------:|
|
|
158
|
-
| `mobydick.md` (1.2 MB, prose ~183 B/line) | 5.2 GB/s | 3.5 GB/s (~0.33 ms) | ~22× |
|
|
159
|
-
| `mobydick-hard.md` (1.2 MB, wrapped ~62 B/line) | 4.2 GB/s | 2.6 GB/s (~0.44 ms) | ~30× |
|
|
160
|
-
| 10 real articles, mean 6.8 KB (link/ref-heavy) | 2.3 GB/s | 1.6 GB/s (~4.2 µs) | ~51× |
|
|
161
|
-
|
|
162
|
-
Sizing the arena: the document is 16 B per node — 130 KB for Moby-Dick's 8346
|
|
163
|
-
nodes, ~0.1× the input. Total arena use after parse and render is ~0.8× the input
|
|
164
|
-
for a book and ~1.3× for a small article.
|
|
165
|
-
|
|
166
|
-
The wasm build runs at ~0.55–0.65× native speed, on every input tested.
|
|
167
|
-
|
|
168
|
-
## Status
|
|
169
|
-
|
|
170
|
-
Alpha: actively developed, API not yet stable. Correctness is exercised
|
|
171
|
-
by a fixture test suite (`./build.sh test`), also run under Address/UB
|
|
172
|
-
sanitizers (see strict mode above).
|
|
173
|
-
Project page with a live browser demo: https://myshkin.eu/mausmark
|
|
33
|
+
Initialize the parser once and reuse it. Initialization is asynchronous;
|
|
34
|
+
`parse()` is synchronous. Returned documents are independent snapshots and
|
|
35
|
+
remain valid after later parses.
|
|
36
|
+
|
|
37
|
+
## AST
|
|
38
|
+
|
|
39
|
+
The root is node `0`. Nodes use integer indexes into a compact preorder table.
|
|
40
|
+
TypeScript declarations and runtime constants are included.
|
|
41
|
+
|
|
42
|
+
- `type(index)` returns a `NodeType`.
|
|
43
|
+
- `children(index)` iterates direct content children.
|
|
44
|
+
- `text(index)` decodes one node's source slice.
|
|
45
|
+
- `joinedText(index)` joins chunked code or image content.
|
|
46
|
+
- `link(index)` returns raw URL, title, label, and `ReferenceStyle`.
|
|
47
|
+
- `level(index)` carries heading levels and other type-specific values.
|
|
48
|
+
- `flags(index)` carries `ListFlags.ORDERED` and `ListFlags.LOOSE`.
|
|
49
|
+
- `offset(index)` and `length(index)` are UTF-8 byte offsets.
|
|
50
|
+
- `subtreeEnd(index)` supports lower-level preorder traversal.
|
|
51
|
+
|
|
52
|
+
`children()` hides internal URL, title, and label nodes. Reference links remain
|
|
53
|
+
unresolved so renderers can choose their own lookup and URL policies. Raw HTML
|
|
54
|
+
is returned as `NodeType.HTML`; sanitize it when parsing untrusted input.
|
|
55
|
+
|
|
56
|
+
## Notes
|
|
57
|
+
|
|
58
|
+
- ESM-only.
|
|
59
|
+
- Node.js 22.14+ or a modern browser with WebAssembly SIMD.
|
|
60
|
+
- Browser bundlers must emit the package-relative `.wasm` asset.
|
|
61
|
+
- Input is limited to 64 MiB; parser arena growth is limited to 512 MiB.
|
|
62
|
+
- Broadly CommonMark-compatible, but not fully conformant.
|
|
63
|
+
- Backtick fences only; no `~~~` fences or tables yet.
|
|
64
|
+
- Fence info strings are currently ignored.
|
|
65
|
+
|
|
66
|
+
The npm package contains ESM bindings, TypeScript declarations, and precompiled
|
|
67
|
+
WebAssembly. The implementation source is currently private; the distributed
|
|
68
|
+
package is licensed under MIT.
|
|
69
|
+
|
|
70
|
+
Project page and demo: https://myshkin.eu/mausmark
|
|
174
71
|
|
|
175
72
|
## License
|
|
176
73
|
|
package/dist/mausmark.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mausmark",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "A fast, dependency-free Markdown parser compiled to WebAssembly",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -35,12 +35,9 @@
|
|
|
35
35
|
"markdown",
|
|
36
36
|
"parser",
|
|
37
37
|
"wasm",
|
|
38
|
-
"webassembly"
|
|
38
|
+
"webassembly",
|
|
39
|
+
"ast"
|
|
39
40
|
],
|
|
40
|
-
"repository": {
|
|
41
|
-
"type": "git",
|
|
42
|
-
"url": "git+https://github.com/mauskin/mausmark.git"
|
|
43
|
-
},
|
|
44
41
|
"homepage": "https://myshkin.eu/mausmark",
|
|
45
42
|
"license": "MIT",
|
|
46
43
|
"sideEffects": false,
|