html-to-markdown-wasm 2.7.0 → 2.7.2

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
@@ -1,5 +1,8 @@
1
1
  # html-to-markdown-wasm
2
2
 
3
+ > **npm package:** `html-to-markdown-wasm` (this README).
4
+ > Use [`html-to-markdown-node`](https://www.npmjs.com/package/html-to-markdown-node) when you only target Node.js or Bun and want native performance.
5
+
3
6
  Universal HTML to Markdown converter using WebAssembly.
4
7
 
5
8
  Powered by the same Rust engine as the Node.js, Python, Ruby, and PHP bindings, so Markdown output stays identical regardless of runtime.
@@ -38,6 +41,23 @@ Universal WebAssembly bindings with **excellent performance** across all JavaScr
38
41
  - **vs Python**: ~6.3× faster (no FFI overhead)
39
42
  - **Best for**: Universal deployment (browsers, Deno, edge runtimes, cross-platform apps)
40
43
 
44
+ ### Benchmark Fixtures (Apple M4)
45
+
46
+ Numbers captured via `task bench:bindings -- --language wasm` using the shared Wikipedia + hOCR suite:
47
+
48
+ | Document | Size | ops/sec (WASM) |
49
+ | ---------------------- | ------ | -------------- |
50
+ | Lists (Timeline) | 129 KB | 882 |
51
+ | Tables (Countries) | 360 KB | 242 |
52
+ | Medium (Python) | 657 KB | 121 |
53
+ | Large (Rust) | 567 KB | 124 |
54
+ | Small (Intro) | 463 KB | 163 |
55
+ | hOCR German PDF | 44 KB | 1,637 |
56
+ | hOCR Invoice | 4 KB | 7,775 |
57
+ | hOCR Embedded Tables | 37 KB | 1,667 |
58
+
59
+ > Expect slightly higher numbers in long-lived browser/Deno workers once the WASM module is warm.
60
+
41
61
  ## Installation
42
62
 
43
63
  ### npm / Yarn / pnpm
@@ -72,13 +92,15 @@ console.log(markdown);
72
92
  // This is **fast**!
73
93
  ```
74
94
 
95
+ > **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.
96
+
75
97
  ### Reusing Options Handles
76
98
 
77
99
  ```ts
78
100
  import {
79
101
  convertWithOptionsHandle,
80
102
  createConversionOptionsHandle,
81
- } from '@html-to-markdown/wasm';
103
+ } from 'html-to-markdown-wasm';
82
104
 
83
105
  const handle = createConversionOptionsHandle({ hocrSpatialTables: false });
84
106
  const markdown = convertWithOptionsHandle('<h1>Reusable</h1>', handle);
@@ -94,7 +116,7 @@ import {
94
116
  convertBytesWithOptionsHandle,
95
117
  createConversionOptionsHandle,
96
118
  convertBytesWithInlineImages,
97
- } from '@html-to-markdown/wasm';
119
+ } from 'html-to-markdown-wasm';
98
120
  import { readFileSync } from 'node:fs';
99
121
 
100
122
  const htmlBytes = readFileSync('input.html'); // Buffer -> Uint8Array
