Skip to main content

Module wasm

Module wasm 

Source
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:

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 wasm

Or with wasm-pack for an npm-publishable bundle:

wasm-pack build --target web --features wasm

Functions§

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.