mdream 1.0.0-beta.9 → 1.0.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/LICENSE.md +9 -0
- package/README.md +741 -206
- package/dist/browser.d.mts +2 -1
- package/dist/browser.mjs +22 -2
- package/dist/edge.d.mts +2 -1
- package/dist/edge.mjs +20 -1
- package/dist/iife.js +368 -1
- package/package.json +15 -15
- package/wasm/mdream_edge_bg.wasm +0 -0
- package/wasm/package.json +1 -1
- package/dist/THIRD-PARTY-LICENSES.md +0 -10
package/dist/browser.d.mts
CHANGED
|
@@ -9,5 +9,6 @@ declare class MarkdownStream {
|
|
|
9
9
|
processChunk(chunk: string): string;
|
|
10
10
|
finish(): string;
|
|
11
11
|
}
|
|
12
|
+
declare function streamHtmlToMarkdown(htmlStream: ReadableStream<Uint8Array | string> | null, options?: HtmlToMarkdownOptions): AsyncIterable<string>;
|
|
12
13
|
//#endregion
|
|
13
|
-
export { MarkdownStream, createMarkdownStream, htmlToMarkdown };
|
|
14
|
+
export { MarkdownStream, createMarkdownStream, htmlToMarkdown, streamHtmlToMarkdown };
|
package/dist/browser.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import init, { MarkdownStream as MarkdownStream$1, htmlToMarkdownResult } from "../wasm/mdream_edge.js";
|
|
2
2
|
//#region src/browser.ts
|
|
3
|
-
let _initPromise
|
|
3
|
+
let _initPromise;
|
|
4
4
|
function ensureInit() {
|
|
5
5
|
if (!_initPromise) _initPromise = init();
|
|
6
6
|
return _initPromise;
|
|
@@ -26,5 +26,25 @@ var MarkdownStream = class {
|
|
|
26
26
|
return this._inner.finish();
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
async function* streamHtmlToMarkdown(htmlStream, options) {
|
|
30
|
+
if (!htmlStream) throw new Error("Invalid HTML stream provided");
|
|
31
|
+
await ensureInit();
|
|
32
|
+
const stream = new MarkdownStream$1(options || {});
|
|
33
|
+
const reader = htmlStream.getReader();
|
|
34
|
+
const decoder = new TextDecoder();
|
|
35
|
+
try {
|
|
36
|
+
while (true) {
|
|
37
|
+
const { done, value } = await reader.read();
|
|
38
|
+
if (done) break;
|
|
39
|
+
const chunk = typeof value === "string" ? value : decoder.decode(value);
|
|
40
|
+
const processed = stream.processChunk(chunk);
|
|
41
|
+
if (processed) yield processed;
|
|
42
|
+
}
|
|
43
|
+
const final_ = stream.finish();
|
|
44
|
+
if (final_) yield final_;
|
|
45
|
+
} finally {
|
|
46
|
+
reader.releaseLock();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
29
49
|
//#endregion
|
|
30
|
-
export { MarkdownStream, createMarkdownStream, htmlToMarkdown };
|
|
50
|
+
export { MarkdownStream, createMarkdownStream, htmlToMarkdown, streamHtmlToMarkdown };
|
package/dist/edge.d.mts
CHANGED
|
@@ -8,5 +8,6 @@ declare class MarkdownStream {
|
|
|
8
8
|
processChunk(chunk: string): string;
|
|
9
9
|
finish(): string;
|
|
10
10
|
}
|
|
11
|
+
declare function streamHtmlToMarkdown(htmlStream: ReadableStream<Uint8Array | string> | null, options?: HtmlToMarkdownOptions): AsyncIterable<string>;
|
|
11
12
|
//#endregion
|
|
12
|
-
export { MarkdownStream, htmlToMarkdown };
|
|
13
|
+
export { MarkdownStream, htmlToMarkdown, streamHtmlToMarkdown };
|
package/dist/edge.mjs
CHANGED
|
@@ -17,5 +17,24 @@ var MarkdownStream = class {
|
|
|
17
17
|
return this._inner.finish();
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
+
async function* streamHtmlToMarkdown(htmlStream, options) {
|
|
21
|
+
if (!htmlStream) throw new Error("Invalid HTML stream provided");
|
|
22
|
+
const stream = new MarkdownStream$1(options || {});
|
|
23
|
+
const reader = htmlStream.getReader();
|
|
24
|
+
const decoder = new TextDecoder();
|
|
25
|
+
try {
|
|
26
|
+
while (true) {
|
|
27
|
+
const { done, value } = await reader.read();
|
|
28
|
+
if (done) break;
|
|
29
|
+
const chunk = typeof value === "string" ? value : decoder.decode(value);
|
|
30
|
+
const processed = stream.processChunk(chunk);
|
|
31
|
+
if (processed) yield processed;
|
|
32
|
+
}
|
|
33
|
+
const final_ = stream.finish();
|
|
34
|
+
if (final_) yield final_;
|
|
35
|
+
} finally {
|
|
36
|
+
reader.releaseLock();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
20
39
|
//#endregion
|
|
21
|
-
export { MarkdownStream, htmlToMarkdown };
|
|
40
|
+
export { MarkdownStream, htmlToMarkdown, streamHtmlToMarkdown };
|