| Crates.io | quillmark-wasm |
| lib.rs | quillmark-wasm |
| version | 0.1.18 |
| created_at | 2025-10-05 00:43:30.145233+00 |
| updated_at | 2025-10-11 03:52:03.2488+00 |
| description | WebAssembly bindings for quillmark |
| homepage | |
| repository | https://github.com/nibsbin/quillmark |
| max_upload_size | |
| id | 1868491 |
| size | 32,228,555 |
WebAssembly bindings for the Quillmark markdown rendering engine.
This crate provides minimal WASM bindings for Quillmark, enabling use in web browsers, Node.js, and other JavaScript/TypeScript environments. All data exchange uses JSON serialization, and JavaScript is responsible for all I/O operations (fetching, reading files, unzipping archives).
This package is published to npm as @quillmark-test/wasm.
wasm-pack build --target bundler --scope quillmark
wasm-pack build --target nodejs --scope quillmark
bash scripts/build-wasm.sh
This will create a pkg/bundler/ directory with the compiled WASM module for the bundler target.
npm install @quillmark-test/wasm
This WASM package follows the canonical Quill JSON contract defined in
designs/QUILL_DESIGN.md. Build a JS object shaped as the file tree or pass
a JSON string describing the Quill when creating Quill instances.
Minimal example:
import { Quillmark } from '@quillmark-test/wasm';
// Create engine
const engine = new Quillmark();
// Prepare a Quill in memory
const quillObj = {
files: {
'Quill.toml': { contents: '[Quill]\nname = "my-quill"\nbackend = "typst"\nglue = "glue.typ"\n' },
'glue.typ': { contents: '= Hello\n\n{{ body }}' }
}
};
// Register Quill
engine.registerQuill('my-quill', quillObj);
// Render markdown with QUILL frontmatter field
const markdown = `---
QUILL: my-quill
---
# Hi`;
const result = engine.render(markdown, { format: 'pdf' });
// Access the PDF bytes
const pdfArtifact = result.artifacts.find(a => a.format === 'pdf');
if (pdfArtifact) {
const blob = new Blob([pdfArtifact.bytes], { type: pdfArtifact.mimeType });
const url = URL.createObjectURL(blob);
window.open(url);
}
The WASM API provides a single main class:
Quillmark - Main engine for managing Quills and rendering markdownSee designs/WASM_DESIGN.md in the repository for the complete API specification.
serde-wasm-bindgenfromPath(), fromUrl(), or fromZip() methods - JavaScript prepares all dataAll data crossing the JavaScript <-> WebAssembly boundary uses JSON/serde-compatible serialization via serde-wasm-bindgen.
This means a few concrete rules you should follow when calling into the WASM module from JS/TS:
Enums: exported Rust enums are serialized as strings (not numeric discriminants). This was a compatibility fix in the recent WASM changes — pass enum values as their string names (for example "PDF") or use the generated JS enum helpers (e.g. OutputFormat.PDF). Avoid using raw numeric indices for enums.
Bytes / binary data: Vec<u8> and similar binary buffers map to Uint8Array across the WASM boundary.
Quill.fromJson() you must represent binary file contents as an array of numeric byte values (e.g. [137,80,78,71,...]). The quillmark-core JSON parser accepts either a UTF-8 string or a numeric array in the contents field.Workflow.withAsset()), pass a Uint8Array in the JS call (or Buffer in Node) — you do NOT JSON.stringify these runtime binary arguments.Collections: Vec<T> <-> JS arrays, and HashMap<String, T> / BTreeMap<String, T> map to plain JS objects or Map where appropriate. You can pass a Map<string, Uint8Array> for file maps, or a plain object whose values are Uint8Array.
Option and nullability: Option<T> is represented as either the value or null in JS. Use null to indicate None.
Errors / Result: Rust Result errors are surfaced to JS as thrown exceptions containing a serialized QuillmarkError object (see "Error Handling" above). Inspect error.diagnostics for rich diagnostic information.
Core API is implemented:
Quillmark - Engine management with new Quillmark() constructorregisterQuill() - Register Quills from JSON objects or stringsrender() - Synchronous rendering to PDF/SVG/TXTRenderOptions.assetsrenderGlue() - Debug template source generationlistQuills() and unregisterQuill() - Memory managementNot implemented (by design):
Licensed under the Apache License, Version 2.0.