Expand description
WebAssembly bindings.
Compiled in only when the crate is built with --features wasm
and a wasm32-* target. Exposes a small JS-friendly surface so
the same Markdown-to-accessible-HTML pipeline that runs server-
side can render directly inside Cloudflare Workers, Vercel Edge,
browser previews, and Node-via-WASI without extra plumbing.
Three functions are exported:
generate_html_wasm— the simplest entry point. Takes a Markdown string, returns the HTML fragment. Usescrate::HtmlConfig::defaultunder the hood (ARIA on, TOC off, JSON-LD off, no full-document wrap, no minify).generate_html_full_document_wasm— wraps the output in a complete HTML5 document.generate_html_with_options_wasm— accepts a JSON string describing the subset ofcrate::HtmlConfigflags that make sense in a browser/edge runtime (no file I/O, no async).
Errors are surfaced as JS exceptions: the bindings return
Result<String, JsValue> and wasm-bindgen materialises the
Err(JsValue) as a thrown JS Error on the JS side.
§Examples
ⓘ
// doctest is `ignore`d because it only compiles when the `wasm`
// feature is on and the target is `wasm32`. The `cargo test`
// target runs on native; the WASM smoke test lives in
// `tests/wasm_smoke.rs` and is driven by `wasm-bindgen-test`.
use wasm_bindgen::prelude::*;
use html_generator::wasm::generate_html_wasm;
let html: Result<String, JsValue> = generate_html_wasm("# Hi");
assert!(html.unwrap().contains("<h1>"));Build for the browser:
cargo build --release --target wasm32-unknown-unknown --features wasmOr with wasm-pack for an npm-publishable bundle:
wasm-pack build --target web --features wasmFunctions§
- generate_
html_ full_ document_ wasm - Render Markdown wrapped in a full HTML5 document skeleton.
- generate_
html_ wasm - Render Markdown to an accessible HTML fragment.
- generate_
html_ with_ options_ wasm - Render Markdown with a JSON-encoded subset of
HtmlConfig.