@@ -192,10 +214,15 @@ const markdown = convert('<h1>Hello</h1>', {
192
214
  ### Cloudflare Workers
193
215
 
194
216
  ```typescript
195
- import { convert } from 'html-to-markdown-wasm';
217
+ import { convert, initWasm, wasmReady } from 'html-to-markdown-wasm';
218
+
219
+ // Cloudflare Workers / other edge runtimes instantiate WASM asynchronously.
220
+ // Kick off initialization once at module scope.
221
+ const ready = wasmReady ?? initWasm();
196
222
 
197
223
  export default {
198
224
  async fetch(request: Request): Promise<Response> {
225
+ await ready;
199
226
  const html = await request.text();
200
227
  const markdown = convert(html, { headingStyle: 'atx' });
201
228
 
@@ -310,7 +337,7 @@ See the [TypeScript definitions](./dist-node/html_to_markdown_wasm.d.ts) for all
310
337
  Keep specific HTML tags in their original form:
311
338
 
312
339
  ```typescript
313
- import { convert } from '@html-to-markdown/wasm';
340
+ import { convert } from 'html-to-markdown-wasm';
314
341
 
315
342
  const html = `
316
343
  <p>Before table</p>
@@ -1,6 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- export function convertBytes(html: Uint8Array, options: any): string;
3
+ export function createConversionOptionsHandle(options: any): WasmConversionOptionsHandle;
4
4
  /**
5
5
  * Convert HTML to Markdown
6
6
  *
@@ -12,7 +12,7 @@ export function convertBytes(html: Uint8Array, options: any): string;
12
12
  * # Example
13
13
  *
14
14
  * ```javascript
15
- * import { convert } from '@html-to-markdown/wasm';
15
+ * import { convert } from 'html-to-markdown-wasm';
16
16
  *
17
17
  * const html = '<h1>Hello World</h1>';
18
18
  * const markdown = convert(html);
@@ -20,15 +20,15 @@ export function convertBytes(html: Uint8Array, options: any): string;
20
20
  * ```
21
21
  */
22
22
  export function convert(html: string, options: any): string;
23
+ export function convertBytes(html: Uint8Array, options: any): string;
23
24
  export function convertWithOptionsHandle(html: string, handle: WasmConversionOptionsHandle): string;
24
- export function createConversionOptionsHandle(options: any): WasmConversionOptionsHandle;
25
- export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
26
25
  export function convertBytesWithInlineImages(html: Uint8Array, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
26
+ export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
27
27
  /**
28
28
  * Initialize panic hook for better error messages in the browser
29
29
  */
30
30
  export function init(): void;
31
- export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
31
+ export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
32
32
  export class WasmConversionOptionsHandle {
33
33
  free(): void;
34
34
  [Symbol.dispose](): void;
@@ -81,3 +81,6 @@ export class WasmInlineImageWarning {
81
81
  readonly index: number;
82
82
  readonly message: string;
83
83
  }
84
+
85
+ export declare function initWasm(): Promise<void>;
86
+ export declare const wasmReady: Promise<void>;
@@ -1,5 +1,94 @@
1
- import * as wasm from "./html_to_markdown_wasm_bg.wasm";
1
+ import * as wasmModule from "./html_to_markdown_wasm_bg.wasm";
2
2
  export * from "./html_to_markdown_wasm_bg.js";
3
3
  import { __wbg_set_wasm } from "./html_to_markdown_wasm_bg.js";
4
- __wbg_set_wasm(wasm);
5
- wasm.__wbindgen_start();
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
+ __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
+ __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
+ function ensureInitPromise() {
71
+ if (initialized) {
72
+ return Promise.resolve(wasmExports);
73
+ }
74
+ if (!initPromise) {
75
+ initPromise = (async () => {
76
+ let module = wasmModule;
77
+ if (module && typeof module.then === "function") {
78
+ module = await module;
79
+ }
80
+ const exports = asExports(module);
81
+ if (!exports) {
82
+ throw new Error("html-to-markdown-wasm: failed to initialize WebAssembly bundle. Call initWasm() with a supported bundler configuration.");
83
+ }
84
+ return finalize(exports);
85
+ })();
86
+ }
87
+ return initPromise;
88
+ }
89
+
90
+ export const wasmReady = ensureInitPromise();
91
+
92
+ export async function initWasm() {
93
+ return ensureInitPromise();
94
+ }
@@ -232,32 +232,22 @@ function getArrayJsValueFromWasm0(ptr, len) {
232
232
  return result;
233
233
  }
234
234
  /**
235
- * @param {Uint8Array} html
236
235
  * @param {any} options
237
- * @returns {string}
236
+ * @returns {WasmConversionOptionsHandle}
238
237
  */
239
- export function convertBytes(html, options) {
240
- let deferred2_0;
241
- let deferred2_1;
238
+ export function createConversionOptionsHandle(options) {
242
239
  try {
243
240
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
244
- wasm.convertBytes(retptr, addHeapObject(html), addHeapObject(options));
241
+ wasm.createConversionOptionsHandle(retptr, addHeapObject(options));
245
242
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
246
243
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
247
244
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
248
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
249
- var ptr1 = r0;
250
- var len1 = r1;
251
- if (r3) {
252
- ptr1 = 0; len1 = 0;
253
- throw takeObject(r2);
245
+ if (r2) {
246
+ throw takeObject(r1);
254
247
  }
255
- deferred2_0 = ptr1;
256
- deferred2_1 = len1;
257
- return getStringFromWasm0(ptr1, len1);
248
+ return WasmConversionOptionsHandle.__wrap(r0);
258
249
  } finally {
259
250
  wasm.__wbindgen_add_to_stack_pointer(16);
260
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
261
251
  }
262
252
  }
263
253
 
@@ -272,7 +262,7 @@ export function convertBytes(html, options) {
272
262
  * # Example
273
263
  *
274
264
  * ```javascript
275
- * import { convert } from '@html-to-markdown/wasm';
265
+ * import { convert } from 'html-to-markdown-wasm';
276
266
  *
277
267
  * const html = '<h1>Hello World</h1>';
278
268
  * const markdown = convert(html);
@@ -309,6 +299,36 @@ export function convert(html, options) {
309
299
  }
310
300
  }
311
301
 
302
+ /**
303
+ * @param {Uint8Array} html
304
+ * @param {any} options
305
+ * @returns {string}
306
+ */
307
+ export function convertBytes(html, options) {
308
+ let deferred2_0;
309
+ let deferred2_1;
310
+ try {
311
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
312
+ wasm.convertBytes(retptr, addHeapObject(html), addHeapObject(options));
313
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
314
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
315
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
316
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
317
+ var ptr1 = r0;
318
+ var len1 = r1;
319
+ if (r3) {
320
+ ptr1 = 0; len1 = 0;
321
+ throw takeObject(r2);
322
+ }
323
+ deferred2_0 = ptr1;
324
+ deferred2_1 = len1;
325
+ return getStringFromWasm0(ptr1, len1);
326
+ } finally {
327
+ wasm.__wbindgen_add_to_stack_pointer(16);
328
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
329
+ }
330
+ }
331
+
312
332
  function _assertClass(instance, klass) {
313
333
  if (!(instance instanceof klass)) {
314
334
  throw new Error(`expected instance of ${klass.name}`);
@@ -347,55 +367,6 @@ export function convertWithOptionsHandle(html, handle) {
347
367
  }
348
368
  }
349
369
 
350
- /**
351
- * @param {any} options
352
- * @returns {WasmConversionOptionsHandle}
353
- */
354
- export function createConversionOptionsHandle(options) {
355
- try {
356
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
357
- wasm.createConversionOptionsHandle(retptr, addHeapObject(options));
358
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
359
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
360
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
361
- if (r2) {
362
- throw takeObject(r1);
363
- }
364
- return WasmConversionOptionsHandle.__wrap(r0);
365
- } finally {
366
- wasm.__wbindgen_add_to_stack_pointer(16);
367
- }
368
- }
369
-
370
- /**
371
- * @param {string} html
372
- * @param {any} options
373
- * @param {WasmInlineImageConfig | null} [image_config]
374
- * @returns {WasmHtmlExtraction}
375
- */
376
- export function convertWithInlineImages(html, options, image_config) {
377
- try {
378
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
379
- const ptr0 = passStringToWasm0(html, wasm.__wbindgen_export, wasm.__wbindgen_export2);
380
- const len0 = WASM_VECTOR_LEN;
381
- let ptr1 = 0;
382
- if (!isLikeNone(image_config)) {
383
- _assertClass(image_config, WasmInlineImageConfig);
384
- ptr1 = image_config.__destroy_into_raw();
385
- }
386
- wasm.convertWithInlineImages(retptr, ptr0, len0, addHeapObject(options), ptr1);
387
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
388
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
389
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
390
- if (r2) {
391
- throw takeObject(r1);
392
- }
393
- return WasmHtmlExtraction.__wrap(r0);
394
- } finally {
395
- wasm.__wbindgen_add_to_stack_pointer(16);
396
- }
397
- }
398
-
399
370
  /**
400
371
  * @param {Uint8Array} html
401
372
  * @param {any} options
@@ -423,13 +394,6 @@ export function convertBytesWithInlineImages(html, options, image_config) {
423
394
  }
424
395
  }
425
396
 
426
- /**
427
- * Initialize panic hook for better error messages in the browser
428
- */
429
- export function init() {
430
- wasm.init();
431
- }
432
-
433
397
  /**
434
398
  * @param {Uint8Array} html
435
399
  * @param {WasmConversionOptionsHandle} handle
@@ -461,6 +425,42 @@ export function convertBytesWithOptionsHandle(html, handle) {
461
425
  }
462
426
  }
463
427
 
428
+ /**
429
+ * Initialize panic hook for better error messages in the browser
430
+ */
431
+ export function init() {
432
+ wasm.init();
433
+ }
434
+
435
+ /**
436
+ * @param {string} html
437
+ * @param {any} options
438
+ * @param {WasmInlineImageConfig | null} [image_config]
439
+ * @returns {WasmHtmlExtraction}
440
+ */
441
+ export function convertWithInlineImages(html, options, image_config) {
442
+ try {
443
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
444
+ const ptr0 = passStringToWasm0(html, wasm.__wbindgen_export, wasm.__wbindgen_export2);
445
+ const len0 = WASM_VECTOR_LEN;
446
+ let ptr1 = 0;
447
+ if (!isLikeNone(image_config)) {
448
+ _assertClass(image_config, WasmInlineImageConfig);
449
+ ptr1 = image_config.__destroy_into_raw();
450
+ }
451
+ wasm.convertWithInlineImages(retptr, ptr0, len0, addHeapObject(options), ptr1);
452
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
453
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
454
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
455
+ if (r2) {
456
+ throw takeObject(r1);
457
+ }
458
+ return WasmHtmlExtraction.__wrap(r0);
459
+ } finally {
460
+ wasm.__wbindgen_add_to_stack_pointer(16);
461
+ }
462
+ }
463
+
464
464
  const WasmConversionOptionsHandleFinalization = (typeof FinalizationRegistry === 'undefined')
465
465
  ? { register: () => {}, unregister: () => {} }
466
466
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmconversionoptionshandle_free(ptr >>> 0, 1));
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.7.0",
7
+ "version": "2.7.2",
8
8
  "license": "MIT",
9
9
  "repository": {
10
10
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- export function convertBytes(html: Uint8Array, options: any): string;
3
+ export function createConversionOptionsHandle(options: any): WasmConversionOptionsHandle;
4
4
  /**
5
5
  * Convert HTML to Markdown
6
6
  *
@@ -12,7 +12,7 @@ export function convertBytes(html: Uint8Array, options: any): string;
12
12
  * # Example
13
13
  *
14
14
  * ```javascript
15
- * import { convert } from '@html-to-markdown/wasm';
15
+ * import { convert } from 'html-to-markdown-wasm';
16
16
  *
17
17
  * const html = '<h1>Hello World</h1>';
18
18
  * const markdown = convert(html);
@@ -20,15 +20,15 @@ export function convertBytes(html: Uint8Array, options: any): string;
20
20
  * ```
21
21
  */
22
22
  export function convert(html: string, options: any): string;
23
+ export function convertBytes(html: Uint8Array, options: any): string;
23
24
  export function convertWithOptionsHandle(html: string, handle: WasmConversionOptionsHandle): string;
24
- export function createConversionOptionsHandle(options: any): WasmConversionOptionsHandle;
25
- export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
26
25
  export function convertBytesWithInlineImages(html: Uint8Array, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
26
+ export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
27
27
  /**
28
28
  * Initialize panic hook for better error messages in the browser
29
29
  */
30
30
  export function init(): void;
31
- export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
31
+ export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
32
32
  export class WasmConversionOptionsHandle {
33
33
  free(): void;
34
34
  [Symbol.dispose](): void;
@@ -222,32 +222,22 @@ function getArrayJsValueFromWasm0(ptr, len) {
222
222
  return result;
223
223
  }
224
224
  /**
225
- * @param {Uint8Array} html
226
225
  * @param {any} options
227
- * @returns {string}
226
+ * @returns {WasmConversionOptionsHandle}
228
227
  */
229
- exports.convertBytes = function(html, options) {
230
- let deferred2_0;
231
- let deferred2_1;
228
+ exports.createConversionOptionsHandle = function(options) {
232
229
  try {
233
230
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
234
- wasm.convertBytes(retptr, addHeapObject(html), addHeapObject(options));
231
+ wasm.createConversionOptionsHandle(retptr, addHeapObject(options));
235
232
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
236
233
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
237
234
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
238
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
239
- var ptr1 = r0;
240
- var len1 = r1;
241
- if (r3) {
242
- ptr1 = 0; len1 = 0;
243
- throw takeObject(r2);
235
+ if (r2) {
236
+ throw takeObject(r1);
244
237
  }
245
- deferred2_0 = ptr1;
246
- deferred2_1 = len1;
247
- return getStringFromWasm0(ptr1, len1);
238
+ return WasmConversionOptionsHandle.__wrap(r0);
248
239
  } finally {
249
240
  wasm.__wbindgen_add_to_stack_pointer(16);
250
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
251
241
  }
252
242
  };
253
243
 
@@ -262,7 +252,7 @@ exports.convertBytes = function(html, options) {
262
252
  * # Example
263
253
  *
264
254
  * ```javascript
265
- * import { convert } from '@html-to-markdown/wasm';
255
+ * import { convert } from 'html-to-markdown-wasm';
266
256
  *
267
257
  * const html = '<h1>Hello World</h1>';
268
258
  * const markdown = convert(html);
@@ -299,6 +289,36 @@ exports.convert = function(html, options) {
299
289
  }
300
290
  };
301
291
 
292
+ /**
293
+ * @param {Uint8Array} html
294
+ * @param {any} options
295
+ * @returns {string}
296
+ */
297
+ exports.convertBytes = function(html, options) {
298
+ let deferred2_0;
299
+ let deferred2_1;
300
+ try {
301
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
302
+ wasm.convertBytes(retptr, addHeapObject(html), addHeapObject(options));
303
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
304
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
305
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
306
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
307
+ var ptr1 = r0;
308
+ var len1 = r1;
309
+ if (r3) {
310
+ ptr1 = 0; len1 = 0;
311
+ throw takeObject(r2);
312
+ }
313
+ deferred2_0 = ptr1;
314
+ deferred2_1 = len1;
315
+ return getStringFromWasm0(ptr1, len1);
316
+ } finally {
317
+ wasm.__wbindgen_add_to_stack_pointer(16);
318
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
319
+ }
320
+ };
321
+
302
322
  function _assertClass(instance, klass) {
303
323
  if (!(instance instanceof klass)) {
304
324
  throw new Error(`expected instance of ${klass.name}`);
@@ -337,55 +357,6 @@ exports.convertWithOptionsHandle = function(html, handle) {
337
357
  }
338
358
  };
339
359
 
340
- /**
341
- * @param {any} options
342
- * @returns {WasmConversionOptionsHandle}
343
- */
344
- exports.createConversionOptionsHandle = function(options) {
345
- try {
346
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
347
- wasm.createConversionOptionsHandle(retptr, addHeapObject(options));
348
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
349
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
350
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
351
- if (r2) {
352
- throw takeObject(r1);
353
- }
354
- return WasmConversionOptionsHandle.__wrap(r0);
355
- } finally {
356
- wasm.__wbindgen_add_to_stack_pointer(16);
357
- }
358
- };
359
-
360
- /**
361
- * @param {string} html
362
- * @param {any} options
363
- * @param {WasmInlineImageConfig | null} [image_config]
364
- * @returns {WasmHtmlExtraction}
365
- */
366
- exports.convertWithInlineImages = function(html, options, image_config) {
367
- try {
368
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
369
- const ptr0 = passStringToWasm0(html, wasm.__wbindgen_export, wasm.__wbindgen_export2);
370
- const len0 = WASM_VECTOR_LEN;
371
- let ptr1 = 0;
372
- if (!isLikeNone(image_config)) {
373
- _assertClass(image_config, WasmInlineImageConfig);
374
- ptr1 = image_config.__destroy_into_raw();
375
- }
376
- wasm.convertWithInlineImages(retptr, ptr0, len0, addHeapObject(options), ptr1);
377
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
378
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
379
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
380
- if (r2) {
381
- throw takeObject(r1);
382
- }
383
- return WasmHtmlExtraction.__wrap(r0);
384
- } finally {
385
- wasm.__wbindgen_add_to_stack_pointer(16);
386
- }
387
- };
388
-
389
360
  /**
390
361
  * @param {Uint8Array} html
391
362
  * @param {any} options
@@ -413,13 +384,6 @@ exports.convertBytesWithInlineImages = function(html, options, image_config) {
413
384
  }
414
385
  };
415
386
 
416
- /**
417
- * Initialize panic hook for better error messages in the browser
418
- */
419
- exports.init = function() {
420
- wasm.init();
421
- };
422
-
423
387
  /**
424
388
  * @param {Uint8Array} html
425
389
  * @param {WasmConversionOptionsHandle} handle
@@ -451,6 +415,42 @@ exports.convertBytesWithOptionsHandle = function(html, handle) {
451
415
  }
452
416
  };
453
417
 
418
+ /**
419
+ * Initialize panic hook for better error messages in the browser
420
+ */
421
+ exports.init = function() {
422
+ wasm.init();
423
+ };
424
+
425
+ /**
426
+ * @param {string} html
427
+ * @param {any} options
428
+ * @param {WasmInlineImageConfig | null} [image_config]
429
+ * @returns {WasmHtmlExtraction}
430
+ */
431
+ exports.convertWithInlineImages = function(html, options, image_config) {
432
+ try {
433
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
434
+ const ptr0 = passStringToWasm0(html, wasm.__wbindgen_export, wasm.__wbindgen_export2);
435
+ const len0 = WASM_VECTOR_LEN;
436
+ let ptr1 = 0;
437
+ if (!isLikeNone(image_config)) {
438
+ _assertClass(image_config, WasmInlineImageConfig);
439
+ ptr1 = image_config.__destroy_into_raw();
440
+ }
441
+ wasm.convertWithInlineImages(retptr, ptr0, len0, addHeapObject(options), ptr1);
442
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
443
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
444
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
445
+ if (r2) {
446
+ throw takeObject(r1);
447
+ }
448
+ return WasmHtmlExtraction.__wrap(r0);
449
+ } finally {
450
+ wasm.__wbindgen_add_to_stack_pointer(16);
451
+ }
452
+ };
453
+
454
454
  const WasmConversionOptionsHandleFinalization = (typeof FinalizationRegistry === 'undefined')
455
455
  ? { register: () => {}, unregister: () => {} }
456
456
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmconversionoptionshandle_free(ptr >>> 0, 1));
@@ -3,7 +3,7 @@
3
3
  "collaborators": [
4
4
  "Na'aman Hirschfeld <nhirschfeld@gmail.com>"
5
5
  ],
6
- "version": "2.7.0",
6
+ "version": "2.7.2",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- export function convertBytes(html: Uint8Array, options: any): string;
3
+ export function createConversionOptionsHandle(options: any): WasmConversionOptionsHandle;
4
4
  /**
5
5
  * Convert HTML to Markdown
6
6
  *
@@ -12,7 +12,7 @@ export function convertBytes(html: Uint8Array, options: any): string;
12
12
  * # Example
13
13
  *
14
14
  * ```javascript
15
- * import { convert } from '@html-to-markdown/wasm';
15
+ * import { convert } from 'html-to-markdown-wasm';
16
16
  *
17
17
  * const html = '<h1>Hello World</h1>';
18
18
  * const markdown = convert(html);
@@ -20,15 +20,15 @@ export function convertBytes(html: Uint8Array, options: any): string;
20
20
  * ```
21
21
  */
22
22
  export function convert(html: string, options: any): string;
23
+ export function convertBytes(html: Uint8Array, options: any): string;
23
24
  export function convertWithOptionsHandle(html: string, handle: WasmConversionOptionsHandle): string;
24
- export function createConversionOptionsHandle(options: any): WasmConversionOptionsHandle;
25
- export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
26
25
  export function convertBytesWithInlineImages(html: Uint8Array, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
26
+ export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
27
27
  /**
28
28
  * Initialize panic hook for better error messages in the browser
29
29
  */
30
30
  export function init(): void;
31
- export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
31
+ export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
32
32
  export class WasmConversionOptionsHandle {
33
33
  free(): void;
34
34
  [Symbol.dispose](): void;
@@ -228,32 +228,22 @@ function getArrayJsValueFromWasm0(ptr, len) {
228
228
  return result;
229
229
  }
230
230
  /**
231
- * @param {Uint8Array} html
232
231
  * @param {any} options
233
- * @returns {string}
232
+ * @returns {WasmConversionOptionsHandle}
234
233
  */
235
- export function convertBytes(html, options) {
236
- let deferred2_0;
237
- let deferred2_1;
234
+ export function createConversionOptionsHandle(options) {
238
235
  try {
239
236
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
240
- wasm.convertBytes(retptr, addHeapObject(html), addHeapObject(options));
237
+ wasm.createConversionOptionsHandle(retptr, addHeapObject(options));
241
238
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
242
239
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
243
240
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
244
- var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
245
- var ptr1 = r0;
246
- var len1 = r1;
247
- if (r3) {
248
- ptr1 = 0; len1 = 0;
249
- throw takeObject(r2);
241
+ if (r2) {
242
+ throw takeObject(r1);
250
243
  }
251
- deferred2_0 = ptr1;
252
- deferred2_1 = len1;
253
- return getStringFromWasm0(ptr1, len1);
244
+ return WasmConversionOptionsHandle.__wrap(r0);
254
245
  } finally {
255
246
  wasm.__wbindgen_add_to_stack_pointer(16);
256
- wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
257
247
  }
258
248
  }
259
249
 
@@ -268,7 +258,7 @@ export function convertBytes(html, options) {
268
258
  * # Example
269
259
  *
270
260
  * ```javascript
271
- * import { convert } from '@html-to-markdown/wasm';
261
+ * import { convert } from 'html-to-markdown-wasm';
272
262
  *
273
263
  * const html = '<h1>Hello World</h1>';
274
264
  * const markdown = convert(html);
@@ -305,6 +295,36 @@ export function convert(html, options) {
305
295
  }
306
296
  }
307
297
 
298
+ /**
299
+ * @param {Uint8Array} html
300
+ * @param {any} options
301
+ * @returns {string}
302
+ */
303
+ export function convertBytes(html, options) {
304
+ let deferred2_0;
305
+ let deferred2_1;
306
+ try {
307
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
308
+ wasm.convertBytes(retptr, addHeapObject(html), addHeapObject(options));
309
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
310
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
311
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
312
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
313
+ var ptr1 = r0;
314
+ var len1 = r1;
315
+ if (r3) {
316
+ ptr1 = 0; len1 = 0;
317
+ throw takeObject(r2);
318
+ }
319
+ deferred2_0 = ptr1;
320
+ deferred2_1 = len1;
321
+ return getStringFromWasm0(ptr1, len1);
322
+ } finally {
323
+ wasm.__wbindgen_add_to_stack_pointer(16);
324
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
325
+ }
326
+ }
327
+
308
328
  function _assertClass(instance, klass) {
309
329
  if (!(instance instanceof klass)) {
310
330
  throw new Error(`expected instance of ${klass.name}`);
@@ -343,55 +363,6 @@ export function convertWithOptionsHandle(html, handle) {
343
363
  }
344
364
  }
345
365
 
346
- /**
347
- * @param {any} options
348
- * @returns {WasmConversionOptionsHandle}
349
- */
350
- export function createConversionOptionsHandle(options) {
351
- try {
352
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
353
- wasm.createConversionOptionsHandle(retptr, addHeapObject(options));
354
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
355
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
356
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
357
- if (r2) {
358
- throw takeObject(r1);
359
- }
360
- return WasmConversionOptionsHandle.__wrap(r0);
361
- } finally {
362
- wasm.__wbindgen_add_to_stack_pointer(16);
363
- }
364
- }
365
-
366
- /**
367
- * @param {string} html
368
- * @param {any} options
369
- * @param {WasmInlineImageConfig | null} [image_config]
370
- * @returns {WasmHtmlExtraction}
371
- */
372
- export function convertWithInlineImages(html, options, image_config) {
373
- try {
374
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
375
- const ptr0 = passStringToWasm0(html, wasm.__wbindgen_export, wasm.__wbindgen_export2);
376
- const len0 = WASM_VECTOR_LEN;
377
- let ptr1 = 0;
378
- if (!isLikeNone(image_config)) {
379
- _assertClass(image_config, WasmInlineImageConfig);
380
- ptr1 = image_config.__destroy_into_raw();
381
- }
382
- wasm.convertWithInlineImages(retptr, ptr0, len0, addHeapObject(options), ptr1);
383
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
384
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
385
- var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
386
- if (r2) {
387
- throw takeObject(r1);
388
- }
389
- return WasmHtmlExtraction.__wrap(r0);
390
- } finally {
391
- wasm.__wbindgen_add_to_stack_pointer(16);
392
- }
393
- }
394
-
395
366
  /**
396
367
  * @param {Uint8Array} html
397
368
  * @param {any} options
@@ -419,13 +390,6 @@ export function convertBytesWithInlineImages(html, options, image_config) {
419
390
  }
420
391
  }
421
392
 
422
- /**
423
- * Initialize panic hook for better error messages in the browser
424
- */
425
- export function init() {
426
- wasm.init();
427
- }
428
-
429
393
  /**
430
394
  * @param {Uint8Array} html
431
395
  * @param {WasmConversionOptionsHandle} handle
@@ -457,6 +421,42 @@ export function convertBytesWithOptionsHandle(html, handle) {
457
421
  }
458
422
  }
459
423
 
424
+ /**
425
+ * Initialize panic hook for better error messages in the browser
426
+ */
427
+ export function init() {
428
+ wasm.init();
429
+ }
430
+
431
+ /**
432
+ * @param {string} html
433
+ * @param {any} options
434
+ * @param {WasmInlineImageConfig | null} [image_config]
435
+ * @returns {WasmHtmlExtraction}
436
+ */
437
+ export function convertWithInlineImages(html, options, image_config) {
438
+ try {
439
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
440
+ const ptr0 = passStringToWasm0(html, wasm.__wbindgen_export, wasm.__wbindgen_export2);
441
+ const len0 = WASM_VECTOR_LEN;
442
+ let ptr1 = 0;
443
+ if (!isLikeNone(image_config)) {
444
+ _assertClass(image_config, WasmInlineImageConfig);
445
+ ptr1 = image_config.__destroy_into_raw();
446
+ }
447
+ wasm.convertWithInlineImages(retptr, ptr0, len0, addHeapObject(options), ptr1);
448
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
449
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
450
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
451
+ if (r2) {
452
+ throw takeObject(r1);
453
+ }
454
+ return WasmHtmlExtraction.__wrap(r0);
455
+ } finally {
456
+ wasm.__wbindgen_add_to_stack_pointer(16);
457
+ }
458
+ }
459
+
460
460
  const WasmConversionOptionsHandleFinalization = (typeof FinalizationRegistry === 'undefined')
461
461
  ? { register: () => {}, unregister: () => {} }
462
462
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmconversionoptionshandle_free(ptr >>> 0, 1));
@@ -4,7 +4,7 @@
4
4
  "collaborators": [
5
5
  "Na'aman Hirschfeld <nhirschfeld@gmail.com>"
6
6
  ],
7
- "version": "2.7.0",
7
+ "version": "2.7.2",
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.7.0",
3
+ "version": "2.7.2",
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",
@@ -42,7 +42,7 @@
42
42
  "README.md"
43
43
  ],
44
44
  "scripts": {
45
- "build": "wasm-pack build --target bundler --out-dir dist",
45
+ "build": "wasm-pack build --target bundler --out-dir dist && node ./scripts/patch-bundler-entry.js",
46
46
  "build:nodejs": "wasm-pack build --target nodejs --out-dir dist-node",
47
47
  "build:web": "wasm-pack build --target web --out-dir dist-web",
48
48
  "build:all": "pnpm run build && pnpm run build:nodejs && pnpm run build:web && pnpm run cleanup:gitignore",
@@ -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.0",
56
+ "@types/node": "^24.10.1",
57
57
  "tsx": "^4.20.6",
58
58
  "vitest": "^4.0.8",
59
59
  "wasm-pack": "^0.13.1"