@mdream/js 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/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 -827
- package/dist/_chunks/minimal.mjs +29 -0
- package/dist/_chunks/output-runner.mjs +54 -0
- package/dist/_chunks/parse.mjs +136 -1490
- 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 -122
- 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 -34
- 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 -27
- 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
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { streamHtmlToMarkdown } from "./_chunks/src.mjs";
|
|
2
|
+
import { streamHtmlToText } from "./_chunks/text.mjs";
|
|
3
|
+
import { streamHtmlToSafeHtml } from "./_chunks/html.mjs";
|
|
4
|
+
import { withMinimalPreset } from "./_chunks/minimal.mjs";
|
|
3
5
|
import { readFileSync } from "node:fs";
|
|
4
6
|
import { Readable } from "node:stream";
|
|
5
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -14,12 +16,44 @@ async function streamingConvert(options = {}) {
|
|
|
14
16
|
}
|
|
15
17
|
let conversionOptions = {
|
|
16
18
|
origin: options.origin,
|
|
17
|
-
wrapWidth: options.wrapWidth ? Number(options.wrapWidth) || void 0 : void 0
|
|
18
|
-
format
|
|
19
|
+
wrapWidth: options.wrapWidth ? Number(options.wrapWidth) || void 0 : void 0
|
|
19
20
|
};
|
|
20
|
-
if (options.preset
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
if (options.preset !== void 0) {
|
|
22
|
+
if (options.preset !== "minimal") {
|
|
23
|
+
process.stderr.write(`Unknown preset: ${options.preset}. Use --preset minimal.\n`);
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
conversionOptions = withMinimalPreset(conversionOptions);
|
|
28
|
+
}
|
|
29
|
+
const output = (format === "text" ? streamHtmlToText : format === "html" ? streamHtmlToSafeHtml : streamHtmlToMarkdown)(Readable.toWeb(process.stdin), conversionOptions);
|
|
30
|
+
for await (const chunk of output) if (chunk && chunk.length > 0) process.stdout.write(chunk);
|
|
31
|
+
}
|
|
32
|
+
const LEADING_DASHES_RE = /^-+/;
|
|
33
|
+
const KEBAB_RE = /([a-z])-([a-z])/g;
|
|
34
|
+
function camelcase(name) {
|
|
35
|
+
return name.replace(KEBAB_RE, (_, a, b) => a + b.toUpperCase());
|
|
36
|
+
}
|
|
37
|
+
function typedFlag(name, argv) {
|
|
38
|
+
for (const arg of argv) {
|
|
39
|
+
if (arg === "--") break;
|
|
40
|
+
if (arg.charCodeAt(0) !== 45) continue;
|
|
41
|
+
const flag = arg.split("=", 1)[0];
|
|
42
|
+
const bare = flag.replace(LEADING_DASHES_RE, "").split(".", 1)[0];
|
|
43
|
+
if (camelcase(bare) === name || bare.startsWith("no-") && camelcase(bare.slice(3)) === name) return flag;
|
|
44
|
+
}
|
|
45
|
+
return name.length > 1 ? `--${name}` : `-${name}`;
|
|
46
|
+
}
|
|
47
|
+
function usageError(cli, argv) {
|
|
48
|
+
const command = cli.matchedCommand;
|
|
49
|
+
if (!command) return;
|
|
50
|
+
for (const name in cli.options) if (name !== "--" && !command.hasOption(name) && !cli.globalCommand.hasOption(name)) return `Unknown option: ${typedFlag(name, argv)}. Run mdream-js --help to list the options.`;
|
|
51
|
+
for (const option of command.options) {
|
|
52
|
+
const value = cli.options[option.name];
|
|
53
|
+
if (!option.required) continue;
|
|
54
|
+
if (value === false) return `Unknown option: ${typedFlag(option.name, argv)}. Run mdream-js --help to list the options.`;
|
|
55
|
+
if (value === true || value === "") return `The ${typedFlag(option.name, argv)} option needs a value.`;
|
|
56
|
+
}
|
|
23
57
|
}
|
|
24
58
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
25
59
|
const packageJsonPath = join(__dirname, "..", "package.json");
|
|
@@ -28,5 +62,10 @@ const cli = cac();
|
|
|
28
62
|
cli.command("[options]", "Convert HTML from stdin to Markdown on stdout (JS engine)").option("--origin <url>", "Origin URL for resolving relative image paths").option("--preset <preset>", "Conversion presets: minimal").option("--wrap-width <n>", "Hard-wrap prose at <n> characters on word boundaries").option("--format <format>", "Output format: markdown, text, html").option("--text", "Alias for --format text").action(async (_, opts) => {
|
|
29
63
|
await streamingConvert(opts);
|
|
30
64
|
});
|
|
31
|
-
cli.help().version(packageJson.version).parse();
|
|
65
|
+
cli.help().version(packageJson.version).parse(process.argv, { run: false });
|
|
66
|
+
const error = usageError(cli, process.argv.slice(2));
|
|
67
|
+
if (error) {
|
|
68
|
+
process.stderr.write(`${error}\n`);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
} else await cli.runMatchedCommand();
|
|
32
71
|
export {};
|
package/dist/html.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MdreamOptions } from "./_chunks/types.mjs";
|
|
2
|
+
/** Convert HTML to allowlisted semantic HTML. */
|
|
3
|
+
export declare function htmlToSafeHtml(html: string, options?: Partial<MdreamOptions>): string;
|
|
4
|
+
/** Stream HTML as allowlisted semantic HTML. */
|
|
5
|
+
export declare function streamHtmlToSafeHtml(htmlStream: ReadableStream<Uint8Array | string> | null, options?: Partial<MdreamOptions>): AsyncIterable<string>;
|
|
6
|
+
export type { MdreamOptions };
|
package/dist/html.mjs
ADDED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
import { CleanOptions, Cleaner, ELEMENT_NODE, ElementNode, EngineOptions, MarkdownChunk, MdreamOptions, Node, NodeEvent, NodeEventEnter, NodeEventExit, OutputFormat, Plugin, PluginContext, PluginSetup, PluginState, SplitterOptions, TEXT_NODE, TagOverride, TextNode, TransformPlugin } from "./_chunks/types.mjs";
|
|
2
|
+
import { ExtractedElement, createPlugin } from "./_chunks/extraction.mjs";
|
|
3
|
+
export declare function htmlToMarkdown(html: string, options?: Partial<MdreamOptions>): string;
|
|
4
|
+
export declare function streamHtmlToMarkdown(htmlStream: ReadableStream<Uint8Array | string> | null, options?: Partial<MdreamOptions>): AsyncIterable<string>;
|
|
5
|
+
export { type CleanOptions, type Cleaner, ELEMENT_NODE, type ElementNode, type EngineOptions, type ExtractedElement, type MarkdownChunk, type MdreamOptions, type Node, type NodeEvent, NodeEventEnter, NodeEventExit, type OutputFormat, type Plugin, type PluginContext, type PluginSetup, type PluginState, type SplitterOptions, TEXT_NODE, type TagOverride, type TextNode, type TransformPlugin, createPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,34 +1,4 @@
|
|
|
1
|
-
import { ELEMENT_NODE, NodeEventEnter, NodeEventExit,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { resolvePlugins } from "./_chunks/resolve-plugins.mjs";
|
|
6
|
-
import { streamHtmlToMarkdown as streamHtmlToMarkdown$1 } from "./_chunks/stream.mjs";
|
|
7
|
-
import { withMinimalPreset } from "./preset/minimal.mjs";
|
|
8
|
-
function resolveHooks(options) {
|
|
9
|
-
return options.hooks?.length ? options.hooks : void 0;
|
|
10
|
-
}
|
|
11
|
-
function convert(html, options, hooks) {
|
|
12
|
-
const { plugins, callExtractionHandlers, getFrontmatter, frontmatterCallback } = resolvePlugins(options, hooks);
|
|
13
|
-
const tagOverrideHandlers = options.plugins?.tagOverrides ? buildTagOverrideHandlers(options.plugins.tagOverrides) : void 0;
|
|
14
|
-
const processor = createMarkdownProcessor(options, plugins, tagOverrideHandlers);
|
|
15
|
-
processor.processHtml(html);
|
|
16
|
-
if (getFrontmatter && frontmatterCallback) {
|
|
17
|
-
const fm = getFrontmatter();
|
|
18
|
-
if (fm) frontmatterCallback(fm);
|
|
19
|
-
}
|
|
20
|
-
callExtractionHandlers?.();
|
|
21
|
-
return processor.getMarkdown();
|
|
22
|
-
}
|
|
23
|
-
function htmlToMarkdown(html, options = {}) {
|
|
24
|
-
const markdown = convert(html, options, resolveHooks(options));
|
|
25
|
-
if (options.clean && (options.format === void 0 || options.format === "markdown")) return applyClean(markdown, resolveClean(options.clean));
|
|
26
|
-
return markdown;
|
|
27
|
-
}
|
|
28
|
-
function streamHtmlToMarkdown(htmlStream, options = {}) {
|
|
29
|
-
const hooks = resolveHooks(options);
|
|
30
|
-
const { plugins } = resolvePlugins(options, hooks);
|
|
31
|
-
const tagOverrideHandlers = options.plugins?.tagOverrides ? buildTagOverrideHandlers(options.plugins.tagOverrides) : void 0;
|
|
32
|
-
return streamHtmlToMarkdown$1(htmlStream, options, plugins, tagOverrideHandlers);
|
|
33
|
-
}
|
|
34
|
-
export { ELEMENT_NODE, NodeEventEnter, NodeEventExit, TAG_H1, TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6, TEXT_NODE, createPlugin, htmlToMarkdown, streamHtmlToMarkdown, withMinimalPreset };
|
|
1
|
+
import { ELEMENT_NODE, NodeEventEnter, NodeEventExit, TEXT_NODE } from "./_chunks/const.mjs";
|
|
2
|
+
import { createPlugin } from "./_chunks/plugin.mjs";
|
|
3
|
+
import { htmlToMarkdown, streamHtmlToMarkdown } from "./_chunks/src.mjs";
|
|
4
|
+
export { ELEMENT_NODE, NodeEventEnter, NodeEventExit, TEXT_NODE, createPlugin, htmlToMarkdown, streamHtmlToMarkdown };
|
package/dist/parse.d.mts
CHANGED
|
@@ -15,6 +15,7 @@ import { ElementNode, Node, NodeEvent, TagHandler, TransformPlugin } from "./_ch
|
|
|
15
15
|
export declare function finalizeParse(leftover: string, state: ParseState, handleEvent: (event: NodeEvent) => void): void;
|
|
16
16
|
export interface ParseOptions {
|
|
17
17
|
resolvedPlugins?: TransformPlugin[];
|
|
18
|
+
tagHandlers?: Record<number, TagHandler>;
|
|
18
19
|
}
|
|
19
20
|
export interface ParseState {
|
|
20
21
|
/** Map of tag names to their current nesting depth - uses TypedArray for performance */
|
|
@@ -52,24 +53,28 @@ export interface ParseState {
|
|
|
52
53
|
scriptDataState?: number;
|
|
53
54
|
/** Consumed script chunks retained for extraction/plugin text events. */
|
|
54
55
|
scriptTextChunks?: string[];
|
|
56
|
+
/** Output streams may discard excluded raw text when no plugin needs events. */
|
|
57
|
+
discardExcludedText?: boolean;
|
|
55
58
|
/** Reference to the last processed text node - for context tracking */
|
|
56
59
|
lastTextNode?: Node;
|
|
57
|
-
/** @deprecated No longer read or written. Retained for source compatibility. */
|
|
58
|
-
inSingleQuote?: boolean;
|
|
59
|
-
/** @deprecated No longer read or written. Retained for source compatibility. */
|
|
60
|
-
inDoubleQuote?: boolean;
|
|
61
|
-
/** @deprecated No longer read or written. Retained for source compatibility. */
|
|
62
|
-
inBacktick?: boolean;
|
|
63
|
-
/** @deprecated Rawtext parsing is no longer quote-aware. Retained for source compatibility. */
|
|
64
|
-
inRawTextQuoteAware?: boolean;
|
|
65
|
-
/** @deprecated No longer read or written. Retained for source compatibility. */
|
|
66
|
-
lastCharWasBackslash?: boolean;
|
|
67
60
|
/** Resolved plugin instances for event processing */
|
|
68
61
|
resolvedPlugins?: TransformPlugin[];
|
|
62
|
+
/** Output-specific tag behavior. Parsing metadata is used when absent. */
|
|
63
|
+
tagHandlers?: Record<number, TagHandler>;
|
|
69
64
|
/** Tag override handlers built from declarative tagOverrides config */
|
|
70
65
|
tagOverrideHandlers?: Map<string, TagHandler>;
|
|
71
66
|
/** Whether emitted text should skip Markdown-only escaping */
|
|
72
67
|
plainText?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Parsed (whitespace-collapsed) form of the raw run the last parse returned.
|
|
70
|
+
* At end of input it is committed instead of the raw run, so trailing text
|
|
71
|
+
* collapses whitespace like any other text.
|
|
72
|
+
*/
|
|
73
|
+
trailingText?: string;
|
|
74
|
+
/** The trailing run is an unfinished end tag of the open rawtext element. */
|
|
75
|
+
rawtextEndTagPending?: boolean;
|
|
76
|
+
/** The last token was an end tag that closed nothing; the next text joins. */
|
|
77
|
+
endTagClosedNothing?: boolean;
|
|
73
78
|
}
|
|
74
79
|
export interface ParseResult {
|
|
75
80
|
events: NodeEvent[];
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,53 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createPlugin } from "./_chunks/
|
|
3
|
-
interface ExtractedElement extends ElementNode {
|
|
4
|
-
textContent: string;
|
|
5
|
-
}
|
|
6
|
-
type ExtractionCallback = (element: ExtractedElement, state: MdreamRuntimeState) => void;
|
|
7
|
-
/** Extract matching elements through the composable JavaScript plugin interface. */
|
|
8
|
-
export declare function extractionPlugin(selectors: Record<string, ExtractionCallback>): TransformPlugin;
|
|
9
|
-
/**
|
|
10
|
-
* Extraction collector for `plugins.extraction` config.
|
|
11
|
-
* Collects results during processing; callbacks are called post-conversion
|
|
12
|
-
* to match Rust engine behavior.
|
|
13
|
-
*/
|
|
14
|
-
export declare function extractionCollectorPlugin(config: Record<string, (element: ExtractedElement$1) => void>): {
|
|
15
|
-
plugin: TransformPlugin;
|
|
16
|
-
getResults: () => ExtractedElement$1[];
|
|
17
|
-
callHandlers: () => void;
|
|
18
|
-
};
|
|
1
|
+
import { PluginSetup, TransformPlugin } from "./_chunks/types.mjs";
|
|
2
|
+
import { ExtractedElement, createPlugin, extractionPlugin } from "./_chunks/extraction.mjs";
|
|
19
3
|
/**
|
|
20
4
|
* Plugin that filters nodes based on CSS selectors.
|
|
21
5
|
* Allows including or excluding nodes based on selectors.
|
|
22
6
|
*
|
|
23
7
|
* @example
|
|
24
8
|
* // Include only heading elements and their children
|
|
25
|
-
*
|
|
9
|
+
* filterPlugin({ include: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] })
|
|
26
10
|
*
|
|
27
11
|
* @example
|
|
28
12
|
* // Exclude navigation, sidebar, and footer
|
|
29
|
-
*
|
|
13
|
+
* filterPlugin({ exclude: ['nav', '#sidebar', '.footer'] })
|
|
30
14
|
*/
|
|
31
15
|
export declare function filterPlugin(options?: {
|
|
32
|
-
/** CSS selectors
|
|
33
|
-
include?:
|
|
34
|
-
/** CSS selectors
|
|
35
|
-
exclude?:
|
|
16
|
+
/** CSS selectors or tag names for elements to include (all others will be excluded) */
|
|
17
|
+
include?: string[];
|
|
18
|
+
/** CSS selectors or tag names for elements to exclude */
|
|
19
|
+
exclude?: string[];
|
|
36
20
|
/** Whether to also process the children of matching elements */
|
|
37
21
|
processChildren?: boolean;
|
|
38
|
-
keepAbsolute?: boolean;
|
|
39
22
|
}): TransformPlugin;
|
|
40
23
|
interface FrontmatterPluginOptions {
|
|
41
24
|
/** Additional frontmatter fields to include */
|
|
42
25
|
additionalFields?: Record<string, string>;
|
|
43
26
|
/** Meta tag names to extract (beyond the standard ones) */
|
|
44
27
|
metaFields?: string[];
|
|
28
|
+
/** Receive structured frontmatter once the document is converted. */
|
|
29
|
+
onExtract?: (frontmatter: Record<string, string>) => void;
|
|
45
30
|
}
|
|
46
31
|
/**
|
|
47
32
|
* A plugin that manages frontmatter generation from HTML head elements
|
|
48
33
|
* Extracts metadata from meta tags and title and generates YAML frontmatter
|
|
49
34
|
*/
|
|
50
|
-
export declare function frontmatterPlugin(options?: FrontmatterPluginOptions):
|
|
35
|
+
export declare function frontmatterPlugin(options?: FrontmatterPluginOptions): PluginSetup;
|
|
51
36
|
/**
|
|
52
37
|
* Plugin that isolates main content using the following priority order:
|
|
53
38
|
* 1. If an explicit <main> element exists (within 5 depth levels), use its content exclusively
|
|
@@ -77,9 +62,9 @@ export declare function frontmatterPlugin(options?: FrontmatterPluginOptions): T
|
|
|
77
62
|
* </body>
|
|
78
63
|
* ```
|
|
79
64
|
*/
|
|
80
|
-
export declare function isolateMainPlugin():
|
|
65
|
+
export declare function isolateMainPlugin(): PluginSetup;
|
|
81
66
|
/**
|
|
82
67
|
* Creates a plugin that adds Tailwind class processing
|
|
83
68
|
*/
|
|
84
69
|
export declare function tailwindPlugin(): TransformPlugin;
|
|
85
|
-
export { type ExtractedElement, createPlugin };
|
|
70
|
+
export { type ExtractedElement, type FrontmatterPluginOptions, createPlugin, extractionPlugin };
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,2 +1,52 @@
|
|
|
1
|
-
import { createPlugin
|
|
2
|
-
|
|
1
|
+
import { createPlugin } from "./_chunks/plugin.mjs";
|
|
2
|
+
import { filterPlugin, frontmatterPlugin, isolateMainPlugin, parseSelector, tailwindPlugin } from "./_chunks/tailwind.mjs";
|
|
3
|
+
function extractionPlugin(selectors) {
|
|
4
|
+
const matcherCallbacks = Object.entries(selectors).map(([selector, callback]) => ({
|
|
5
|
+
matcher: parseSelector(selector),
|
|
6
|
+
callback
|
|
7
|
+
}));
|
|
8
|
+
return createPlugin(() => createExtractionHooks(matcherCallbacks));
|
|
9
|
+
}
|
|
10
|
+
function createExtractionHooks(matcherCallbacks) {
|
|
11
|
+
const trackedElements = /* @__PURE__ */ new Map();
|
|
12
|
+
return createPlugin({
|
|
13
|
+
onNodeEnter(element) {
|
|
14
|
+
let callbacks;
|
|
15
|
+
for (let i = 0; i < matcherCallbacks.length; i++) {
|
|
16
|
+
const { matcher, callback } = matcherCallbacks[i];
|
|
17
|
+
if (matcher.matches(element)) {
|
|
18
|
+
callbacks ||= [];
|
|
19
|
+
callbacks.push(callback);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (callbacks) trackedElements.set(element, {
|
|
23
|
+
textContent: "",
|
|
24
|
+
callbacks
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
processTextNode(textNode) {
|
|
28
|
+
let currentParent = textNode.parent;
|
|
29
|
+
while (currentParent) {
|
|
30
|
+
const tracked = trackedElements.get(currentParent);
|
|
31
|
+
if (tracked) tracked.textContent += textNode.value;
|
|
32
|
+
currentParent = currentParent.parent;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
onNodeExit(element, state) {
|
|
36
|
+
const tracked = trackedElements.get(element);
|
|
37
|
+
if (tracked) {
|
|
38
|
+
for (let i = 0; i < tracked.callbacks.length; i++) {
|
|
39
|
+
const extractedElement = {
|
|
40
|
+
...element,
|
|
41
|
+
depthMap: element.depthMap,
|
|
42
|
+
attributes: { ...element.attributes },
|
|
43
|
+
textContent: tracked.textContent.trim()
|
|
44
|
+
};
|
|
45
|
+
tracked.callbacks[i](extractedElement, state);
|
|
46
|
+
}
|
|
47
|
+
trackedElements.delete(element);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export { createPlugin, extractionPlugin, filterPlugin, frontmatterPlugin, isolateMainPlugin, tailwindPlugin };
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Cleaner, MdreamOptions, SplitterOptions } from "../_chunks/types.mjs";
|
|
2
|
+
/** Preset input: the options it returns, where `clean: false` turns off the default cleanup. */
|
|
3
|
+
type PresetInput<T extends MdreamOptions> = Omit<T, 'clean'> & {
|
|
4
|
+
clean?: Cleaner | false;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Compose the minimal plugin set with explicit user plugins. An appended
|
|
8
|
+
* `filterPlugin()` adds to the preset's excludes. To leave out a default
|
|
9
|
+
* plugin, pass your own `plugins` array instead of using the preset.
|
|
10
|
+
* Splitter options pass through, so the result also works with
|
|
11
|
+
* `htmlToMarkdownSplitChunks()`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withMinimalPreset(options?: PresetInput<MdreamOptions>): MdreamOptions;
|
|
14
|
+
export declare function withMinimalPreset(options: PresetInput<SplitterOptions>): SplitterOptions;
|
package/dist/preset/minimal.mjs
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
import "../_chunks/
|
|
2
|
-
function withMinimalPreset(options = {}) {
|
|
3
|
-
return {
|
|
4
|
-
clean: options.clean !== void 0 ? options.clean : true,
|
|
5
|
-
...options,
|
|
6
|
-
plugins: {
|
|
7
|
-
frontmatter: true,
|
|
8
|
-
isolateMain: true,
|
|
9
|
-
tailwind: true,
|
|
10
|
-
filter: { exclude: [
|
|
11
|
-
40,
|
|
12
|
-
68,
|
|
13
|
-
103,
|
|
14
|
-
58,
|
|
15
|
-
47,
|
|
16
|
-
88,
|
|
17
|
-
73,
|
|
18
|
-
59,
|
|
19
|
-
66,
|
|
20
|
-
65,
|
|
21
|
-
43,
|
|
22
|
-
41
|
|
23
|
-
] },
|
|
24
|
-
...options.plugins
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
1
|
+
import { withMinimalPreset } from "../_chunks/minimal.mjs";
|
|
28
2
|
export { withMinimalPreset };
|
package/dist/splitter.d.mts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { MarkdownChunk, SplitterOptions } from "./_chunks/types.mjs";
|
|
2
2
|
/**
|
|
3
|
-
* Convert HTML to Markdown and split into chunks
|
|
4
|
-
*
|
|
3
|
+
* Convert HTML to Markdown and split it into chunks.
|
|
4
|
+
*
|
|
5
|
+
* The whole document converts before the first chunk. Open writers, such as
|
|
6
|
+
* a blockquote or fragment cleanup, can rewrite earlier output until the
|
|
7
|
+
* document ends. The generator then yields one chunk at a time, so a caller
|
|
8
|
+
* that stops early skips the remaining chunk work.
|
|
9
|
+
*
|
|
10
|
+
* Chunks drop the separators between them. A chunk's `content` has no blank
|
|
11
|
+
* first or last line, and `metadata.loc` gives the lines it spans in the
|
|
12
|
+
* converted Markdown.
|
|
5
13
|
*
|
|
6
14
|
* **JavaScript engine only** — uses the JS engine's internal processing pipeline.
|
|
7
15
|
* Not compatible with the Rust engine.
|
|
8
16
|
*/
|
|
9
17
|
export declare function htmlToMarkdownSplitChunksStream(html: string, options?: SplitterOptions): Generator<MarkdownChunk, void, undefined>;
|
|
10
18
|
/**
|
|
11
|
-
* Convert HTML to Markdown and split into chunks
|
|
12
|
-
*
|
|
19
|
+
* Convert HTML to Markdown and split it into chunks.
|
|
20
|
+
* See `htmlToMarkdownSplitChunksStream` for the chunk contract.
|
|
13
21
|
*
|
|
14
22
|
* **JavaScript engine only** — uses the JS engine's internal processing pipeline.
|
|
15
23
|
* Not compatible with the Rust engine.
|