1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright © 2023 - 2026 HTML Generator. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! 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. Uses
//! [`crate::HtmlConfig::default`] under 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 of [`crate::HtmlConfig`] flags 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
//!
//! ```ignore
//! // 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:
//!
//! ```text
//! cargo build --release --target wasm32-unknown-unknown --features wasm
//! ```
//!
//! Or with `wasm-pack` for an npm-publishable bundle:
//!
//! ```text
//! wasm-pack build --target web --features wasm
//! ```
use *;
use crate::;
/// Render Markdown to an accessible HTML fragment.
///
/// This is the simplest WASM entry point — no configuration, the
/// pipeline runs with [`HtmlConfig::default`] (ARIA on, TOC off,
/// JSON-LD off, no full-document wrap).
///
/// # Errors
///
/// Returns a `JsValue` carrying the [`crate::error::HtmlError`]
/// display string when the underlying Markdown render fails.
/// `wasm-bindgen` materialises this on the JS side as a thrown
/// JavaScript `Error`.
/// Render Markdown wrapped in a full HTML5 document skeleton.
///
/// Convenience wrapper that flips `generate_full_document` on
/// before delegating to [`generate_html`]. The output starts with
/// `<!DOCTYPE html>` and is suitable for direct write-out from a
/// Worker / Edge function.
///
/// # Errors
///
/// Same as [`generate_html_wasm`].
/// Render Markdown with a JSON-encoded subset of [`HtmlConfig`].
///
/// The JSON object accepts these keys (all optional, all booleans
/// or strings, defaults match [`HtmlConfig::default`]):
///
/// * `add_aria_attributes` *(bool)* — inject ARIA labels and roles.
/// * `generate_toc` *(bool)* — replace the `[[TOC]]` placeholder
/// with a generated table of contents.
/// * `generate_structured_data` *(bool)* — emit a `<script
/// type="application/ld+json">` JSON-LD block.
/// * `generate_full_document` *(bool)* — wrap output in
/// `<!DOCTYPE html>`.
/// * `enable_math` *(bool)* — render `$..$` and `$$..$$` to MathML
/// (requires the `math` feature, on by default).
/// * `enable_diagrams` *(bool)* — rewrite mermaid fenced blocks for
/// client-side mermaid.js.
/// * `language` *(string)* — BCP 47 language code for the `<html>`
/// `lang` attribute when full-document mode is on.
/// * `minify_output` *(bool)* — minify the final HTML.
///
/// File-I/O fields (`encoding`, `max_buffer_size`) are accepted for
/// shape compatibility but ignored: WASM has no host filesystem.
///
/// # Errors
///
/// Returns a `JsValue` carrying:
///
/// * `"invalid options JSON: …"` if `options_json` does not parse
/// as a JSON object.
/// * The [`crate::error::HtmlError`] display string when the
/// underlying render fails.