ironmark 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Philip Stapelfeldt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # ironmark
2
+
3
+ Fast Markdown-to-HTML parser written in Rust. Fully compliant with [CommonMark 0.31.2](https://spec.commonmark.org/0.31.2/) (652/652 spec tests pass). Available as a Rust crate and as an npm package via WebAssembly.
4
+
5
+ ## Features
6
+
7
+ - Zero third-party parsing dependencies
8
+ - Headings (`#` through `######`) and setext headings
9
+ - Paragraphs, emphasis, strong emphasis, inline code
10
+ - ~~strikethrough~~, ==highlight==, ++underline++
11
+ - Links, reference links, autolinks (angle-bracket and bare URL/email), images
12
+ - Ordered and unordered lists with nesting, task lists (checkboxes)
13
+ - Blockquotes, horizontal rules
14
+ - Fenced and indented code blocks
15
+ - Tables with alignment
16
+ - Raw HTML passthrough
17
+ - Backslash escapes and HTML entities
18
+
19
+ ## JavaScript / TypeScript
20
+
21
+ ### Install
22
+
23
+ ```bash
24
+ npm install ironmark
25
+ ```
26
+
27
+ ### Usage
28
+
29
+ ```ts
30
+ import { parse } from "ironmark";
31
+
32
+ const html = parse("# Hello\n\nThis is **fast**.");
33
+
34
+ const bytes = new TextEncoder().encode("# Hello from bytes");
35
+ const html2 = parse(bytes);
36
+ ```
37
+
38
+ ### Options
39
+
40
+ ```ts
41
+ import { parse } from "ironmark";
42
+
43
+ const html = parse("line one\nline two", {
44
+ hardBreaks: false, // every newline becomes <br /> (default: true)
45
+ enableHighlight: true, // ==highlight== → <mark> (default: true)
46
+ enableStrikethrough: true, // ~~strike~~ → <del> (default: true)
47
+ enableUnderline: true, // ++underline++ → <u> (default: true)
48
+ enableTables: true, // pipe tables (default: true)
49
+ enableAutolink: true, // bare URLs & emails → <a> (default: true)
50
+ enableTaskLists: true, // - [ ] / - [x] checkboxes (default: true)
51
+ });
52
+ ```
53
+
54
+ ### Build from source
55
+
56
+ ```bash
57
+ npm run setup:wasm
58
+ npm run build
59
+ ```
60
+
61
+ | Command | Description |
62
+ | -------------------- | ---------------------- |
63
+ | `npm run setup:wasm` | Install prerequisites |
64
+ | `npm run build` | Release WASM build |
65
+ | `npm run build:dev` | Debug WASM build |
66
+ | `npm run test` | Run Rust tests |
67
+ | `npm run check` | Format check + tests |
68
+ | `npm run clean` | Remove build artifacts |
69
+
70
+ ## Rust
71
+
72
+ ### Add to your project
73
+
74
+ ```bash
75
+ cargo add ironmark
76
+ ```
77
+
78
+ ### Usage
79
+
80
+ ```rust
81
+ use ironmark::{parse, ParseOptions};
82
+
83
+ fn main() {
84
+ let html = parse("# Hello\n\nThis is **fast**.", &ParseOptions::default());
85
+ println!("{html}");
86
+ }
87
+ ```
88
+
89
+ ### With options
90
+
91
+ ```rust
92
+ use ironmark::{parse, ParseOptions};
93
+
94
+ fn main() {
95
+ let options = ParseOptions {
96
+ hard_breaks: true,
97
+ enable_strikethrough: false, // disable ~~strikethrough~~
98
+ enable_autolink: true, // bare URLs & emails → <a>
99
+ enable_task_lists: true, // - [ ] / - [x] checkboxes
100
+ ..Default::default()
101
+ };
102
+
103
+ let html = parse("line one\nline two", &options);
104
+ println!("{html}");
105
+ }
106
+ ```
107
+
108
+ ## Benchmarks
109
+
110
+ ```bash
111
+ cd benchmark
112
+ npm install
113
+ node bench.mjs
114
+ ```
115
+
116
+ ## Troubleshooting
117
+
118
+ ### `wasm32-unknown-unknown target not found` with Homebrew Rust
119
+
120
+ The build scripts prepend `$HOME/.cargo/bin` to `PATH` so that rustup-managed binaries take priority. If the error persists:
121
+
122
+ ```bash
123
+ npm run setup:wasm
124
+ ```
125
+
126
+ ### `wasm-bindgen` not found
127
+
128
+ ```bash
129
+ npm run setup:wasm
130
+ ```
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "ironmark",
3
+ "version": "0.1.0",
4
+ "description": "Very fast markdown parser in Rust, consumable from JavaScript/TypeScript via WebAssembly",
5
+ "keywords": [
6
+ "markdown",
7
+ "parser",
8
+ "rust",
9
+ "wasm"
10
+ ],
11
+ "homepage": "https://github.com/ph1p/ironmark",
12
+ "bugs": {
13
+ "url": "https://github.com/ph1p/ironmark/issues"
14
+ },
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/ph1p/ironmark.git"
19
+ },
20
+ "files": [
21
+ "wasm/pkg",
22
+ "wasm/index.js",
23
+ "wasm/index.d.ts",
24
+ "README.md"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "main": "wasm/index.js",
29
+ "types": "wasm/index.d.ts",
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "registry": "https://registry.npmjs.org/"
33
+ },
34
+ "devDependencies": {
35
+ "@semantic-release/commit-analyzer": "^13.0.1",
36
+ "@semantic-release/exec": "^7.1.0",
37
+ "@semantic-release/git": "^10.0.1",
38
+ "@semantic-release/github": "^12.0.6",
39
+ "@semantic-release/npm": "^13.1.4",
40
+ "@semantic-release/release-notes-generator": "^14.1.0",
41
+ "oxfmt": "^0.35.0",
42
+ "oxlint": "^1.50.0",
43
+ "semantic-release": "^25.0.3"
44
+ },
45
+ "engines": {
46
+ "node": ">=18"
47
+ },
48
+ "prepack": "npm run build",
49
+ "scripts": {
50
+ "build": "npm run build:wasm",
51
+ "build:dev": "PATH=\"$PWD/.wasm-tools/bin:$HOME/.cargo/bin:$PATH\" cargo build -p ironmark-wasm --target wasm32-unknown-unknown && PATH=\"$PWD/.wasm-tools/bin:$HOME/.cargo/bin:$PATH\" wasm-bindgen --target bundler --out-dir wasm/pkg --out-name ironmark target/wasm32-unknown-unknown/debug/ironmark.wasm",
52
+ "build:wasm": "PATH=\"$PWD/.wasm-tools/bin:$HOME/.cargo/bin:$PATH\" cargo build -p ironmark-wasm --release --target wasm32-unknown-unknown && PATH=\"$PWD/.wasm-tools/bin:$HOME/.cargo/bin:$PATH\" wasm-bindgen --target bundler --out-dir wasm/pkg --out-name ironmark target/wasm32-unknown-unknown/release/ironmark.wasm && wasm-opt --enable-bulk-memory -O3 wasm/pkg/ironmark_bg.wasm -o wasm/pkg/ironmark_bg.wasm",
53
+ "check": "cargo fmt --check && cargo test --offline && oxlint && oxfmt --check .",
54
+ "clean": "rm -rf wasm/pkg .wasm-tools",
55
+ "fmt": "cargo fmt && oxfmt --write .",
56
+ "lint": "oxlint",
57
+ "release": "semantic-release",
58
+ "release:dry": "semantic-release --dry-run",
59
+ "setup:wasm": "PATH=\"$HOME/.cargo/bin:$PATH\" rustup target add wasm32-unknown-unknown && TMPDIR=/tmp PATH=\"$HOME/.cargo/bin:$PATH\" cargo install wasm-bindgen-cli --locked --root .wasm-tools",
60
+ "test": "cargo test --offline"
61
+ }
62
+ }
@@ -0,0 +1,27 @@
1
+ export type MarkdownInput = string | Uint8Array | ArrayBuffer | ArrayBufferView;
2
+
3
+ export interface ParseOptions {
4
+ /** When true, every newline in a paragraph becomes a hard line break (`<br />`). Default: true. */
5
+ hardBreaks?: boolean;
6
+ /** Enable ==highlight== syntax for `<mark>`. Default: true. */
7
+ enableHighlight?: boolean;
8
+ /** Enable ~~strikethrough~~ syntax for `<del>`. Default: true. */
9
+ enableStrikethrough?: boolean;
10
+ /** Enable ++underline++ syntax for `<u>`. Default: true. */
11
+ enableUnderline?: boolean;
12
+ /** Enable pipe table syntax. Default: true. */
13
+ enableTables?: boolean;
14
+ /** Automatically detect bare URLs and emails and wrap them in links. Default: true. */
15
+ enableAutolink?: boolean;
16
+ /** Enable GitHub-style task lists (`- [ ] unchecked`, `- [x] checked`). Default: true. */
17
+ enableTaskLists?: boolean;
18
+ }
19
+
20
+ /**
21
+ * Parse Markdown to HTML.
22
+ *
23
+ * @param markdown - Markdown source (string or binary).
24
+ * @param options - Optional parsing options.
25
+ * @returns HTML string.
26
+ */
27
+ export declare function parse(markdown: MarkdownInput, options?: ParseOptions): string;
package/wasm/index.js ADDED
@@ -0,0 +1,27 @@
1
+ import { parse as wasmParse } from "./pkg/ironmark.js";
2
+
3
+ const decoder = new TextDecoder("utf-8");
4
+
5
+ function toStr(markdown) {
6
+ if (typeof markdown === "string") return markdown;
7
+ if (markdown instanceof Uint8Array) return decoder.decode(markdown);
8
+ if (markdown instanceof ArrayBuffer) return decoder.decode(new Uint8Array(markdown));
9
+ if (ArrayBuffer.isView(markdown))
10
+ return decoder.decode(
11
+ new Uint8Array(markdown.buffer, markdown.byteOffset, markdown.byteLength),
12
+ );
13
+ throw new TypeError("markdown must be a string, Uint8Array, ArrayBuffer, or Buffer");
14
+ }
15
+
16
+ export function parse(markdown, options) {
17
+ return wasmParse(
18
+ toStr(markdown),
19
+ options?.hardBreaks ?? undefined,
20
+ options?.enableHighlight ?? undefined,
21
+ options?.enableStrikethrough ?? undefined,
22
+ options?.enableUnderline ?? undefined,
23
+ options?.enableTables ?? undefined,
24
+ options?.enableAutolink ?? undefined,
25
+ options?.enableTaskLists ?? undefined,
26
+ );
27
+ }
@@ -0,0 +1,4 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function parse(markdown: string, hard_breaks?: boolean | null, enable_highlight?: boolean | null, enable_strikethrough?: boolean | null, enable_underline?: boolean | null, enable_tables?: boolean | null, enable_autolink?: boolean | null, enable_task_lists?: boolean | null): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./ironmark.d.ts" */
2
+
3
+ import * as wasm from "./ironmark_bg.wasm";
4
+ import { __wbg_set_wasm } from "./ironmark_bg.js";
5
+ __wbg_set_wasm(wasm);
6
+
7
+ export {
8
+ parse
9
+ } from "./ironmark_bg.js";
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @param {string} markdown
3
+ * @param {boolean | null} [hard_breaks]
4
+ * @param {boolean | null} [enable_highlight]
5
+ * @param {boolean | null} [enable_strikethrough]
6
+ * @param {boolean | null} [enable_underline]
7
+ * @param {boolean | null} [enable_tables]
8
+ * @param {boolean | null} [enable_autolink]
9
+ * @param {boolean | null} [enable_task_lists]
10
+ * @returns {string}
11
+ */
12
+ export function parse(markdown, hard_breaks, enable_highlight, enable_strikethrough, enable_underline, enable_tables, enable_autolink, enable_task_lists) {
13
+ let deferred2_0;
14
+ let deferred2_1;
15
+ try {
16
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
17
+ const ptr0 = passStringToWasm0(markdown, wasm.__wbindgen_export, wasm.__wbindgen_export2);
18
+ const len0 = WASM_VECTOR_LEN;
19
+ wasm.parse(retptr, ptr0, len0, isLikeNone(hard_breaks) ? 0xFFFFFF : hard_breaks ? 1 : 0, isLikeNone(enable_highlight) ? 0xFFFFFF : enable_highlight ? 1 : 0, isLikeNone(enable_strikethrough) ? 0xFFFFFF : enable_strikethrough ? 1 : 0, isLikeNone(enable_underline) ? 0xFFFFFF : enable_underline ? 1 : 0, isLikeNone(enable_tables) ? 0xFFFFFF : enable_tables ? 1 : 0, isLikeNone(enable_autolink) ? 0xFFFFFF : enable_autolink ? 1 : 0, isLikeNone(enable_task_lists) ? 0xFFFFFF : enable_task_lists ? 1 : 0);
20
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
21
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
22
+ deferred2_0 = r0;
23
+ deferred2_1 = r1;
24
+ return getStringFromWasm0(r0, r1);
25
+ } finally {
26
+ wasm.__wbindgen_add_to_stack_pointer(16);
27
+ wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
28
+ }
29
+ }
30
+ let cachedDataViewMemory0 = null;
31
+ function getDataViewMemory0() {
32
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
33
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
34
+ }
35
+ return cachedDataViewMemory0;
36
+ }
37
+
38
+ function getStringFromWasm0(ptr, len) {
39
+ ptr = ptr >>> 0;
40
+ return decodeText(ptr, len);
41
+ }
42
+
43
+ let cachedUint8ArrayMemory0 = null;
44
+ function getUint8ArrayMemory0() {
45
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
46
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
47
+ }
48
+ return cachedUint8ArrayMemory0;
49
+ }
50
+
51
+ function isLikeNone(x) {
52
+ return x === undefined || x === null;
53
+ }
54
+
55
+ function passStringToWasm0(arg, malloc, realloc) {
56
+ if (realloc === undefined) {
57
+ const buf = cachedTextEncoder.encode(arg);
58
+ const ptr = malloc(buf.length, 1) >>> 0;
59
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
60
+ WASM_VECTOR_LEN = buf.length;
61
+ return ptr;
62
+ }
63
+
64
+ let len = arg.length;
65
+ let ptr = malloc(len, 1) >>> 0;
66
+
67
+ const mem = getUint8ArrayMemory0();
68
+
69
+ let offset = 0;
70
+
71
+ for (; offset < len; offset++) {
72
+ const code = arg.charCodeAt(offset);
73
+ if (code > 0x7F) break;
74
+ mem[ptr + offset] = code;
75
+ }
76
+ if (offset !== len) {
77
+ if (offset !== 0) {
78
+ arg = arg.slice(offset);
79
+ }
80
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
81
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
82
+ const ret = cachedTextEncoder.encodeInto(arg, view);
83
+
84
+ offset += ret.written;
85
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
86
+ }
87
+
88
+ WASM_VECTOR_LEN = offset;
89
+ return ptr;
90
+ }
91
+
92
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
93
+ cachedTextDecoder.decode();
94
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
95
+ let numBytesDecoded = 0;
96
+ function decodeText(ptr, len) {
97
+ numBytesDecoded += len;
98
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
99
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
100
+ cachedTextDecoder.decode();
101
+ numBytesDecoded = len;
102
+ }
103
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
104
+ }
105
+
106
+ const cachedTextEncoder = new TextEncoder();
107
+
108
+ if (!('encodeInto' in cachedTextEncoder)) {
109
+ cachedTextEncoder.encodeInto = function (arg, view) {
110
+ const buf = cachedTextEncoder.encode(arg);
111
+ view.set(buf);
112
+ return {
113
+ read: arg.length,
114
+ written: buf.length
115
+ };
116
+ };
117
+ }
118
+
119
+ let WASM_VECTOR_LEN = 0;
120
+
121
+
122
+ let wasm;
123
+ export function __wbg_set_wasm(val) {
124
+ wasm = val;
125
+ }
Binary file
@@ -0,0 +1,8 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const parse: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
5
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
6
+ export const __wbindgen_export: (a: number, b: number) => number;
7
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
8
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;