html-to-markdown-wasm 2.11.4 → 2.12.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/README.md CHANGED
@@ -97,7 +97,10 @@ console.log(markdown);
97
97
 
98
98
  > **Heads up for edge runtimes:** Cloudflare Workers, Vite dev servers, and other environments that instantiate `.wasm` files asynchronously must call `await initWasm()` (or `await wasmReady`) once during startup before invoking `convert`. Traditional bundlers (Webpack, Rollup) and Deno/Node imports continue to work without manual initialization.
99
99
 
100
- Need a reference setup? Check out the Rollup example under [`examples/wasm-rollup`](https://github.com/Goldziher/html-to-markdown/blob/main/examples/wasm-rollup), which shows how to bundle the WASM artifact, await `wasmReady`, and render the Markdown output in a browser extension–style environment.
100
+ **Working Examples:**
101
+ - [**Browser with Rollup**](https://github.com/Goldziher/html-to-markdown/tree/main/examples/wasm-rollup) - Using dist-web target in browser
102
+ - [**Node.js**](https://github.com/Goldziher/html-to-markdown/tree/main/examples/wasm-node) - Using dist-node target
103
+ - [**Cloudflare Workers**](https://github.com/Goldziher/html-to-markdown/tree/main/examples/wasm-cloudflare) - Using bundler target with Wrangler
101
104
 
102
105
  ### Reusing Options Handles
103
106
 
@@ -238,6 +241,8 @@ export default {
238
241
  };
239
242
  ```
240
243
 
244
+ > See the full [Cloudflare Workers example](https://github.com/Goldziher/html-to-markdown/tree/main/examples/wasm-cloudflare) with Wrangler configuration.
245
+
241
246
  ## TypeScript
242
247
 
243
248
  Full TypeScript support with type definitions:
@@ -1,6 +1,6 @@
1
1
  import * as wasmModule from "./html_to_markdown_wasm_bg.wasm";
2
2
  export * from "./html_to_markdown_wasm_bg.js";
3
- import { __wbg_set_wasm } from "./html_to_markdown_wasm_bg.js";
3
+ import * as imports_mod from "./html_to_markdown_wasm_bg.js";
4
4
 
5
5
  const notReadyError = () =>
6
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).");
@@ -18,7 +18,7 @@ let wasmExports;
18
18
  let initialized = false;
19
19
  let initPromise;
20
20
 
21
- __wbg_set_wasm(notReadyProxy);
21
+ imports_mod.__wbg_set_wasm(notReadyProxy);
22
22
 
23
23
  function asExports(value) {
24
24
  if (!value) {
@@ -46,7 +46,7 @@ function asExports(value) {
46
46
 
47
47
  function finalize(exports) {
48
48
  wasmExports = exports;
49
- __wbg_set_wasm(exports);
49
+ imports_mod.__wbg_set_wasm(exports);
50
50
  if (typeof exports.__wbindgen_start === "function") {
51
51
  exports.__wbindgen_start();
52
52
  }
@@ -67,16 +67,38 @@ function trySyncInit() {
67
67
 
68
68
  trySyncInit();
69
69
 
70
- function ensureInitPromise() {
70
+ async function ensureInitPromise() {
71
71
  if (initialized) {
72
72
  return Promise.resolve(wasmExports);
73
73
  }
74
74
  if (!initPromise) {
75
75
  initPromise = (async () => {
76
76
  let module = wasmModule;
77
+
78
+ // Handle promise-wrapped modules
77
79
  if (module && typeof module.then === "function") {
78
80
  module = await module;
79
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
80
102
  const exports = asExports(module);
81
103
  if (!exports) {
82
104
  throw new Error("html-to-markdown-wasm: failed to initialize WebAssembly bundle. Call initWasm() with a supported bundler configuration.");
Binary file
package/dist/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "collaborators": [
5
5
  "Na'aman Hirschfeld <nhirschfeld@gmail.com>"
6
6
  ],
7
- "version": "2.11.4",
7
+ "version": "2.12.1",
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "Na'aman Hirschfeld <nhirschfeld@gmail.com>"
5
5
  ],
6
- "version": "2.11.4",
6
+ "version": "2.12.1",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
@@ -4,7 +4,7 @@
4
4
  "collaborators": [
5
5
  "Na'aman Hirschfeld <nhirschfeld@gmail.com>"
6
6
  ],
7
- "version": "2.11.4",
7
+ "version": "2.12.1",
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-to-markdown-wasm",
3
- "version": "2.11.4",
3
+ "version": "2.12.1",
4
4
  "description": "High-performance HTML to Markdown converter - WebAssembly bindings",
5
5
  "main": "dist/html_to_markdown_wasm.js",
6
6
  "types": "dist/html_to_markdown_wasm.d.ts",
@@ -53,7 +53,7 @@
53
53
  "clean": "rm -rf dist dist-node dist-web node_modules pkg"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/node": "^24.10.1",
56
+ "@types/node": "^24.10.2",
57
57
  "tsx": "^4.21.0",
58
58
  "vitest": "^4.0.15",
59
59
  "wasm-pack": "^0.13.1"