mdream 1.7.2 → 2.0.0

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/index.d.mts CHANGED
@@ -5,8 +5,6 @@ export interface CleanOptions {
5
5
  fragments?: boolean;
6
6
  /** Strip links with meaningless hrefs (#, javascript:void(0)) → plain text */
7
7
  emptyLinks?: boolean;
8
- /** Collapse 3+ consecutive blank lines to 2 */
9
- blankLines?: boolean;
10
8
  /** Strip links where text equals URL: [https://x.com](https://x.com) → https://x.com */
11
9
  redundantLinks?: boolean;
12
10
  /** Strip self-referencing heading anchors: ## [Title](#title) → ## Title */
@@ -42,8 +40,8 @@ export interface MdreamOptions {
42
40
  origin?: string;
43
41
  /**
44
42
  * Clean up the markdown output. Pass `true` for all cleanup or an object
45
- * to enable specific features. `clean.urls` is handled during conversion;
46
- * other options are post-processing steps (sync API only).
43
+ * to enable specific features. Both `htmlToMarkdown` and
44
+ * `streamHtmlToMarkdown` apply it.
47
45
  */
48
46
  clean?: boolean | CleanOptions;
49
47
  /** Enable minimal preset (frontmatter, isolateMain, tailwind, filter). Default: false */
@@ -59,8 +57,12 @@ export interface MdreamOptions {
59
57
  isolateMain?: boolean;
60
58
  /** Convert Tailwind utility classes. Default when minimal: true */
61
59
  tailwind?: boolean;
62
- /** Filter elements. Default when minimal: excludes form, nav, footer, etc. */
63
- filter?: {
60
+ /**
61
+ * Filter elements by CSS selector. `minimal` excludes form, nav, footer, and
62
+ * similar; a filter passed with `minimal` adds to those excludes. `false`
63
+ * turns filtering off, including the `minimal` one.
64
+ */
65
+ filter?: false | {
64
66
  include?: string[];
65
67
  exclude?: string[];
66
68
  processChildren?: boolean;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MarkdownStream, htmlToMarkdown as htmlToMarkdown$1 } from "../napi/index.mjs";
2
- const MINIMAL_FILTER_DEFAULT = { exclude: [
2
+ const MINIMAL_FILTER_EXCLUDE = [
3
3
  "form",
4
4
  "fieldset",
5
5
  "object",
@@ -12,7 +12,7 @@ const MINIMAL_FILTER_DEFAULT = { exclude: [
12
12
  "select",
13
13
  "button",
14
14
  "nav"
15
- ] };
15
+ ];
16
16
  const CLEAN_ALL = {
17
17
  urls: true,
18
18
  fragments: true,
@@ -22,19 +22,38 @@ const CLEAN_ALL = {
22
22
  emptyImages: true,
23
23
  emptyLinkText: true
24
24
  };
25
- function resolveCleanConfig(options, minimal) {
26
- const cleanUrls = options.cleanUrls === true;
27
- let cleanOpt = options.clean;
28
- if (cleanOpt === void 0) {
29
- if (!minimal) return { cleanUrls };
30
- cleanOpt = true;
25
+ const VALID_OPTIONS = "origin, clean, minimal, frontmatter, isolateMain, tailwind, filter, extraction, tagOverrides, wrapWidth, format";
26
+ function unknownOptionMessage(key, value) {
27
+ switch (key) {
28
+ case "preset": return "mdream has no `preset` option. Pass { minimal: true }.";
29
+ case "cleanUrls": return "mdream has no `cleanUrls` option. Pass { clean: { urls: true } }.";
30
+ case "plugins": return Array.isArray(value) ? "Custom hook plugins require @mdream/js. Pass declarative config (e.g. { frontmatter: true }) to the Rust engine, or import { htmlToMarkdown } from '@mdream/js' for hook-based plugins. See https://github.com/harlan-zw/mdream/tree/main/packages/js#migrating-from-v1" : "mdream takes plugin options at the top level, such as { frontmatter: true }.";
31
31
  }
32
- if (!cleanOpt) return { cleanUrls };
33
- const resolved = cleanOpt === true ? CLEAN_ALL : cleanOpt;
34
- return {
35
- cleanUrls: cleanUrls || resolved.urls === true,
36
- clean: resolved
37
- };
32
+ return `mdream has no \`${key}\` option. Valid options: ${VALID_OPTIONS}.`;
33
+ }
34
+ function assertKnownOptions(options) {
35
+ for (const key in options) {
36
+ switch (key) {
37
+ case "origin":
38
+ case "clean":
39
+ case "minimal":
40
+ case "frontmatter":
41
+ case "isolateMain":
42
+ case "tailwind":
43
+ case "filter":
44
+ case "extraction":
45
+ case "tagOverrides":
46
+ case "wrapWidth":
47
+ case "format": continue;
48
+ }
49
+ const value = options[key];
50
+ if (value !== void 0) throw new TypeError(unknownOptionMessage(key, value));
51
+ }
52
+ }
53
+ function resolveClean(clean, minimal) {
54
+ if (clean === void 0) return minimal ? CLEAN_ALL : void 0;
55
+ if (!clean) return void 0;
56
+ return clean === true ? CLEAN_ALL : clean;
38
57
  }
39
58
  function resolveFrontmatter(opt) {
40
59
  if (typeof opt === "function") return {
@@ -51,23 +70,21 @@ function resolveFrontmatter(opt) {
51
70
  return { config: {} };
52
71
  }
53
72
  function resolveOptions(options) {
54
- if (Array.isArray(options.plugins)) throw new TypeError("Custom hook plugins require @mdream/js. Pass declarative config (e.g. { frontmatter: true }) to the Rust engine, or import { htmlToMarkdown } from '@mdream/js' for hook-based plugins. See https://mdream.dev/v1-migration#custom-plugins");
73
+ assertKnownOptions(options);
55
74
  const minimal = options.minimal === true;
56
- const plugins = options.plugins ? { ...options.plugins } : {};
75
+ const plugins = {};
57
76
  let frontmatterCallback;
58
- const frontmatterDisabled = options.frontmatter === false;
59
- if (minimal ? !frontmatterDisabled : !!options.frontmatter) {
77
+ if (minimal ? options.frontmatter !== false : options.frontmatter) {
60
78
  const fm = resolveFrontmatter(options.frontmatter);
61
79
  plugins.frontmatter = fm.config;
62
80
  frontmatterCallback = fm.callback;
63
- } else if (frontmatterDisabled) delete plugins.frontmatter;
64
- const isolateMainDisabled = options.isolateMain === false;
65
- if (minimal ? !isolateMainDisabled : options.isolateMain) plugins.isolateMain = true;
66
- else if (isolateMainDisabled) delete plugins.isolateMain;
67
- const tailwindDisabled = options.tailwind === false;
68
- if (minimal ? !tailwindDisabled : options.tailwind) plugins.tailwind = true;
69
- else if (tailwindDisabled) delete plugins.tailwind;
70
- if (minimal) plugins.filter = options.filter || MINIMAL_FILTER_DEFAULT;
81
+ }
82
+ if (minimal ? options.isolateMain !== false : options.isolateMain) plugins.isolateMain = true;
83
+ if (minimal ? options.tailwind !== false : options.tailwind) plugins.tailwind = true;
84
+ if (minimal && options.filter !== false) plugins.filter = {
85
+ ...options.filter,
86
+ exclude: [...MINIMAL_FILTER_EXCLUDE, ...options.filter?.exclude ?? []]
87
+ };
71
88
  else if (options.filter) plugins.filter = options.filter;
72
89
  const extraction = options.extraction;
73
90
  let extractionHandlers;
@@ -84,12 +101,10 @@ function resolveOptions(options) {
84
101
  }
85
102
  plugins.tagOverrides = overrides;
86
103
  }
87
- const { cleanUrls, clean } = resolveCleanConfig(options, minimal);
88
104
  return {
89
105
  napiOpts: {
90
106
  origin: options.origin,
91
- cleanUrls,
92
- clean,
107
+ clean: resolveClean(options.clean, minimal),
93
108
  plugins,
94
109
  wrapWidth: options.wrapWidth,
95
110
  format: options.format
@@ -98,36 +113,82 @@ function resolveOptions(options) {
98
113
  frontmatterCallback
99
114
  };
100
115
  }
101
- function htmlToMarkdown(html, options = {}) {
102
- const { napiOpts, extractionHandlers, frontmatterCallback } = resolveOptions(options);
103
- const napiResult = htmlToMarkdown$1(html, napiOpts);
104
- if (napiResult.frontmatter && frontmatterCallback) frontmatterCallback(napiResult.frontmatter);
105
- if (napiResult.extracted?.length && extractionHandlers) for (const el of napiResult.extracted) extractionHandlers[el.selector]?.(el);
106
- return napiResult.markdown;
116
+ function deliverPluginData(data, { frontmatterCallback, extractionHandlers }) {
117
+ if (data.frontmatter && frontmatterCallback) frontmatterCallback(data.frontmatter);
118
+ if (data.extracted?.length && extractionHandlers) for (const element of data.extracted) extractionHandlers[element.selector]?.(element);
107
119
  }
108
- async function* streamHtmlToMarkdown(htmlStream, options = {}) {
109
- if (!htmlStream) throw new Error("Invalid HTML stream provided");
110
- const { napiOpts } = resolveOptions(options);
111
- const stream = new MarkdownStream(napiOpts);
120
+ function hasCallbacks({ frontmatterCallback, extractionHandlers }) {
121
+ return !!frontmatterCallback || !!extractionHandlers;
122
+ }
123
+ function convertResult(convert, html, options = {}) {
124
+ const resolved = resolveOptions(options);
125
+ const result = convert(html, resolved.napiOpts);
126
+ deliverPluginData(result, resolved);
127
+ return result;
128
+ }
129
+ async function* pumpStream(stream, htmlStream, callbacks, { mapError = (error) => error } = {}) {
112
130
  const reader = htmlStream.getReader();
113
- const decoder = new TextDecoder();
131
+ const decoder = stream.processChunkBytes ? void 0 : new TextDecoder();
114
132
  try {
115
133
  while (true) {
116
134
  const { done, value } = await reader.read();
117
135
  if (done) break;
118
- const chunk = typeof value === "string" ? decoder.decode() + value : decoder.decode(value, { stream: true });
119
- const processed = stream.processChunk(chunk);
136
+ let processed;
137
+ if (typeof value === "string") processed = stream.processChunk(decoder ? decoder.decode() + value : value);
138
+ else processed = decoder ? stream.processChunk(decoder.decode(value, { stream: true })) : stream.processChunkBytes(value);
120
139
  if (processed) yield processed;
121
140
  }
122
- const decoderTail = decoder.decode();
141
+ const decoderTail = decoder?.decode();
123
142
  if (decoderTail) {
124
143
  const processed = stream.processChunk(decoderTail);
125
144
  if (processed) yield processed;
126
145
  }
127
146
  const final_ = stream.finish();
147
+ if (hasCallbacks(callbacks)) deliverPluginData(stream.takeData(), callbacks);
128
148
  if (final_) yield final_;
149
+ } catch (error) {
150
+ throw mapError(error);
129
151
  } finally {
130
152
  reader.releaseLock();
131
153
  }
132
154
  }
155
+ function createSurrogateCarry() {
156
+ let held = "";
157
+ return {
158
+ take(chunk) {
159
+ if (held) {
160
+ chunk = held + chunk;
161
+ held = "";
162
+ }
163
+ const last = chunk.charCodeAt(chunk.length - 1);
164
+ if (last >= 55296 && last <= 56319) {
165
+ held = chunk.slice(-1);
166
+ return chunk.slice(0, -1);
167
+ }
168
+ return chunk;
169
+ },
170
+ flush() {
171
+ const value = held;
172
+ held = "";
173
+ return value;
174
+ }
175
+ };
176
+ }
177
+ function htmlToMarkdown(html, options = {}) {
178
+ return convertResult(htmlToMarkdown$1, html, options).markdown;
179
+ }
180
+ async function* streamHtmlToMarkdown(htmlStream, options = {}) {
181
+ if (!htmlStream) throw new Error("Invalid HTML stream provided");
182
+ const resolved = resolveOptions(options);
183
+ const carry = createSurrogateCarry();
184
+ const stream = new MarkdownStream(resolved.napiOpts);
185
+ yield* pumpStream({
186
+ processChunk: (chunk) => stream.processChunk(carry.take(chunk)),
187
+ finish: () => {
188
+ const held = carry.flush();
189
+ return held ? stream.processChunk(held) + stream.finish() : stream.finish();
190
+ },
191
+ takeData: () => stream.takeData()
192
+ }, htmlStream, resolved);
193
+ }
133
194
  export { htmlToMarkdown, streamHtmlToMarkdown };
@@ -1,3 +1,5 @@
1
+ import mdream_edge_default, { InitInput, InitOutput, MarkdownStream as MarkdownStream$1, SyncInitInput, initSync } from "../wasm/mdream_edge.js";
2
+ import { MdreamNapiResult } from "../napi/index.js";
1
3
  interface CleanOptions {
2
4
  /** Strip tracking query parameters (utm_*, fbclid, gclid, etc.) from URLs */
3
5
  urls?: boolean;
@@ -5,8 +7,6 @@ interface CleanOptions {
5
7
  fragments?: boolean;
6
8
  /** Strip links with meaningless hrefs (#, javascript:void(0)) → plain text */
7
9
  emptyLinks?: boolean;
8
- /** Collapse 3+ consecutive blank lines to 2 */
9
- blankLines?: boolean;
10
10
  /** Strip links where text equals URL: [https://x.com](https://x.com) → https://x.com */
11
11
  redundantLinks?: boolean;
12
12
  /** Strip self-referencing heading anchors: ## [Title](#title) → ## Title */
@@ -42,8 +42,8 @@ interface MdreamOptions {
42
42
  origin?: string;
43
43
  /**
44
44
  * Clean up the markdown output. Pass `true` for all cleanup or an object
45
- * to enable specific features. `clean.urls` is handled during conversion;
46
- * other options are post-processing steps (sync API only).
45
+ * to enable specific features. Both `htmlToMarkdown` and
46
+ * `streamHtmlToMarkdown` apply it.
47
47
  */
48
48
  clean?: boolean | CleanOptions;
49
49
  /** Enable minimal preset (frontmatter, isolateMain, tailwind, filter). Default: false */
@@ -59,8 +59,12 @@ interface MdreamOptions {
59
59
  isolateMain?: boolean;
60
60
  /** Convert Tailwind utility classes. Default when minimal: true */
61
61
  tailwind?: boolean;
62
- /** Filter elements. Default when minimal: excludes form, nav, footer, etc. */
63
- filter?: {
62
+ /**
63
+ * Filter elements by CSS selector. `minimal` excludes form, nav, footer, and
64
+ * similar; a filter passed with `minimal` adds to those excludes. `false`
65
+ * turns filtering off, including the `minimal` one.
66
+ */
67
+ filter?: false | {
64
68
  include?: string[];
65
69
  exclude?: string[];
66
70
  processChildren?: boolean;
@@ -81,17 +85,13 @@ interface MdreamOptions {
81
85
  */
82
86
  format?: 'markdown' | 'text' | 'html';
83
87
  }
84
- /**
85
- * Initialize the mdream web worker. Must be called before htmlToMarkdown.
86
- * @param wasmUrl - URL to the mdream_edge_bg.wasm file
87
- */
88
- export declare function initWorker(wasmUrl: string): Promise<void>;
89
- /**
90
- * Convert HTML to markdown using the web worker.
91
- * Call initWorker() first.
92
- */
93
- export declare function htmlToMarkdown(html: string, options?: Partial<MdreamOptions>): Promise<string>;
94
- /**
95
- * Terminate the web worker and free resources.
96
- */
97
- export declare function terminateWorker(): void;
88
+ export declare function htmlToMarkdownResult(html: string, options?: Partial<MdreamOptions>): MdreamNapiResult;
89
+ export declare function htmlToMarkdown(html: string, options?: Partial<MdreamOptions>): string;
90
+ export declare function htmlToMarkdownBytes(html: Uint8Array, options?: Partial<MdreamOptions>): string;
91
+ /** Streaming converter. Runs the frontmatter and extraction callbacks in `finish()`. */
92
+ export declare class MarkdownStream extends MarkdownStream$1 {
93
+ private _callbacks;
94
+ constructor(options?: Partial<MdreamOptions>);
95
+ finish(): string;
96
+ }
97
+ export { type InitInput, type InitOutput, type SyncInitInput, mdream_edge_default as default, initSync };
package/dist/wasm.mjs ADDED
@@ -0,0 +1,150 @@
1
+ import mdream_edge_default, { MarkdownStream as MarkdownStream$1, htmlToMarkdownBytes as htmlToMarkdownBytes$1, htmlToMarkdownResult as htmlToMarkdownResult$1, initSync } from "../wasm/mdream_edge.js";
2
+ const MINIMAL_FILTER_EXCLUDE = [
3
+ "form",
4
+ "fieldset",
5
+ "object",
6
+ "embed",
7
+ "footer",
8
+ "aside",
9
+ "iframe",
10
+ "input",
11
+ "textarea",
12
+ "select",
13
+ "button",
14
+ "nav"
15
+ ];
16
+ const CLEAN_ALL = {
17
+ urls: true,
18
+ fragments: true,
19
+ emptyLinks: true,
20
+ redundantLinks: true,
21
+ selfLinkHeadings: true,
22
+ emptyImages: true,
23
+ emptyLinkText: true
24
+ };
25
+ const VALID_OPTIONS = "origin, clean, minimal, frontmatter, isolateMain, tailwind, filter, extraction, tagOverrides, wrapWidth, format";
26
+ function unknownOptionMessage(key, value) {
27
+ switch (key) {
28
+ case "preset": return "mdream has no `preset` option. Pass { minimal: true }.";
29
+ case "cleanUrls": return "mdream has no `cleanUrls` option. Pass { clean: { urls: true } }.";
30
+ case "plugins": return Array.isArray(value) ? "Custom hook plugins require @mdream/js. Pass declarative config (e.g. { frontmatter: true }) to the Rust engine, or import { htmlToMarkdown } from '@mdream/js' for hook-based plugins. See https://github.com/harlan-zw/mdream/tree/main/packages/js#migrating-from-v1" : "mdream takes plugin options at the top level, such as { frontmatter: true }.";
31
+ }
32
+ return `mdream has no \`${key}\` option. Valid options: ${VALID_OPTIONS}.`;
33
+ }
34
+ function assertKnownOptions(options) {
35
+ for (const key in options) {
36
+ switch (key) {
37
+ case "origin":
38
+ case "clean":
39
+ case "minimal":
40
+ case "frontmatter":
41
+ case "isolateMain":
42
+ case "tailwind":
43
+ case "filter":
44
+ case "extraction":
45
+ case "tagOverrides":
46
+ case "wrapWidth":
47
+ case "format": continue;
48
+ }
49
+ const value = options[key];
50
+ if (value !== void 0) throw new TypeError(unknownOptionMessage(key, value));
51
+ }
52
+ }
53
+ function resolveClean(clean, minimal) {
54
+ if (clean === void 0) return minimal ? CLEAN_ALL : void 0;
55
+ if (!clean) return void 0;
56
+ return clean === true ? CLEAN_ALL : clean;
57
+ }
58
+ function resolveFrontmatter(opt) {
59
+ if (typeof opt === "function") return {
60
+ config: {},
61
+ callback: opt
62
+ };
63
+ if (opt && typeof opt === "object") {
64
+ const { onExtract, ...config } = opt;
65
+ return {
66
+ config,
67
+ callback: onExtract
68
+ };
69
+ }
70
+ return { config: {} };
71
+ }
72
+ function resolveOptions(options) {
73
+ assertKnownOptions(options);
74
+ const minimal = options.minimal === true;
75
+ const plugins = {};
76
+ let frontmatterCallback;
77
+ if (minimal ? options.frontmatter !== false : options.frontmatter) {
78
+ const fm = resolveFrontmatter(options.frontmatter);
79
+ plugins.frontmatter = fm.config;
80
+ frontmatterCallback = fm.callback;
81
+ }
82
+ if (minimal ? options.isolateMain !== false : options.isolateMain) plugins.isolateMain = true;
83
+ if (minimal ? options.tailwind !== false : options.tailwind) plugins.tailwind = true;
84
+ if (minimal && options.filter !== false) plugins.filter = {
85
+ ...options.filter,
86
+ exclude: [...MINIMAL_FILTER_EXCLUDE, ...options.filter?.exclude ?? []]
87
+ };
88
+ else if (options.filter) plugins.filter = options.filter;
89
+ const extraction = options.extraction;
90
+ let extractionHandlers;
91
+ if (extraction) {
92
+ plugins.extraction = { selectors: Object.keys(extraction) };
93
+ extractionHandlers = extraction;
94
+ }
95
+ const tagOverrides = options.tagOverrides;
96
+ if (tagOverrides) {
97
+ const overrides = {};
98
+ for (const tag in tagOverrides) {
99
+ const value = tagOverrides[tag];
100
+ if (value) overrides[tag] = typeof value === "string" ? { alias: value } : value;
101
+ }
102
+ plugins.tagOverrides = overrides;
103
+ }
104
+ return {
105
+ napiOpts: {
106
+ origin: options.origin,
107
+ clean: resolveClean(options.clean, minimal),
108
+ plugins,
109
+ wrapWidth: options.wrapWidth,
110
+ format: options.format
111
+ },
112
+ extractionHandlers,
113
+ frontmatterCallback
114
+ };
115
+ }
116
+ function deliverPluginData(data, { frontmatterCallback, extractionHandlers }) {
117
+ if (data.frontmatter && frontmatterCallback) frontmatterCallback(data.frontmatter);
118
+ if (data.extracted?.length && extractionHandlers) for (const element of data.extracted) extractionHandlers[element.selector]?.(element);
119
+ }
120
+ function convertResult(convert, html, options = {}) {
121
+ const resolved = resolveOptions(options);
122
+ const result = convert(html, resolved.napiOpts);
123
+ deliverPluginData(result, resolved);
124
+ return result;
125
+ }
126
+ function htmlToMarkdownResult(html, options = {}) {
127
+ return convertResult(htmlToMarkdownResult$1, html, options);
128
+ }
129
+ function htmlToMarkdown(html, options = {}) {
130
+ return htmlToMarkdownResult(html, options).markdown || "";
131
+ }
132
+ function htmlToMarkdownBytes(html, options = {}) {
133
+ const resolved = resolveOptions(options);
134
+ if (resolved.frontmatterCallback || resolved.extractionHandlers) return htmlToMarkdown(new TextDecoder().decode(html), options);
135
+ return htmlToMarkdownBytes$1(html, resolved.napiOpts);
136
+ }
137
+ var MarkdownStream = class extends MarkdownStream$1 {
138
+ _callbacks;
139
+ constructor(options = {}) {
140
+ const resolved = resolveOptions(options);
141
+ super(resolved.napiOpts);
142
+ this._callbacks = resolved;
143
+ }
144
+ finish() {
145
+ const markdown = super.finish();
146
+ deliverPluginData(this.takeData(), this._callbacks);
147
+ return markdown;
148
+ }
149
+ };
150
+ export { MarkdownStream, mdream_edge_default as default, htmlToMarkdown, htmlToMarkdownBytes, htmlToMarkdownResult, initSync };
package/napi/index.d.mts CHANGED
@@ -1,28 +1,29 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
+
3
12
  export declare class MarkdownStream {
4
13
  constructor(options?: HtmlToMarkdownOptions | undefined | null)
5
14
  processChunk(chunk: string): string
6
- processChunkBytes(chunk: Uint8Array): string
7
15
  finish(): string
8
- }
9
-
10
- export interface ChunkLocNapi {
11
- from: number
12
- to: number
13
- }
14
-
15
- export interface ChunkMetadataNapi {
16
- headers?: Record<string, string>
17
- code?: string
18
- loc?: ChunkLocNapi
16
+ /**
17
+ * Frontmatter and extracted elements collected so far. Call after
18
+ * `finish()` for the complete data. Extracted elements drain on each call.
19
+ */
20
+ takeData(): MdreamStreamData
19
21
  }
20
22
 
21
23
  export interface CleanOptionsNapi {
22
24
  urls?: boolean
23
25
  fragments?: boolean
24
26
  emptyLinks?: boolean
25
- blankLines?: boolean
26
27
  redundantLinks?: boolean
27
28
  selfLinkHeadings?: boolean
28
29
  emptyImages?: boolean
@@ -53,30 +54,26 @@ export interface FrontmatterOptions {
53
54
 
54
55
  export declare function htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions | undefined | null): MdreamNapiResult
55
56
 
56
- export declare function htmlToMarkdownBytes(html: Uint8Array, options?: HtmlToMarkdownOptions | undefined | null): MdreamNapiResult
57
-
58
- export declare function htmlToMarkdownChunks(html: string, options?: HtmlToMarkdownOptions | undefined | null, splitterOptions?: SplitterOptionsNapi | undefined | null): Array<MarkdownChunkNapi>
59
-
60
57
  export interface HtmlToMarkdownOptions {
61
58
  origin?: string
62
- cleanUrls?: boolean
63
59
  clean?: CleanOptionsNapi
64
60
  plugins?: PluginOptions
65
61
  wrapWidth?: number
66
62
  format?: "markdown" | "text" | "html"
67
63
  }
68
64
 
69
- export interface MarkdownChunkNapi {
70
- content: string
71
- metadata: ChunkMetadataNapi
72
- }
73
-
74
65
  export interface MdreamNapiResult {
75
66
  markdown: string
76
67
  extracted?: Array<ExtractedElementNapi>
77
68
  frontmatter?: Record<string, string>
78
69
  }
79
70
 
71
+ /** Plugin data a stream collected: frontmatter and extracted elements. */
72
+ export interface MdreamStreamData {
73
+ extracted?: Array<ExtractedElementNapi>
74
+ frontmatter?: Record<string, string>
75
+ }
76
+
80
77
  export interface PluginOptions {
81
78
  filter?: FilterOptions
82
79
  isolateMain?: boolean
@@ -86,16 +83,6 @@ export interface PluginOptions {
86
83
  tagOverrides?: Record<string, TagOverrideNapi>
87
84
  }
88
85
 
89
- export declare function splitMarkdown(markdown: string, options?: SplitterOptionsNapi | undefined | null): Array<MarkdownChunkNapi>
90
-
91
- export interface SplitterOptionsNapi {
92
- headersToSplitOn?: Array<number>
93
- returnEachLine?: boolean
94
- stripHeaders?: boolean
95
- chunkSize?: number
96
- chunkOverlap?: number
97
- }
98
-
99
86
  export interface TagOverrideNapi {
100
87
  enter?: string
101
88
  exit?: string
package/napi/index.d.ts CHANGED
@@ -1,28 +1,29 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
+
3
12
  export declare class MarkdownStream {
4
13
  constructor(options?: HtmlToMarkdownOptions | undefined | null)
5
14
  processChunk(chunk: string): string
6
- processChunkBytes(chunk: Uint8Array): string
7
15
  finish(): string
8
- }
9
-
10
- export interface ChunkLocNapi {
11
- from: number
12
- to: number
13
- }
14
-
15
- export interface ChunkMetadataNapi {
16
- headers?: Record<string, string>
17
- code?: string
18
- loc?: ChunkLocNapi
16
+ /**
17
+ * Frontmatter and extracted elements collected so far. Call after
18
+ * `finish()` for the complete data. Extracted elements drain on each call.
19
+ */
20
+ takeData(): MdreamStreamData
19
21
  }
20
22
 
21
23
  export interface CleanOptionsNapi {
22
24
  urls?: boolean
23
25
  fragments?: boolean
24
26
  emptyLinks?: boolean
25
- blankLines?: boolean
26
27
  redundantLinks?: boolean
27
28
  selfLinkHeadings?: boolean
28
29
  emptyImages?: boolean
@@ -53,30 +54,26 @@ export interface FrontmatterOptions {
53
54
 
54
55
  export declare function htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions | undefined | null): MdreamNapiResult
55
56
 
56
- export declare function htmlToMarkdownBytes(html: Uint8Array, options?: HtmlToMarkdownOptions | undefined | null): MdreamNapiResult
57
-
58
- export declare function htmlToMarkdownChunks(html: string, options?: HtmlToMarkdownOptions | undefined | null, splitterOptions?: SplitterOptionsNapi | undefined | null): Array<MarkdownChunkNapi>
59
-
60
57
  export interface HtmlToMarkdownOptions {
61
58
  origin?: string
62
- cleanUrls?: boolean
63
59
  clean?: CleanOptionsNapi
64
60
  plugins?: PluginOptions
65
61
  wrapWidth?: number
66
62
  format?: "markdown" | "text" | "html"
67
63
  }
68
64
 
69
- export interface MarkdownChunkNapi {
70
- content: string
71
- metadata: ChunkMetadataNapi
72
- }
73
-
74
65
  export interface MdreamNapiResult {
75
66
  markdown: string
76
67
  extracted?: Array<ExtractedElementNapi>
77
68
  frontmatter?: Record<string, string>
78
69
  }
79
70
 
71
+ /** Plugin data a stream collected: frontmatter and extracted elements. */
72
+ export interface MdreamStreamData {
73
+ extracted?: Array<ExtractedElementNapi>
74
+ frontmatter?: Record<string, string>
75
+ }
76
+
80
77
  export interface PluginOptions {
81
78
  filter?: FilterOptions
82
79
  isolateMain?: boolean
@@ -86,16 +83,6 @@ export interface PluginOptions {
86
83
  tagOverrides?: Record<string, TagOverrideNapi>
87
84
  }
88
85
 
89
- export declare function splitMarkdown(markdown: string, options?: SplitterOptionsNapi | undefined | null): Array<MarkdownChunkNapi>
90
-
91
- export interface SplitterOptionsNapi {
92
- headersToSplitOn?: Array<number>
93
- returnEachLine?: boolean
94
- stripHeaders?: boolean
95
- chunkSize?: number
96
- chunkOverlap?: number
97
- }
98
-
99
86
  export interface TagOverrideNapi {
100
87
  enter?: string
101
88
  exit?: string