html-to-markdown-wasm 2.6.6 → 2.7.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.
@@ -1,5 +1,8 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+ export function convertBytesWithInlineImages(html: Uint8Array, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
4
+ export function convertBytes(html: Uint8Array, options: any): string;
5
+ export function createConversionOptionsHandle(options: any): WasmConversionOptionsHandle;
3
6
  /**
4
7
  * Convert HTML to Markdown
5
8
  *
@@ -11,7 +14,7 @@
11
14
  * # Example
12
15
  *
13
16
  * ```javascript
14
- * import { convert } from '@html-to-markdown/wasm';
17
+ * import { convert } from 'html-to-markdown-wasm';
15
18
  *
16
19
  * const html = '<h1>Hello World</h1>';
17
20
  * const markdown = convert(html);
@@ -19,34 +22,18 @@
19
22
  * ```
20
23
  */
21
24
  export function convert(html: string, options: any): string;
22
- /**
23
- * Convert HTML to Markdown while collecting inline images
24
- *
25
- * # Arguments
26
- *
27
- * * `html` - The HTML string to convert
28
- * * `options` - Optional conversion options (as a JavaScript object)
29
- * * `image_config` - Configuration for inline image extraction
30
- *
31
- * # Example
32
- *
33
- * ```javascript
34
- * import { convertWithInlineImages, WasmInlineImageConfig } from '@html-to-markdown/wasm';
35
- *
36
- * const html = '<img src="data:image/png;base64,..." alt="test">';
37
- * const config = new WasmInlineImageConfig(1024 * 1024);
38
- * config.inferDimensions = true;
39
- *
40
- * const result = convertWithInlineImages(html, null, config);
41
- * console.log(result.markdown);
42
- * console.log(result.inlineImages.length);
43
- * ```
44
- */
45
- export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
25
+ export function convertWithOptionsHandle(html: string, handle: WasmConversionOptionsHandle): string;
26
+ export function convertBytesWithOptionsHandle(html: Uint8Array, handle: WasmConversionOptionsHandle): string;
46
27
  /**
47
28
  * Initialize panic hook for better error messages in the browser
48
29
  */
49
30
  export function init(): void;
31
+ export function convertWithInlineImages(html: string, options: any, image_config?: WasmInlineImageConfig | null): WasmHtmlExtraction;
32
+ export class WasmConversionOptionsHandle {
33
+ free(): void;
34
+ [Symbol.dispose](): void;
35
+ constructor(options: any);
36
+ }
50
37
  /**
51
38
  * Result of HTML extraction with inline images
52
39
  */
@@ -99,12 +86,19 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
99
86
 
100
87
  export interface InitOutput {
101
88
  readonly memory: WebAssembly.Memory;
89
+ readonly __wbg_wasmconversionoptionshandle_free: (a: number, b: number) => void;
102
90
  readonly __wbg_wasmhtmlextraction_free: (a: number, b: number) => void;
103
91
  readonly __wbg_wasminlineimage_free: (a: number, b: number) => void;
104
92
  readonly __wbg_wasminlineimageconfig_free: (a: number, b: number) => void;
105
93
  readonly __wbg_wasminlineimagewarning_free: (a: number, b: number) => void;
106
94
  readonly convert: (a: number, b: number, c: number, d: number) => void;
95
+ readonly convertBytes: (a: number, b: number, c: number) => void;
96
+ readonly convertBytesWithInlineImages: (a: number, b: number, c: number, d: number) => void;
97
+ readonly convertBytesWithOptionsHandle: (a: number, b: number, c: number) => void;
107
98
  readonly convertWithInlineImages: (a: number, b: number, c: number, d: number, e: number) => void;
99
+ readonly convertWithOptionsHandle: (a: number, b: number, c: number, d: number) => void;
100
+ readonly createConversionOptionsHandle: (a: number, b: number) => void;
101
+ readonly wasmconversionoptionshandle_new: (a: number, b: number) => void;
108
102
  readonly wasmhtmlextraction_inlineImages: (a: number, b: number) => void;
109
103
  readonly wasmhtmlextraction_markdown: (a: number, b: number) => void;
110
104
  readonly wasmhtmlextraction_warnings: (a: number, b: number) => void;
@@ -227,6 +227,89 @@ function getArrayJsValueFromWasm0(ptr, len) {
227
227
  }
228
228
  return result;
229
229
  }
230
+
231
+ function _assertClass(instance, klass) {
232
+ if (!(instance instanceof klass)) {
233
+ throw new Error(`expected instance of ${klass.name}`);
234
+ }
235
+ }
236
+ /**
237
+ * @param {Uint8Array} html
238
+ * @param {any} options
239
+ * @param {WasmInlineImageConfig | null} [image_config]
240
+ * @returns {WasmHtmlExtraction}
241
+ */
242
+ export function convertBytesWithInlineImages(html, options, image_config) {
243
+ try {
244
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
245
+ let ptr0 = 0;
246
+ if (!isLikeNone(image_config)) {
247
+ _assertClass(image_config, WasmInlineImageConfig);
248
+ ptr0 = image_config.__destroy_into_raw();
249
+ }
250
+ wasm.convertBytesWithInlineImages(retptr, addHeapObject(html), addHeapObject(options), ptr0);
251
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
252
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
253
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
254
+ if (r2) {
255
+ throw takeObject(r1);
256
+ }
257
+ return WasmHtmlExtraction.__wrap(r0);
258
+ } finally {
259
+ wasm.__wbindgen_add_to_stack_pointer(16);
260
+ }
261
+ }
262
+
263
+ /**
264
+ * @param {Uint8Array} html
265
+ * @param {any} options
266
+ * @returns {string}
267
+ */
268
+ export function convertBytes(html, options) {
269
+ let deferred2_0;
270
+ let deferred2_1;
271
+ try {
272
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
273
+ wasm.convertBytes(retptr, addHeapObject(html), addHeapObject(options));
274
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
275
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
276
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
277
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
278
+ var ptr1 = r0;
279
+ var len1 = r1;
280
+ if (r3) {
281
+ ptr1 = 0; len1 = 0;
282
+ throw takeObject(r2);
283
+ }
284
+ deferred2_0 = ptr1;
285
+ deferred2_1 = len1;
286
+ return getStringFromWasm0(ptr1, len1);
287
+ } finally {
288
+ wasm.__wbindgen_add_to_stack_pointer(16);
289
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
290
+ }
291
+ }
292
+
293
+ /**
294
+ * @param {any} options
295
+ * @returns {WasmConversionOptionsHandle}
296
+ */
297
+ export function createConversionOptionsHandle(options) {
298
+ try {
299
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
300
+ wasm.createConversionOptionsHandle(retptr, addHeapObject(options));
301
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
302
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
303
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
304
+ if (r2) {
305
+ throw takeObject(r1);
306
+ }
307
+ return WasmConversionOptionsHandle.__wrap(r0);
308
+ } finally {
309
+ wasm.__wbindgen_add_to_stack_pointer(16);
310
+ }
311
+ }
312
+
230
313
  /**
231
314
  * Convert HTML to Markdown
232
315
  *
@@ -238,7 +321,7 @@ function getArrayJsValueFromWasm0(ptr, len) {
238
321
  * # Example
239
322
  *
240
323
  * ```javascript
241
- * import { convert } from '@html-to-markdown/wasm';
324
+ * import { convert } from 'html-to-markdown-wasm';
242
325
  *
243
326
  * const html = '<h1>Hello World</h1>';
244
327
  * const markdown = convert(html);
@@ -275,33 +358,78 @@ export function convert(html, options) {
275
358
  }
276
359
  }
277
360
 
278
- function _assertClass(instance, klass) {
279
- if (!(instance instanceof klass)) {
280
- throw new Error(`expected instance of ${klass.name}`);
361
+ /**
362
+ * @param {string} html
363
+ * @param {WasmConversionOptionsHandle} handle
364
+ * @returns {string}
365
+ */
366
+ export function convertWithOptionsHandle(html, handle) {
367
+ let deferred3_0;
368
+ let deferred3_1;
369
+ try {
370
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
371
+ const ptr0 = passStringToWasm0(html, wasm.__wbindgen_export, wasm.__wbindgen_export2);
372
+ const len0 = WASM_VECTOR_LEN;
373
+ _assertClass(handle, WasmConversionOptionsHandle);
374
+ wasm.convertWithOptionsHandle(retptr, ptr0, len0, handle.__wbg_ptr);
375
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
376
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
377
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
378
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
379
+ var ptr2 = r0;
380
+ var len2 = r1;
381
+ if (r3) {
382
+ ptr2 = 0; len2 = 0;
383
+ throw takeObject(r2);
384
+ }
385
+ deferred3_0 = ptr2;
386
+ deferred3_1 = len2;
387
+ return getStringFromWasm0(ptr2, len2);
388
+ } finally {
389
+ wasm.__wbindgen_add_to_stack_pointer(16);
390
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
281
391
  }
282
392
  }
393
+
394
+ /**
395
+ * @param {Uint8Array} html
396
+ * @param {WasmConversionOptionsHandle} handle
397
+ * @returns {string}
398
+ */
399
+ export function convertBytesWithOptionsHandle(html, handle) {
400
+ let deferred2_0;
401
+ let deferred2_1;
402
+ try {
403
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
404
+ _assertClass(handle, WasmConversionOptionsHandle);
405
+ wasm.convertBytesWithOptionsHandle(retptr, addHeapObject(html), handle.__wbg_ptr);
406
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
407
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
408
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
409
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
410
+ var ptr1 = r0;
411
+ var len1 = r1;
412
+ if (r3) {
413
+ ptr1 = 0; len1 = 0;
414
+ throw takeObject(r2);
415
+ }
416
+ deferred2_0 = ptr1;
417
+ deferred2_1 = len1;
418
+ return getStringFromWasm0(ptr1, len1);
419
+ } finally {
420
+ wasm.__wbindgen_add_to_stack_pointer(16);
421
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
422
+ }
423
+ }
424
+
425
+ /**
426
+ * Initialize panic hook for better error messages in the browser
427
+ */
428
+ export function init() {
429
+ wasm.init();
430
+ }
431
+
283
432
  /**
284
- * Convert HTML to Markdown while collecting inline images
285
- *
286
- * # Arguments
287
- *
288
- * * `html` - The HTML string to convert
289
- * * `options` - Optional conversion options (as a JavaScript object)
290
- * * `image_config` - Configuration for inline image extraction
291
- *
292
- * # Example
293
- *
294
- * ```javascript
295
- * import { convertWithInlineImages, WasmInlineImageConfig } from '@html-to-markdown/wasm';
296
- *
297
- * const html = '<img src="data:image/png;base64,..." alt="test">';
298
- * const config = new WasmInlineImageConfig(1024 * 1024);
299
- * config.inferDimensions = true;
300
- *
301
- * const result = convertWithInlineImages(html, null, config);
302
- * console.log(result.markdown);
303
- * console.log(result.inlineImages.length);
304
- * ```
305
433
  * @param {string} html
306
434
  * @param {any} options
307
435
  * @param {WasmInlineImageConfig | null} [image_config]
@@ -330,12 +458,53 @@ export function convertWithInlineImages(html, options, image_config) {
330
458
  }
331
459
  }
332
460
 
333
- /**
334
- * Initialize panic hook for better error messages in the browser
335
- */
336
- export function init() {
337
- wasm.init();
461
+ const WasmConversionOptionsHandleFinalization = (typeof FinalizationRegistry === 'undefined')
462
+ ? { register: () => {}, unregister: () => {} }
463
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmconversionoptionshandle_free(ptr >>> 0, 1));
464
+
465
+ export class WasmConversionOptionsHandle {
466
+
467
+ static __wrap(ptr) {
468
+ ptr = ptr >>> 0;
469
+ const obj = Object.create(WasmConversionOptionsHandle.prototype);
470
+ obj.__wbg_ptr = ptr;
471
+ WasmConversionOptionsHandleFinalization.register(obj, obj.__wbg_ptr, obj);
472
+ return obj;
473
+ }
474
+
475
+ __destroy_into_raw() {
476
+ const ptr = this.__wbg_ptr;
477
+ this.__wbg_ptr = 0;
478
+ WasmConversionOptionsHandleFinalization.unregister(this);
479
+ return ptr;
480
+ }
481
+
482
+ free() {
483
+ const ptr = this.__destroy_into_raw();
484
+ wasm.__wbg_wasmconversionoptionshandle_free(ptr, 0);
485
+ }
486
+ /**
487
+ * @param {any} options
488
+ */
489
+ constructor(options) {
490
+ try {
491
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
492
+ wasm.wasmconversionoptionshandle_new(retptr, addHeapObject(options));
493
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
494
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
495
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
496
+ if (r2) {
497
+ throw takeObject(r1);
498
+ }
499
+ this.__wbg_ptr = r0 >>> 0;
500
+ WasmConversionOptionsHandleFinalization.register(this, this.__wbg_ptr, this);
501
+ return this;
502
+ } finally {
503
+ wasm.__wbindgen_add_to_stack_pointer(16);
504
+ }
505
+ }
338
506
  }
507
+ if (Symbol.dispose) WasmConversionOptionsHandle.prototype[Symbol.dispose] = WasmConversionOptionsHandle.prototype.free;
339
508
 
340
509
  const WasmHtmlExtractionFinalization = (typeof FinalizationRegistry === 'undefined')
341
510
  ? { register: () => {}, unregister: () => {} }
@@ -838,6 +1007,16 @@ function __wbg_get_imports() {
838
1007
  const ret = result;
839
1008
  return ret;
840
1009
  };
1010
+ imports.wbg.__wbg_instanceof_Object_10bb762262230c68 = function(arg0) {
1011
+ let result;
1012
+ try {
1013
+ result = getObject(arg0) instanceof Object;
1014
+ } catch (_) {
1015
+ result = false;
1016
+ }
1017
+ const ret = result;
1018
+ return ret;
1019
+ };
841
1020
  imports.wbg.__wbg_instanceof_Uint8Array_20c8e73002f7af98 = function(arg0) {
842
1021
  let result;
843
1022
  try {
@@ -860,6 +1039,10 @@ function __wbg_get_imports() {
860
1039
  const ret = Symbol.iterator;
861
1040
  return addHeapObject(ret);
862
1041
  };
1042
+ imports.wbg.__wbg_keys_b4d27b02ad14f4be = function(arg0) {
1043
+ const ret = Object.keys(getObject(arg0));
1044
+ return addHeapObject(ret);
1045
+ };
863
1046
  imports.wbg.__wbg_length_69bca3cb64fc8748 = function(arg0) {
864
1047
  const ret = getObject(arg0).length;
865
1048
  return ret;
@@ -1,12 +1,19 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
+ export const __wbg_wasmconversionoptionshandle_free: (a: number, b: number) => void;
4
5
  export const __wbg_wasmhtmlextraction_free: (a: number, b: number) => void;
5
6
  export const __wbg_wasminlineimage_free: (a: number, b: number) => void;
6
7
  export const __wbg_wasminlineimageconfig_free: (a: number, b: number) => void;
7
8
  export const __wbg_wasminlineimagewarning_free: (a: number, b: number) => void;
8
9
  export const convert: (a: number, b: number, c: number, d: number) => void;
10
+ export const convertBytes: (a: number, b: number, c: number) => void;
11
+ export const convertBytesWithInlineImages: (a: number, b: number, c: number, d: number) => void;
12
+ export const convertBytesWithOptionsHandle: (a: number, b: number, c: number) => void;
9
13
  export const convertWithInlineImages: (a: number, b: number, c: number, d: number, e: number) => void;
14
+ export const convertWithOptionsHandle: (a: number, b: number, c: number, d: number) => void;
15
+ export const createConversionOptionsHandle: (a: number, b: number) => void;
16
+ export const wasmconversionoptionshandle_new: (a: number, b: number) => void;
10
17
  export const wasmhtmlextraction_inlineImages: (a: number, b: number) => void;
11
18
  export const wasmhtmlextraction_markdown: (a: number, b: number) => void;
12
19
  export const wasmhtmlextraction_warnings: (a: number, b: number) => void;
@@ -4,7 +4,7 @@
4
4
  "collaborators": [
5
5
  "Na'aman Hirschfeld <nhirschfeld@gmail.com>"
6
6
  ],
7
- "version": "2.6.6",
7
+ "version": "2.7.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.6.6",
3
+ "version": "2.7.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",
@@ -50,12 +50,10 @@
50
50
  "test": "vitest run",
51
51
  "test:watch": "vitest",
52
52
  "test:wasm-pack": "wasm-pack test --headless --chrome",
53
- "bench": "tsx benchmark.ts",
54
53
  "clean": "rm -rf dist dist-node dist-web node_modules pkg"
55
54
  },
56
55
  "devDependencies": {
57
56
  "@types/node": "^24.10.0",
58
- "tinybench": "^5.1.0",
59
57
  "tsx": "^4.20.6",
60
58
  "vitest": "^4.0.8",
61
59
  "wasm-pack": "^0.13.1"