@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.
Files changed (40) hide show
  1. package/README.md +402 -126
  2. package/dist/_chunks/clean.mjs +526 -0
  3. package/dist/_chunks/const.mjs +3 -7
  4. package/dist/_chunks/extraction.d.mts +14 -0
  5. package/dist/_chunks/html.mjs +260 -0
  6. package/dist/_chunks/markdown-processor.mjs +1077 -828
  7. package/dist/_chunks/minimal.mjs +29 -0
  8. package/dist/_chunks/output-runner.mjs +54 -0
  9. package/dist/_chunks/parse.mjs +133 -1500
  10. package/dist/_chunks/plugin.mjs +14 -0
  11. package/dist/_chunks/src.mjs +291 -0
  12. package/dist/_chunks/tag-overrides.mjs +138 -0
  13. package/dist/_chunks/{plugins.mjs → tailwind.mjs} +145 -292
  14. package/dist/_chunks/text.mjs +583 -0
  15. package/dist/_chunks/types.d.mts +136 -126
  16. package/dist/_chunks/url.mjs +82 -0
  17. package/dist/_chunks/utils.mjs +659 -0
  18. package/dist/clean.d.mts +10 -0
  19. package/dist/clean.mjs +2 -0
  20. package/dist/cli.mjs +47 -8
  21. package/dist/html.d.mts +6 -0
  22. package/dist/html.mjs +2 -0
  23. package/dist/index.d.mts +5 -4
  24. package/dist/index.mjs +4 -58
  25. package/dist/parse.d.mts +15 -10
  26. package/dist/plugins.d.mts +13 -28
  27. package/dist/plugins.mjs +52 -2
  28. package/dist/preset/minimal.d.mts +14 -2
  29. package/dist/preset/minimal.mjs +1 -32
  30. package/dist/splitter.d.mts +12 -4
  31. package/dist/splitter.mjs +355 -113
  32. package/dist/text.d.mts +6 -0
  33. package/dist/text.mjs +2 -0
  34. package/package.json +33 -7
  35. package/dist/_chunks/index.d.mts +0 -9
  36. package/dist/_chunks/minimal.d.mts +0 -6
  37. package/dist/_chunks/resolve-plugins.mjs +0 -44
  38. package/dist/_chunks/stream.mjs +0 -37
  39. package/dist/core.d.mts +0 -15
  40. package/dist/core.mjs +0 -28
package/dist/cli.mjs CHANGED
@@ -1,5 +1,7 @@
1
- import { withMinimalPreset } from "./preset/minimal.mjs";
2
- import { streamHtmlToMarkdown } from "./index.mjs";
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 === "minimal") conversionOptions = withMinimalPreset(conversionOptions);
21
- const markdownGenerator = streamHtmlToMarkdown(Readable.toWeb(process.stdin), conversionOptions);
22
- for await (const markdownChunk of markdownGenerator) if (markdownChunk && markdownChunk.length > 0) process.stdout.write(markdownChunk);
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 {};
@@ -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
@@ -0,0 +1,2 @@
1
+ import { htmlToSafeHtml, streamHtmlToSafeHtml } from "./_chunks/html.mjs";
2
+ export { htmlToSafeHtml, streamHtmlToSafeHtml };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { BuiltinPlugins, CleanOptions, ELEMENT_NODE, ElementNode, EngineOptions, ExtractedElement, FrontmatterConfig, MarkdownChunk, MdreamOptions, Node, NodeEvent, NodeEventEnter, NodeEventExit, PluginContext, SplitterOptions, TAG_H1, TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6, TEXT_NODE, TagOverride, TextNode, TransformPlugin } from "./_chunks/types.mjs";
2
- import { createPlugin, htmlToMarkdown, streamHtmlToMarkdown } from "./_chunks/index.mjs";
3
- import { withMinimalPreset } from "./_chunks/minimal.mjs";
4
- export { type BuiltinPlugins, type CleanOptions, ELEMENT_NODE, type ElementNode, type EngineOptions, type ExtractedElement, type FrontmatterConfig, type MarkdownChunk, type MdreamOptions, type Node, type NodeEvent, NodeEventEnter, NodeEventExit, type PluginContext, type SplitterOptions, TAG_H1, TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6, TEXT_NODE, type TagOverride, type TextNode, type TransformPlugin, createPlugin, htmlToMarkdown, streamHtmlToMarkdown, withMinimalPreset };
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,58 +1,4 @@
1
- import { ELEMENT_NODE, NodeEventEnter, NodeEventExit, TAG_H1, TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6, TEXT_NODE } from "./_chunks/const.mjs";
2
- import { buildTagOverrideHandlers } from "./_chunks/parse.mjs";
3
- import { applyClean, createMarkdownProcessor, resolveClean } from "./_chunks/markdown-processor.mjs";
4
- import { createPlugin } from "./_chunks/plugins.mjs";
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
- const TOP_LEVEL_PLUGIN_KEYS = [
9
- "frontmatter",
10
- "isolateMain",
11
- "tailwind",
12
- "filter",
13
- "extraction",
14
- "tagOverrides"
15
- ];
16
- function assertEngineOptions(options) {
17
- if ("minimal" in options) throw new TypeError("@mdream/js has no `minimal` option. Use withMinimalPreset() from '@mdream/js/preset/minimal': htmlToMarkdown(html, withMinimalPreset({ origin })).");
18
- for (const key of TOP_LEVEL_PLUGIN_KEYS) if (key in options) throw new TypeError(`@mdream/js reads \`${key}\` from \`plugins\`. Pass { plugins: { ${key} } } instead of { ${key} }.`);
19
- }
20
- function resolveHooks(options) {
21
- return options.hooks?.length ? options.hooks : void 0;
22
- }
23
- function convert(html, options, hooks) {
24
- const { plugins, callExtractionHandlers, getFrontmatter, frontmatterCallback } = resolvePlugins(options, hooks);
25
- const tagOverrideHandlers = options.plugins?.tagOverrides ? buildTagOverrideHandlers(options.plugins.tagOverrides) : void 0;
26
- const processor = createMarkdownProcessor(options, plugins, tagOverrideHandlers);
27
- processor.processHtml(html);
28
- if (getFrontmatter && frontmatterCallback) {
29
- const fm = getFrontmatter();
30
- if (fm) frontmatterCallback(fm);
31
- }
32
- callExtractionHandlers?.();
33
- return processor.getMarkdown();
34
- }
35
- function htmlToMarkdown(html, options = {}) {
36
- assertEngineOptions(options);
37
- const markdown = convert(html, options, resolveHooks(options));
38
- if (options.clean && (options.format === void 0 || options.format === "markdown")) return applyClean(markdown, resolveClean(options.clean));
39
- return markdown;
40
- }
41
- function streamHtmlToMarkdown(htmlStream, options = {}) {
42
- assertEngineOptions(options);
43
- const hooks = resolveHooks(options);
44
- const { plugins, callExtractionHandlers, getFrontmatter, frontmatterCallback } = resolvePlugins(options, hooks);
45
- const tagOverrideHandlers = options.plugins?.tagOverrides ? buildTagOverrideHandlers(options.plugins.tagOverrides) : void 0;
46
- const stream = streamHtmlToMarkdown$1(htmlStream, options, plugins, tagOverrideHandlers);
47
- if (!callExtractionHandlers && !frontmatterCallback) return stream;
48
- return withCallbacks(stream, () => {
49
- const fm = getFrontmatter?.();
50
- if (fm && frontmatterCallback) frontmatterCallback(fm);
51
- callExtractionHandlers?.();
52
- });
53
- }
54
- async function* withCallbacks(stream, onEnd) {
55
- yield* stream;
56
- onEnd();
57
- }
58
- 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[];
@@ -1,53 +1,38 @@
1
- import { ElementNode, ExtractedElement as ExtractedElement$1, MdreamRuntimeState, TransformPlugin } from "./_chunks/types.mjs";
2
- import { createPlugin } from "./_chunks/index.mjs";
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
- * withQuerySelectorPlugin({ include: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] })
9
+ * filterPlugin({ include: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] })
26
10
  *
