@mdream/js 2.0.0-beta.1 → 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/README.md +402 -126
- package/dist/_chunks/clean.mjs +526 -0
- package/dist/_chunks/const.mjs +3 -7
- package/dist/_chunks/extraction.d.mts +14 -0
- package/dist/_chunks/html.mjs +260 -0
- package/dist/_chunks/markdown-processor.mjs +1077 -828
- package/dist/_chunks/minimal.mjs +29 -0
- package/dist/_chunks/output-runner.mjs +54 -0
- package/dist/_chunks/parse.mjs +133 -1500
- package/dist/_chunks/plugin.mjs +14 -0
- package/dist/_chunks/src.mjs +291 -0
- package/dist/_chunks/tag-overrides.mjs +138 -0
- package/dist/_chunks/{plugins.mjs → tailwind.mjs} +145 -292
- package/dist/_chunks/text.mjs +583 -0
- package/dist/_chunks/types.d.mts +136 -126
- package/dist/_chunks/url.mjs +82 -0
- package/dist/_chunks/utils.mjs +659 -0
- package/dist/clean.d.mts +10 -0
- package/dist/clean.mjs +2 -0
- package/dist/cli.mjs +47 -8
- package/dist/html.d.mts +6 -0
- package/dist/html.mjs +2 -0
- package/dist/index.d.mts +5 -4
- package/dist/index.mjs +4 -58
- package/dist/parse.d.mts +15 -10
- package/dist/plugins.d.mts +13 -28
- package/dist/plugins.mjs +52 -2
- package/dist/preset/minimal.d.mts +14 -2
- package/dist/preset/minimal.mjs +1 -32
- package/dist/splitter.d.mts +12 -4
- package/dist/splitter.mjs +355 -113
- package/dist/text.d.mts +6 -0
- package/dist/text.mjs +2 -0
- package/package.json +33 -7
- package/dist/_chunks/index.d.mts +0 -9
- package/dist/_chunks/minimal.d.mts +0 -6
- package/dist/_chunks/resolve-plugins.mjs +0 -44
- package/dist/_chunks/stream.mjs +0 -37
- package/dist/core.d.mts +0 -15
- package/dist/core.mjs +0 -28
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { clean } from "./clean.mjs";
|
|
2
|
+
import { filterPlugin, frontmatterPlugin, isolateMainPlugin, tailwindPlugin } from "./tailwind.mjs";
|
|
3
|
+
function withMinimalPreset(options = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...options,
|
|
6
|
+
clean: options.clean === false ? void 0 : options.clean ?? clean(),
|
|
7
|
+
plugins: [
|
|
8
|
+
frontmatterPlugin(),
|
|
9
|
+
isolateMainPlugin(),
|
|
10
|
+
tailwindPlugin(),
|
|
11
|
+
filterPlugin({ exclude: [
|
|
12
|
+
"form",
|
|
13
|
+
"fieldset",
|
|
14
|
+
"object",
|
|
15
|
+
"embed",
|
|
16
|
+
"footer",
|
|
17
|
+
"aside",
|
|
18
|
+
"iframe",
|
|
19
|
+
"input",
|
|
20
|
+
"textarea",
|
|
21
|
+
"select",
|
|
22
|
+
"button",
|
|
23
|
+
"nav"
|
|
24
|
+
] }),
|
|
25
|
+
...options.plugins ?? []
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export { withMinimalPreset };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { endPlugins, processPluginsForEvent } from "./tag-overrides.mjs";
|
|
2
|
+
import { finalizeParse, parseHtmlStream } from "./parse.mjs";
|
|
3
|
+
function createParseState(processor, options) {
|
|
4
|
+
return {
|
|
5
|
+
depthMap: processor.state.depthMap,
|
|
6
|
+
depth: 0,
|
|
7
|
+
resolvedPlugins: options.plugins,
|
|
8
|
+
tagHandlers: options.tagHandlers,
|
|
9
|
+
tagOverrideHandlers: options.tagOverrideHandlers,
|
|
10
|
+
plainText: options.plainText
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function createEventHandler(processor, plugins) {
|
|
14
|
+
return plugins.length ? (event) => processPluginsForEvent(event, plugins, processor.state, processor.processEvent) : processor.processEvent;
|
|
15
|
+
}
|
|
16
|
+
function processHtmlOutput(html, processor, options) {
|
|
17
|
+
const plugins = options.plugins ?? [];
|
|
18
|
+
const parseState = createParseState(processor, options);
|
|
19
|
+
const handleEvent = createEventHandler(processor, plugins);
|
|
20
|
+
const leftover = parseHtmlStream(html, parseState, handleEvent);
|
|
21
|
+
finalizeParse(leftover, parseState, handleEvent);
|
|
22
|
+
endPlugins(plugins, processor.state);
|
|
23
|
+
return processor.takeOutput(true);
|
|
24
|
+
}
|
|
25
|
+
async function* streamHtmlOutput(htmlStream, processor, options) {
|
|
26
|
+
if (!htmlStream) throw new Error("Invalid HTML stream provided");
|
|
27
|
+
const plugins = options.plugins ?? [];
|
|
28
|
+
const parseState = createParseState(processor, options);
|
|
29
|
+
parseState.discardExcludedText = plugins.length === 0;
|
|
30
|
+
const handleEvent = createEventHandler(processor, plugins);
|
|
31
|
+
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
32
|
+
const reader = htmlStream.getReader();
|
|
33
|
+
let remainingHtml = "";
|
|
34
|
+
try {
|
|
35
|
+
while (true) {
|
|
36
|
+
const { done, value } = await reader.read();
|
|
37
|
+
if (done) break;
|
|
38
|
+
if (value === "") continue;
|
|
39
|
+
const decoded = typeof value === "string" ? decoder.decode() + value : decoder.decode(value, { stream: true });
|
|
40
|
+
remainingHtml = parseHtmlStream(`${remainingHtml}${decoded}`, parseState, handleEvent);
|
|
41
|
+
const chunk = processor.takeOutput(false);
|
|
42
|
+
if (chunk) yield chunk;
|
|
43
|
+
}
|
|
44
|
+
const finalHtml = remainingHtml + decoder.decode();
|
|
45
|
+
const leftover = finalHtml ? parseHtmlStream(finalHtml, parseState, handleEvent) : "";
|
|
46
|
+
finalizeParse(leftover, parseState, handleEvent);
|
|
47
|
+
endPlugins(plugins, processor.state);
|
|
48
|
+
const finalChunk = processor.takeOutput(true);
|
|
49
|
+
if (finalChunk) yield finalChunk;
|
|
50
|
+
} finally {
|
|
51
|
+
reader.releaseLock();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export { processHtmlOutput, streamHtmlOutput };
|