@kreuzberg/html-to-markdown-wasm 2.19.0-rc.1

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/dist/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # html-to-markdown
2
+
3
+ <img width="1128" height="191" alt="Linkedin- Banner (1)" src="https://github.com/user-attachments/assets/f8e91036-20a5-40f9-9fcc-9e6c6e15f1f5" />
4
+
5
+
6
+
7
+ High-performance HTML → Markdown conversion powered by Rust. Shipping as a Rust crate, Python package, PHP extension, Ruby gem, Elixir Rustler NIF, Node.js bindings, WebAssembly, and standalone CLI with identical rendering behaviour.
8
+
9
+ Part of the Kreuzberg.dev document intelligence ecosystem. Kreuzberg is a polyglot document intelligence framework with a fast Rust core. We build tools that help developers extract, process, and understand documents at scale, from PDFs to Office files, images, archives, emails, in 50+ formats. We've set out to make high-performance document intelligence faster and more ecological.
10
+
11
+ [![Crates.io](https://img.shields.io/crates/v/html-to-markdown-rs.svg?logo=rust&label=crates.io)](https://crates.io/crates/html-to-markdown-rs)
12
+ [![npm (node)](https://img.shields.io/npm/v/%40kreuzberg%2Fhtml-to-markdown-node.svg?logo=npm)](https://www.npmjs.com/package/@kreuzberg/html-to-markdown-node)
13
+ [![npm (wasm)](https://img.shields.io/npm/v/%40kreuzberg%2Fhtml-to-markdown-wasm.svg?logo=npm)](https://www.npmjs.com/package/@kreuzberg/html-to-markdown-wasm)
14
+ [![PyPI](https://img.shields.io/pypi/v/html-to-markdown.svg?logo=pypi)](https://pypi.org/project/html-to-markdown/)
15
+ [![Packagist](https://img.shields.io/packagist/v/goldziher/html-to-markdown.svg)](https://packagist.org/packages/goldziher/html-to-markdown)
16
+ [![RubyGems](https://badge.fury.io/rb/html-to-markdown.svg)](https://rubygems.org/gems/html-to-markdown)
17
+ [![Hex.pm](https://img.shields.io/hexpm/v/html_to_markdown.svg)](https://hex.pm/packages/html_to_markdown)
18
+ [![NuGet](https://img.shields.io/nuget/v/KreuzbergDev.HtmlToMarkdown.svg)](https://www.nuget.org/packages/KreuzbergDev.HtmlToMarkdown/)
19
+ [![Maven Central](https://img.shields.io/maven-central/v/dev.kreuzberg/html-to-markdown.svg)](https://central.sonatype.com/artifact/dev.kreuzberg/html-to-markdown)
20
+ [![Go Reference](https://pkg.go.dev/badge/github.com/kreuzberg-dev/html-to-markdown/packages/go/v2/htmltomarkdown.svg)](https://pkg.go.dev/github.com/kreuzberg-dev/html-to-markdown/packages/go/v2/htmltomarkdown)
21
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/kreuzberg-dev/html-to-markdown/blob/main/LICENSE)
22
+ [![Discord](https://img.shields.io/badge/Discord-Join%20our%20community-7289da)](https://discord.gg/pXxagNK2zN)
23
+
24
+
25
+ ---
26
+
27
+ ## 🎮 **[Try the Live Demo →](https://kreuzberg-dev.github.io/html-to-markdown/)**
28
+
29
+ Experience WebAssembly-powered HTML to Markdown conversion instantly in your browser. No installation needed!
30
+
31
+ ---
32
+
33
+ ## Why html-to-markdown?
34
+
35
+ - **Blazing Fast**: Rust-powered core delivers 10-80× faster conversion than pure Python alternatives
36
+ - **Universal**: Works everywhere - Node.js, Bun, Deno, browsers, Python, Rust, and standalone CLI
37
+ - **Smart Conversion**: Handles complex documents including nested tables, code blocks, task lists, and hOCR OCR output
38
+ - **Metadata Extraction**: Extract document metadata (title, description, headers, links, images) alongside conversion
39
+ - **Highly Configurable**: Control heading styles, code block fences, list formatting, whitespace handling, and HTML sanitization
40
+ - **Tag Preservation**: Keep specific HTML tags unconverted when markdown isn't expressive enough
41
+ - **Secure by Default**: Built-in HTML sanitization prevents malicious content
42
+ - **Consistent Output**: Identical markdown rendering across all language bindings
43
+
44
+ ## Quick Start
45
+
46
+ **Node.js / Bun (Native - Fastest):**
47
+
48
+ ```typescript
49
+ import { convert } from '@kreuzberg/html-to-markdown-node';
50
+
51
+ const html = '<h1>Hello</h1><p>Rust ❤️ Markdown</p>';
52
+ const markdown = convert(html, {
53
+ headingStyle: 'Atx',
54
+ codeBlockStyle: 'Backticks',
55
+ wrap: true,
56
+ preserveTags: ['table'],
57
+ });
58
+ ```
59
+
60
+ **Python:**
61
+
62
+ ```python
63
+ from html_to_markdown import convert
64
+
65
+ html = '<h1>Hello</h1><p>Rust ❤️ Markdown</p>'
66
+ markdown = convert(html, heading_style='Atx', wrap=True)
67
+ ```
68
+
69
+ **Ruby:**
70
+
71
+ ```ruby
72
+ require 'html_to_markdown'
73
+
74
+ html = '<h1>Hello</h1><p>Rust ❤️ Markdown</p>'
75
+ markdown = HtmlToMarkdown.convert(html, heading_style: :atx, wrap: true)
76
+ ```
77
+
78
+ Full language guides: See [Language Guides](#language-guides) below.
79
+
80
+ ## Installation
81
+
82
+ | Target | Command(s) |
83
+ | --------------------------- | ---------------------------------------------------------------------------------------------------------------- |
84
+ | **Node.js/Bun** (native) | `npm install @kreuzberg/html-to-markdown-node` |
85
+ | **WebAssembly** (universal) | `npm install @kreuzberg/html-to-markdown-wasm` |
86
+ | **Deno** | `import { convert } from "npm:@kreuzberg/html-to-markdown-wasm"` |
87
+ | **Python** (bindings + CLI) | `pip install html-to-markdown` |
88
+ | **PHP** (extension + helpers) | `PHP_EXTENSION_DIR=$(php-config --extension-dir) pie install goldziher/html-to-markdown`<br>`composer require goldziher/html-to-markdown` |
89
+ | **Ruby** gem | `bundle add html-to-markdown` or `gem install html-to-markdown` |
90
+ | **Elixir** (Rustler NIF) | `{:html_to_markdown, "~> 2.8"}` |
91
+ | **Rust** crate | `cargo add html-to-markdown-rs` |
92
+ | **Java** (Maven) | `<groupId>dev.kreuzberg</groupId><artifactId>html-to-markdown</artifactId>` |
93
+ | **C#/.NET** (NuGet) | `dotnet add package KreuzbergDev.HtmlToMarkdown` |
94
+ | Rust CLI (crates.io) | `cargo install html-to-markdown-cli` |
95
+ | Homebrew CLI | `brew install html-to-markdown` (core) |
96
+ | Releases | [GitHub Releases](https://github.com/kreuzberg-dev/html-to-markdown/releases) |
97
+
98
+ ## Performance
99
+
100
+ Benchmarked on Apple M4 using the shared fixture harness in `tools/benchmark-harness`.
101
+
102
+ ### Comparative Throughput (Median Across Fixtures)
103
+
104
+ | Runtime | Median ops/sec | Median throughput (MB/s) | Peak memory (MB) | Successes |
105
+ | ------- | -------------- | ------------------------ | ---------------- | --------- |
106
+ | Rust | 1,060.3 | 116.4 | 171.3 | 56/56 |
107
+ | Go | 1,496.3 | 131.1 | 22.9 | 16/16 |
108
+ | Ruby | 2,155.5 | 300.4 | 280.3 | 48/48 |
109
+ | PHP | 2,357.7 | 308.0 | 223.5 | 48/48 |
110
+ | Elixir | 1,564.1 | 269.1 | 384.7 | 48/48 |
111
+ | C# | 1,234.2 | 272.4 | 187.8 | 16/16 |
112
+ | Java | 1,298.7 | 167.1 | 527.2 | 16/16 |
113
+ | WASM | 1,485.8 | 157.6 | 95.3 | 48/48 |
114
+ | Node.js (NAPI) | 2,054.2 | 306.5 | 95.4 | 48/48 |
115
+ | Python (PyO3) | 3,120.3 | 307.5 | 83.5 | 48/48 |
116
+
117
+ Use `task bench:harness` to regenerate throughput numbers. See [Performance Guide](./examples/performance/) for benchmarking strategies and optimization tips.
118
+
119
+ ## Language Guides
120
+
121
+ Complete documentation with examples for each language:
122
+
123
+ - **Python** – [README](./packages/python/README.md) | PyO3 bindings, metadata extraction, inline images
124
+ - **JavaScript/TypeScript** – [Node.js](./crates/html-to-markdown-node/README.md) | [TypeScript](./packages/typescript/README.md) | [WASM](./crates/html-to-markdown-wasm/README.md)
125
+ - **Ruby** – [README](./packages/ruby/README.md) | Magnus bindings, RBS type definitions, Steep checking
126
+ - **PHP** – [Package](./packages/php/README.md) | [Extension (PIE)](./packages/php-ext/README.md) | ext-php-rs extension
127
+ - **Go** – [README](./packages/go/README.md) | FFI bindings with cgo
128
+ - **Java** – [README](./packages/java/README.md) | Panama FFI, Maven/Gradle setup
129
+ - **C#/.NET** – [README](./packages/csharp/README.md) | P/Invoke FFI, NuGet distribution
130
+ - **Elixir** – [README](./packages/elixir/README.md) | Rustler NIF bindings
131
+ - **Rust** – [README](./crates/html-to-markdown/README.md) | Core library, error handling, advanced features
132
+
133
+ ## Feature Guides
134
+
135
+ ### Visitor Pattern
136
+ Customize HTML→Markdown conversion with callbacks for specific elements. Use cases: domain-specific dialects, content filtering, URL rewriting, accessibility validation.
137
+
138
+ **→ [Full Guide with Examples](./examples/visitor-pattern/)** (Python, TypeScript, Ruby)
139
+
140
+ ### Metadata Extraction
141
+ Extract comprehensive metadata during conversion: title, description, headers, links, images, structured data. Use cases: SEO extraction, TOC generation, link validation, accessibility auditing, content migration.
142
+
143
+ **→ [Full Guide with Examples](./examples/metadata-extraction/)** (Python, TypeScript, Ruby)
144
+
145
+ ### Performance & Benchmarking
146
+ Understand performance characteristics, run benchmarks, optimize for your use case. Includes benchmarking tools, memory profiling, streaming strategies, and optimization tips.
147
+
148
+ **→ [Full Guide](./examples/performance/)**
149
+
150
+ ## Examples
151
+
152
+ Explore working code examples in multiple languages:
153
+
154
+ | Example | Path | Languages |
155
+ | ------- | ---- | --------- |
156
+ | **Visitor Pattern** | [examples/visitor-pattern/](./examples/visitor-pattern/) | Python, TypeScript, Ruby |
157
+ | **Metadata Extraction** | [examples/metadata-extraction/](./examples/metadata-extraction/) | Python, TypeScript, Ruby |
158
+ | **Performance** | [examples/performance/](./examples/performance/) | Benchmarks, profiling, optimization |
159
+
160
+ ## Testing
161
+
162
+ Run the test suite locally:
163
+
164
+ ```bash
165
+ # All core test suites (Rust, Python, Ruby, Node, PHP, Go, C#, Elixir, Java)
166
+ task test
167
+
168
+ # Run the Wasmtime-backed WASM integration tests
169
+ task wasm:test:wasmtime
170
+ ```
171
+
172
+ ## Compatibility & Migrations
173
+
174
+ ### v2.19.0 Breaking Changes (Package Namespace Updates)
175
+
176
+ Several language bindings were updated to use new namespaces and package owners:
177
+
178
+ - **npm packages**: Scoped under `@kreuzberg` organization
179
+ - Old: `html-to-markdown-node` → New: `@kreuzberg/html-to-markdown-node`
180
+ - Old: `html-to-markdown-wasm` → New: `@kreuzberg/html-to-markdown-wasm`
181
+ - **Java**: Package namespace changed from `io.github.goldziher` to `dev.kreuzberg`
182
+ - **C#/.NET**: Package changed from `Goldziher.HtmlToMarkdown` to `KreuzbergDev.HtmlToMarkdown`
183
+
184
+ See [MIGRATION.md](./MIGRATION.md) for step-by-step upgrade instructions for each language.
185
+
186
+ ### v1 → v2 Compatibility
187
+
188
+ - V2's Rust core sustains **150–210 MB/s** throughput; V1 averaged **≈ 2.5 MB/s** (60–80× faster).
189
+ - Python compatibility shim available in `html_to_markdown.v1_compat` (deprecated; emits warnings; plan migrations now). See [Python README](./packages/python/README.md#v1-compatibility) for keyword mappings.
190
+ - CLI flag changes and other breaking updates in [CHANGELOG](./CHANGELOG.md#breaking-changes).
191
+
192
+ ## Community
193
+
194
+ - **Discord** – [Join our community](https://discord.gg/pXxagNK2zN)
195
+ - **Ecosystem** – Explore [Kreuzberg](https://kreuzberg.dev) document-processing tools
196
+ - **Contribute** – [CONTRIBUTING.md](./CONTRIBUTING.md)
197
+ - **Sponsor** – [GitHub Sponsors](https://github.com/sponsors/kreuzberg-dev)
198
+ - **Changelog** – [Version history](./CHANGELOG.md)
199
+
200
+ ## License
201
+
202
+ MIT License – see [LICENSE](./LICENSE) for details.
@@ -0,0 +1,200 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class WasmConversionOptionsHandle {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ constructor(options?: WasmConversionOptions | null);
8
+ }
9
+
10
+ export class WasmHtmlExtraction {
11
+ private constructor();
12
+ free(): void;
13
+ [Symbol.dispose](): void;
14
+ readonly inlineImages: WasmInlineImage[];
15
+ readonly markdown: string;
16
+ readonly warnings: WasmInlineImageWarning[];
17
+ }
18
+
19
+ export class WasmInlineImage {
20
+ private constructor();
21
+ free(): void;
22
+ [Symbol.dispose](): void;
23
+ readonly attributes: Record<string, string>;
24
+ readonly dimensions: Uint32Array | undefined;
25
+ readonly description: string | undefined;
26
+ readonly data: Uint8Array;
27
+ readonly format: string;
28
+ readonly source: string;
29
+ readonly filename: string | undefined;
30
+ }
31
+
32
+ export class WasmInlineImageConfig {
33
+ free(): void;
34
+ [Symbol.dispose](): void;
35
+ constructor(max_decoded_size_bytes?: number | null);
36
+ set captureSvg(value: boolean);
37
+ set filenamePrefix(value: string | null | undefined);
38
+ set inferDimensions(value: boolean);
39
+ }
40
+
41
+ export class WasmInlineImageWarning {
42
+ private constructor();
43
+ free(): void;
44
+ [Symbol.dispose](): void;
45
+ readonly index: number;
46
+ readonly message: string;
47
+ }
48
+
49
+ export class WasmMetadataConfig {
50
+ free(): void;
51
+ [Symbol.dispose](): void;
52
+ /**
53
+ * Create a new metadata configuration with defaults
54
+ *
55
+ * All extraction types enabled by default with 1MB structured data limit
56
+ */
57
+ constructor();
58
+ extract_links: boolean;
59
+ extract_images: boolean;
60
+ extract_headers: boolean;
61
+ extract_document: boolean;
62
+ extract_structured_data: boolean;
63
+ max_structured_data_size: number;
64
+ }
65
+
66
+ /**
67
+ * Convert HTML to Markdown
68
+ *
69
+ * # Arguments
70
+ *
71
+ * * `html` - The HTML string to convert
72
+ * * `options` - Optional conversion options (as a JavaScript object)
73
+ *
74
+ * # Example
75
+ *
76
+ * ```javascript
77
+ * import { convert } from 'html-to-markdown-wasm';
78
+ *
79
+ * const html = '<h1>Hello World</h1>';
80
+ * const markdown = convert(html);
81
+ * console.log(markdown); // # Hello World
82
+ * ```
83
+ */
84
+ export function convert(html: string, options?: WasmConversionOptions | null): string;
85
+
86
+ export function convertBytes(html: Uint8Array, options?: WasmConversionOptions | null): string;
87
+
88
+ export function convertBytesWithInlineImages(html: Uint8Array, options?: WasmConversionOptions | null, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
89
+
90
+ /**
91
+ * Convert HTML bytes to Markdown with metadata extraction
92
+ *
93
+ * # Arguments
94
+ *
95
+ * * `html` - The HTML bytes to convert
96
+ * * `options` - Optional conversion options (as a JavaScript object)
97
+ * * `metadata_config` - Metadata extraction configuration
98
+ *
99
+ * # Returns
100
+ *
101
+ * JavaScript object with `markdown` (string) and `metadata` (object) fields
102
+ */
103
+ export function convertBytesWithMetadata(html: Uint8Array, options?: WasmConversionOptions | null, metadata_config?: WasmMetadataConfig | null): any;
104
+
105
+ export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
106
+
107
+ export function convertWithInlineImages(html: string, options?: WasmConversionOptions | null, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
108
+
109
+ /**
110
+ * Convert HTML to Markdown with metadata extraction
111
+ *
112
+ * # Arguments
113
+ *
114
+ * * `html` - The HTML string to convert
115
+ * * `options` - Optional conversion options (as a JavaScript object)
116
+ * * `metadata_config` - Metadata extraction configuration
117
+ *
118
+ * # Returns
119
+ *
120
+ * JavaScript object with `markdown` (string) and `metadata` (object) fields
121
+ *
122
+ * # Example
123
+ *
124
+ * ```javascript
125
+ * import { convertWithMetadata, WasmMetadataConfig } from 'html-to-markdown-wasm';
126
+ *
127
+ * const html = '<h1>Hello World</h1><a href="https://example.com">Link</a>';
128
+ * const config = new WasmMetadataConfig();
129
+ * config.extractHeaders = true;
130
+ * config.extractLinks = true;
131
+ *
132
+ * const result = convertWithMetadata(html, null, config);
133
+ * console.log(result.markdown); // # Hello World\n\n[Link](https://example.com)
134
+ * console.log(result.metadata.headers); // [{ level: 1, text: "Hello World", ... }]
135
+ * console.log(result.metadata.links); // [{ href: "https://example.com", text: "Link", ... }]
136
+ * ```
137
+ */
138
+ export function convertWithMetadata(html: string, options?: WasmConversionOptions | null, metadata_config?: WasmMetadataConfig | null): any;
139
+
140
+ export function convertWithOptionsHandle(html: string, handle: WasmConversionOptionsHandle): string;
141
+
142
+ export function createConversionOptionsHandle(options?: WasmConversionOptions | null): WasmConversionOptionsHandle;
143
+
144
+ /**
145
+ * Initialize panic hook for better error messages in the browser
146
+ */
147
+ export function init(): void;
148
+
149
+ export declare function initWasm(): Promise<void>;
150
+ export declare const wasmReady: Promise<void>;
151
+
152
+
153
+ export type WasmHeadingStyle = "underlined" | "atx" | "atxClosed";
154
+ export type WasmListIndentType = "spaces" | "tabs";
155
+ export type WasmWhitespaceMode = "normalized" | "strict";
156
+ export type WasmNewlineStyle = "spaces" | "backslash";
157
+ export type WasmCodeBlockStyle = "indented" | "backticks" | "tildes";
158
+ export type WasmHighlightStyle = "doubleEqual" | "html" | "bold" | "none";
159
+ export type WasmPreprocessingPreset = "minimal" | "standard" | "aggressive";
160
+
161
+ export interface WasmPreprocessingOptions {
162
+ enabled?: boolean;
163
+ preset?: WasmPreprocessingPreset;
164
+ removeNavigation?: boolean;
165
+ removeForms?: boolean;
166
+ }
167
+
168
+ export interface WasmConversionOptions {
169
+ headingStyle?: WasmHeadingStyle;
170
+ listIndentType?: WasmListIndentType;
171
+ listIndentWidth?: number;
172
+ bullets?: string;
173
+ strongEmSymbol?: string;
174
+ escapeAsterisks?: boolean;
175
+ escapeUnderscores?: boolean;
176
+ escapeMisc?: boolean;
177
+ escapeAscii?: boolean;
178
+ codeLanguage?: string;
179
+ autolinks?: boolean;
180
+ defaultTitle?: boolean;
181
+ brInTables?: boolean;
182
+ hocrSpatialTables?: boolean;
183
+ highlightStyle?: WasmHighlightStyle;
184
+ extractMetadata?: boolean;
185
+ whitespaceMode?: WasmWhitespaceMode;
186
+ stripNewlines?: boolean;
187
+ wrap?: boolean;
188
+ wrapWidth?: number;
189
+ convertAsInline?: boolean;
190
+ subSymbol?: string;
191
+ supSymbol?: string;
192
+ newlineStyle?: WasmNewlineStyle;
193
+ codeBlockStyle?: WasmCodeBlockStyle;
194
+ keepInlineImagesIn?: string[];
195
+ preprocessing?: WasmPreprocessingOptions | null;
196
+ encoding?: string;
197
+ debug?: boolean;
198
+ stripTags?: string[];
199
+ preserveTags?: string[];
200
+ }
@@ -0,0 +1,116 @@
1
+ import * as wasmModule from "./html_to_markdown_wasm_bg.wasm";
2
+ export * from "./html_to_markdown_wasm_bg.js";
3
+ import * as imports_mod from "./html_to_markdown_wasm_bg.js";
4
+
5
+ const notReadyError = () =>
6
+ new Error("html-to-markdown-wasm: WebAssembly bundle is still initializing. Await initWasm() before calling convert() in runtimes that load WASM asynchronously (e.g., Cloudflare Workers).");
7
+
8
+ const notReadyProxy = new Proxy({}, {
9
+ get(_target, prop) {
10
+ if (prop === "__esModule") {
11
+ return true;
12
+ }
13
+ throw notReadyError();
14
+ }
15
+ });
16
+
17
+ let wasmExports;
18
+ let initialized = false;
19
+ let initPromise;
20
+
21
+ imports_mod.__wbg_set_wasm(notReadyProxy);
22
+
23
+ function asExports(value) {
24
+ if (!value) {
25
+ return null;
26
+ }
27
+ if (typeof value.__wbindgen_start === "function") {
28
+ return value;
29
+ }
30
+ if (value instanceof WebAssembly.Instance) {
31
+ return value.exports;
32
+ }
33
+ if (typeof value === "object") {
34
+ if (value.instance instanceof WebAssembly.Instance) {
35
+ return value.instance.exports;
36
+ }
37
+ if (value.default instanceof WebAssembly.Instance) {
38
+ return value.default.exports;
39
+ }
40
+ if (value.default && value.default.instance instanceof WebAssembly.Instance) {
41
+ return value.default.instance.exports;
42
+ }
43
+ }
44
+ return null;
45
+ }
46
+
47
+ function finalize(exports) {
48
+ wasmExports = exports;
49
+ imports_mod.__wbg_set_wasm(exports);
50
+ if (typeof exports.__wbindgen_start === "function") {
51
+ exports.__wbindgen_start();
52
+ }
53
+ initialized = true;
54
+ return exports;
55
+ }
56
+
57
+ function trySyncInit() {
58
+ try {
59
+ const exports = asExports(wasmModule);
60
+ if (exports) {
61
+ finalize(exports);
62
+ }
63
+ } catch {
64
+ // ignore and fall back to async init
65
+ }
66
+ }
67
+
68
+ trySyncInit();
69
+
70
+ async function ensureInitPromise() {
71
+ if (initialized) {
72
+ return Promise.resolve(wasmExports);
73
+ }
74
+ if (!initPromise) {
75
+ initPromise = (async () => {
76
+ let module = wasmModule;
77
+
78
+ // Handle promise-wrapped modules
79
+ if (module && typeof module.then === "function") {
80
+ module = await module;
81
+ }
82
+
83
+ // Handle function loaders (like @rollup/plugin-wasm)
84
+ if (module && typeof module.default === "function") {
85
+ module = await module.default(module);
86
+ }
87
+
88
+ // Handle WebAssembly.Module (Wrangler/esbuild)
89
+ if (module && module.default instanceof WebAssembly.Module) {
90
+ const imports = {};
91
+ imports["./html_to_markdown_wasm_bg.js"] = {};
92
+ for (const key in imports_mod) {
93
+ if ((key.startsWith('__wbg_') || key.startsWith('__wbindgen_')) && key !== '__wbg_set_wasm' && typeof imports_mod[key] === 'function') {
94
+ imports["./html_to_markdown_wasm_bg.js"][key] = imports_mod[key];
95
+ }
96
+ }
97
+ const instance = await WebAssembly.instantiate(module.default, imports);
98
+ return finalize(instance.exports);
99
+ }
100
+
101
+ // Try standard export detection
102
+ const exports = asExports(module);
103
+ if (!exports) {
104
+ throw new Error("html-to-markdown-wasm: failed to initialize WebAssembly bundle. Call initWasm() with a supported bundler configuration.");
105
+ }
106
+ return finalize(exports);
107
+ })();
108
+ }
109
+ return initPromise;
110
+ }
111
+
112
+ export const wasmReady = ensureInitPromise();
113
+
114
+ export async function initWasm() {
115
+ return ensureInitPromise();
116
+ }