27
11
  * @example
28
12
  * // Exclude navigation, sidebar, and footer
29
- * withQuerySelectorPlugin({ exclude: ['nav', '#sidebar', '.footer'] })
13
+ * filterPlugin({ exclude: ['nav', '#sidebar', '.footer'] })
30
14
  */
31
15
  export declare function filterPlugin(options?: {
32
- /** CSS selectors, tag names, or TAG_* constants for elements to include (all others will be excluded) */
33
- include?: (string | number)[];
34
- /** CSS selectors, tag names, or TAG_* constants for elements to exclude */
35
- exclude?: (string | number)[];
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): TransformPlugin;
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(): TransformPlugin;
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, extractionCollectorPlugin, extractionPlugin, filterPlugin, frontmatterPlugin, isolateMainPlugin, tailwindPlugin } from "./_chunks/plugins.mjs";
2
- export { createPlugin, extractionCollectorPlugin, extractionPlugin, filterPlugin, frontmatterPlugin, isolateMainPlugin, tailwindPlugin };
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 { withMinimalPreset } from "../_chunks/minimal.mjs";
2
- export { withMinimalPreset };
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;
@@ -1,33 +1,2 @@
1
- import "../_chunks/const.mjs";
2
- const MINIMAL_EXCLUDE = [
3
- 40,
4
- 68,
5
- 103,
6
- 58,
7
- 47,
8
- 88,
9
- 73,
10
- 59,
11
- 66,
12
- 65,
13
- 43,
14
- 41
15
- ];
16
- function withMinimalPreset(options = {}) {
17
- const filter = options.plugins?.filter;
18
- return {
19
- clean: options.clean !== void 0 ? options.clean : true,
20
- ...options,
21
- plugins: {
22
- frontmatter: true,
23
- isolateMain: true,
24
- tailwind: true,
25
- ...options.plugins,
26
- filter: filter === false ? false : {
27
- ...filter,
28
- exclude: [...MINIMAL_EXCLUDE, ...filter?.exclude ?? []]
29
- }
30
- }
31
- };
32
- }
1
+ import { withMinimalPreset } from "../_chunks/minimal.mjs";
33
2
  export { withMinimalPreset };
@@ -1,15 +1,23 @@
1
1
  import { MarkdownChunk, SplitterOptions } from "./_chunks/types.mjs";
2
2
  /**
3
- * Convert HTML to Markdown and split into chunks in single pass.
4
- * Yields chunks during HTML event processing for better memory efficiency.
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 in single pass.
12
- * Chunks are created during HTML event processing.
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.