mdream 0.16.0 → 0.17.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/README.md +0 -9
- package/dist/_chunks/const.mjs +110 -228
- package/dist/_chunks/extraction.mjs +24 -1
- package/dist/_chunks/markdown-processor.mjs +269 -167
- package/dist/_chunks/plugin.mjs +7 -0
- package/dist/_chunks/{tailwind.mjs → plugins.mjs} +115 -27
- package/dist/_chunks/{stream.mjs → src.mjs} +16 -1
- package/dist/cli.mjs +7 -1
- package/dist/iife.js +4 -3
- package/dist/index.mjs +3 -8
- package/dist/llms-txt.mjs +91 -5
- package/dist/negotiate.d.mts +26 -0
- package/dist/negotiate.mjs +92 -0
- package/dist/plugins.mjs +2 -1
- package/dist/preset/minimal.mjs +28 -18
- package/dist/splitter.mjs +34 -19
- package/package.json +10 -2
package/dist/_chunks/plugin.mjs
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
//#region src/pluggable/plugin.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a plugin that implements the Plugin interface with improved type inference
|
|
4
|
+
*
|
|
5
|
+
* @returns A complete plugin implementation
|
|
6
|
+
*/
|
|
1
7
|
function createPlugin(plugin) {
|
|
2
8
|
return plugin;
|
|
3
9
|
}
|
|
10
|
+
//#endregion
|
|
4
11
|
export { createPlugin as t };
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { $ as TAG_H5, Q as TAG_H4, X as TAG_H2, Y as TAG_H1, Z as TAG_H3, dn as TEXT_NODE, et as TAG_H6, ht as TAG_MAIN, nn as TAG_TITLE, nt as TAG_HEADER, q as TAG_FOOTER, r as ELEMENT_NODE, tt as TAG_HEAD, vt as TAG_META } from "./const.mjs";
|
|
2
1
|
import { t as createPlugin } from "./plugin.mjs";
|
|
3
2
|
import { n as parseSelector } from "./extraction.mjs";
|
|
3
|
+
//#region src/plugins/filter.ts
|
|
4
|
+
/**
|
|
5
|
+
* Plugin that filters nodes based on CSS selectors.
|
|
6
|
+
* Allows including or excluding nodes based on selectors.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Include only heading elements and their children
|
|
10
|
+
* withQuerySelectorPlugin({ include: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] })
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Exclude navigation, sidebar, and footer
|
|
14
|
+
* withQuerySelectorPlugin({ exclude: ['nav', '#sidebar', '.footer'] })
|
|
15
|
+
*/
|
|
4
16
|
function filterPlugin(options = {}) {
|
|
5
17
|
const includeSelectors = options.include?.map((selector) => {
|
|
6
18
|
if (typeof selector === "string") return parseSelector(selector);
|
|
@@ -13,7 +25,7 @@ function filterPlugin(options = {}) {
|
|
|
13
25
|
const processChildren = options.processChildren !== false;
|
|
14
26
|
return createPlugin({ beforeNodeProcess(event) {
|
|
15
27
|
const { node } = event;
|
|
16
|
-
if (node.type ===
|
|
28
|
+
if (node.type === 2) {
|
|
17
29
|
let currentParent = node.parent;
|
|
18
30
|
while (currentParent && excludeSelectors.length) {
|
|
19
31
|
if (excludeSelectors.some((selector) => selector.matches(currentParent))) return { skip: true };
|
|
@@ -21,7 +33,7 @@ function filterPlugin(options = {}) {
|
|
|
21
33
|
}
|
|
22
34
|
return;
|
|
23
35
|
}
|
|
24
|
-
if (node.type !==
|
|
36
|
+
if (node.type !== 1) return;
|
|
25
37
|
const element = node;
|
|
26
38
|
if (excludeSelectors.length) {
|
|
27
39
|
if (element.attributes.style?.includes("absolute") || element.attributes.style?.includes("fixed")) return { skip: true };
|
|
@@ -45,6 +57,13 @@ function filterPlugin(options = {}) {
|
|
|
45
57
|
}
|
|
46
58
|
} });
|
|
47
59
|
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/plugins/frontmatter.ts
|
|
62
|
+
const DOUBLE_QUOTE_RE = /"/g;
|
|
63
|
+
/**
|
|
64
|
+
* A plugin that manages frontmatter generation from HTML head elements
|
|
65
|
+
* Extracts metadata from meta tags and title and generates YAML frontmatter
|
|
66
|
+
*/
|
|
48
67
|
function frontmatterPlugin(options = {}) {
|
|
49
68
|
const additionalFields = options.additionalFields || {};
|
|
50
69
|
const metaFields = new Set([
|
|
@@ -64,18 +83,18 @@ function frontmatterPlugin(options = {}) {
|
|
|
64
83
|
};
|
|
65
84
|
let inHead = false;
|
|
66
85
|
const formatValue = options.formatValue || ((name, value) => {
|
|
67
|
-
value = value.replace(
|
|
86
|
+
value = value.replace(DOUBLE_QUOTE_RE, "\\\"");
|
|
68
87
|
if (value.includes("\n") || value.includes(":") || value.includes("#") || value.includes(" ")) return `"${value}"`;
|
|
69
88
|
return value;
|
|
70
89
|
});
|
|
71
90
|
return createPlugin({
|
|
72
91
|
onNodeEnter(node) {
|
|
73
|
-
if (node.tagId ===
|
|
92
|
+
if (node.tagId === 1) {
|
|
74
93
|
inHead = true;
|
|
75
94
|
return;
|
|
76
95
|
}
|
|
77
|
-
if (inHead && node.type ===
|
|
78
|
-
if (inHead && node.type ===
|
|
96
|
+
if (inHead && node.type === 1 && node.tagId === 4) return;
|
|
97
|
+
if (inHead && node.type === 1 && node.tagId === 5) {
|
|
79
98
|
const { name, property, content } = node.attributes || {};
|
|
80
99
|
const metaName = property || name;
|
|
81
100
|
if (metaName && content && metaFields.has(metaName)) frontmatter.meta[metaName.includes(":") ? `"${metaName}"` : metaName] = formatValue(metaName, content);
|
|
@@ -83,7 +102,7 @@ function frontmatterPlugin(options = {}) {
|
|
|
83
102
|
}
|
|
84
103
|
},
|
|
85
104
|
onNodeExit(node, state) {
|
|
86
|
-
if (node.type ===
|
|
105
|
+
if (node.type === 1 && node.tagId === 1) {
|
|
87
106
|
inHead = false;
|
|
88
107
|
if (Object.keys(frontmatter).length > 0) {
|
|
89
108
|
const frontmatterContent = generateFrontmatter();
|
|
@@ -97,7 +116,7 @@ function frontmatterPlugin(options = {}) {
|
|
|
97
116
|
processTextNode(node) {
|
|
98
117
|
if (!inHead) return;
|
|
99
118
|
const parent = node.parent;
|
|
100
|
-
if (parent && parent.tagId ===
|
|
119
|
+
if (parent && parent.tagId === 4 && node.value) {
|
|
101
120
|
frontmatter.title = formatValue("title", node.value.trim());
|
|
102
121
|
return {
|
|
103
122
|
content: "",
|
|
@@ -106,6 +125,9 @@ function frontmatterPlugin(options = {}) {
|
|
|
106
125
|
}
|
|
107
126
|
}
|
|
108
127
|
});
|
|
128
|
+
/**
|
|
129
|
+
* Generate YAML frontmatter string from collected metadata
|
|
130
|
+
*/
|
|
109
131
|
function generateFrontmatter() {
|
|
110
132
|
if (Object.keys(frontmatter).length === 0) return "";
|
|
111
133
|
let yamlLines = [];
|
|
@@ -125,23 +147,54 @@ function frontmatterPlugin(options = {}) {
|
|
|
125
147
|
return `---\n${yamlLines.join("\n")}\n---\n\n`;
|
|
126
148
|
}
|
|
127
149
|
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/plugins/isolate-main.ts
|
|
152
|
+
/**
|
|
153
|
+
* Plugin that isolates main content using the following priority order:
|
|
154
|
+
* 1. If an explicit <main> element exists (within 5 depth levels), use its content exclusively
|
|
155
|
+
* 2. Otherwise, find content between the first header tag (h1-h6) and first footer
|
|
156
|
+
* 3. If footer is within 5 levels of nesting from the header, use it as the end boundary
|
|
157
|
+
* 4. Exclude all content before the start marker and after the end marker
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```html
|
|
161
|
+
* <body>
|
|
162
|
+
* <nav>Navigation (excluded)</nav>
|
|
163
|
+
* <main>
|
|
164
|
+
* <h1>Main Title (included)</h1>
|
|
165
|
+
* <p>Main content (included)</p>
|
|
166
|
+
* </main>
|
|
167
|
+
* <footer>Footer (excluded)</footer>
|
|
168
|
+
* </body>
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```html
|
|
173
|
+
* <body>
|
|
174
|
+
* <nav>Navigation (excluded)</nav>
|
|
175
|
+
* <h1>Main Title (included)</h1>
|
|
176
|
+
* <p>Main content (included)</p>
|
|
177
|
+
* <footer>Footer (excluded)</footer>
|
|
178
|
+
* </body>
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
128
181
|
function isolateMainPlugin() {
|
|
129
182
|
let mainElement = null;
|
|
130
183
|
let firstHeaderElement = null;
|
|
131
184
|
let afterFooter = false;
|
|
132
185
|
const headerTagIds = new Set([
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
186
|
+
7,
|
|
187
|
+
8,
|
|
188
|
+
9,
|
|
189
|
+
10,
|
|
190
|
+
11,
|
|
191
|
+
12
|
|
139
192
|
]);
|
|
140
193
|
return createPlugin({ beforeNodeProcess(event) {
|
|
141
194
|
const { node } = event;
|
|
142
|
-
if (node.type ===
|
|
195
|
+
if (node.type === 1) {
|
|
143
196
|
const element = node;
|
|
144
|
-
if (!mainElement && element.tagId ===
|
|
197
|
+
if (!mainElement && element.tagId === 104 && element.depth <= 5) {
|
|
145
198
|
mainElement = element;
|
|
146
199
|
return;
|
|
147
200
|
}
|
|
@@ -162,7 +215,7 @@ function isolateMainPlugin() {
|
|
|
162
215
|
let current = element.parent;
|
|
163
216
|
let isInHeaderTag = false;
|
|
164
217
|
while (current) {
|
|
165
|
-
if (current.tagId ===
|
|
218
|
+
if (current.tagId === 105) {
|
|
166
219
|
isInHeaderTag = true;
|
|
167
220
|
break;
|
|
168
221
|
}
|
|
@@ -173,24 +226,24 @@ function isolateMainPlugin() {
|
|
|
173
226
|
return;
|
|
174
227
|
}
|
|
175
228
|
}
|
|
176
|
-
if (firstHeaderElement && !afterFooter && element.tagId ===
|
|
229
|
+
if (firstHeaderElement && !afterFooter && element.tagId === 47) {
|
|
177
230
|
if (element.depth - firstHeaderElement.depth <= 5) {
|
|
178
231
|
afterFooter = true;
|
|
179
232
|
return { skip: true };
|
|
180
233
|
}
|
|
181
234
|
}
|
|
182
235
|
if (!firstHeaderElement) {
|
|
183
|
-
if (element.tagId ===
|
|
236
|
+
if (element.tagId === 1) return;
|
|
184
237
|
let current = element.parent;
|
|
185
238
|
while (current) {
|
|
186
|
-
if (current.tagId ===
|
|
239
|
+
if (current.tagId === 1) return;
|
|
187
240
|
current = current.parent;
|
|
188
241
|
}
|
|
189
242
|
return { skip: true };
|
|
190
243
|
}
|
|
191
244
|
if (afterFooter) return { skip: true };
|
|
192
245
|
}
|
|
193
|
-
if (node.type ===
|
|
246
|
+
if (node.type === 2) {
|
|
194
247
|
if (mainElement) {
|
|
195
248
|
let current = node.parent;
|
|
196
249
|
let isInsideMain = false;
|
|
@@ -207,7 +260,7 @@ function isolateMainPlugin() {
|
|
|
207
260
|
if (!firstHeaderElement || afterFooter) {
|
|
208
261
|
let current = node.parent;
|
|
209
262
|
while (current) {
|
|
210
|
-
if (current.tagId ===
|
|
263
|
+
if (current.tagId === 1) return;
|
|
211
264
|
current = current.parent;
|
|
212
265
|
}
|
|
213
266
|
return { skip: true };
|
|
@@ -215,6 +268,11 @@ function isolateMainPlugin() {
|
|
|
215
268
|
}
|
|
216
269
|
} });
|
|
217
270
|
}
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region src/plugins/tailwind.ts
|
|
273
|
+
/**
|
|
274
|
+
* Mapping of Tailwind classes to Markdown formatting
|
|
275
|
+
*/
|
|
218
276
|
const TAILWIND_TO_MARKDOWN_MAP = {
|
|
219
277
|
"font-bold": {
|
|
220
278
|
prefix: "**",
|
|
@@ -254,6 +312,9 @@ const TAILWIND_TO_MARKDOWN_MAP = {
|
|
|
254
312
|
"fixed": { hidden: true },
|
|
255
313
|
"sticky": { hidden: true }
|
|
256
314
|
};
|
|
315
|
+
/**
|
|
316
|
+
* Extract base class name from a responsive breakpoint variant
|
|
317
|
+
*/
|
|
257
318
|
function extractBaseClass(className) {
|
|
258
319
|
for (const bp of [
|
|
259
320
|
"sm:",
|
|
@@ -270,6 +331,9 @@ function extractBaseClass(className) {
|
|
|
270
331
|
breakpoint: ""
|
|
271
332
|
};
|
|
272
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Sort classes by breakpoint for mobile-first processing
|
|
336
|
+
*/
|
|
273
337
|
function sortByBreakpoint(classes) {
|
|
274
338
|
const breakpointOrder = {
|
|
275
339
|
"": 0,
|
|
@@ -279,12 +343,15 @@ function sortByBreakpoint(classes) {
|
|
|
279
343
|
"xl:": 4,
|
|
280
344
|
"2xl:": 5
|
|
281
345
|
};
|
|
282
|
-
return
|
|
346
|
+
return classes.toSorted((a, b) => {
|
|
283
347
|
const aBreakpoint = extractBaseClass(a).breakpoint;
|
|
284
348
|
const bBreakpoint = extractBaseClass(b).breakpoint;
|
|
285
349
|
return breakpointOrder[aBreakpoint] - breakpointOrder[bBreakpoint];
|
|
286
350
|
});
|
|
287
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Group classes by their formatting type to handle overrides
|
|
354
|
+
*/
|
|
288
355
|
function groupByFormattingType(classes) {
|
|
289
356
|
const sorted = sortByBreakpoint(classes);
|
|
290
357
|
const groups = {
|
|
@@ -310,6 +377,9 @@ function groupByFormattingType(classes) {
|
|
|
310
377
|
}
|
|
311
378
|
return groups;
|
|
312
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Fix redundant markdown delimiters without regex
|
|
382
|
+
*/
|
|
313
383
|
function fixRedundantDelimiters(content) {
|
|
314
384
|
content = content.replaceAll("****", "**");
|
|
315
385
|
content = content.replaceAll("~~~~", "~~");
|
|
@@ -319,6 +389,9 @@ function fixRedundantDelimiters(content) {
|
|
|
319
389
|
}
|
|
320
390
|
return content;
|
|
321
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Normalizes a list of Tailwind classes by processing breakpoints and resolving conflicts
|
|
394
|
+
*/
|
|
322
395
|
function normalizeClasses(classes) {
|
|
323
396
|
const result = [];
|
|
324
397
|
const mobileClasses = classes.filter((cls) => !hasBreakpoint(cls));
|
|
@@ -327,10 +400,16 @@ function normalizeClasses(classes) {
|
|
|
327
400
|
result.push(...breakpointClasses);
|
|
328
401
|
return result;
|
|
329
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Check if a class has a breakpoint prefix
|
|
405
|
+
*/
|
|
330
406
|
function hasBreakpoint(className) {
|
|
331
407
|
const { breakpoint } = extractBaseClass(className);
|
|
332
408
|
return breakpoint !== "";
|
|
333
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Process Tailwind classes for an element with mobile-first approach
|
|
412
|
+
*/
|
|
334
413
|
function processTailwindClasses(classes) {
|
|
335
414
|
let prefix = "";
|
|
336
415
|
let suffix = "";
|
|
@@ -382,6 +461,9 @@ function processTailwindClasses(classes) {
|
|
|
382
461
|
hidden
|
|
383
462
|
};
|
|
384
463
|
}
|
|
464
|
+
/**
|
|
465
|
+
* Creates a plugin that adds Tailwind class processing
|
|
466
|
+
*/
|
|
385
467
|
function tailwindPlugin() {
|
|
386
468
|
return createPlugin({
|
|
387
469
|
processAttributes(node) {
|
|
@@ -397,7 +479,7 @@ function tailwindPlugin() {
|
|
|
397
479
|
},
|
|
398
480
|
processTextNode(node) {
|
|
399
481
|
const parentNode = node.parent;
|
|
400
|
-
if (!parentNode || parentNode.type !==
|
|
482
|
+
if (!parentNode || parentNode.type !== 1) return;
|
|
401
483
|
const tailwindData = parentNode.context?.tailwind;
|
|
402
484
|
if (tailwindData?.hidden) return {
|
|
403
485
|
content: "",
|
|
@@ -416,10 +498,16 @@ function tailwindPlugin() {
|
|
|
416
498
|
};
|
|
417
499
|
},
|
|
418
500
|
beforeNodeProcess({ node }) {
|
|
419
|
-
|
|
420
|
-
|
|
501
|
+
let parent = node.parent;
|
|
502
|
+
while (parent) {
|
|
503
|
+
if (parent.context?.tailwind?.hidden) return { skip: true };
|
|
504
|
+
parent = parent.parent;
|
|
505
|
+
}
|
|
506
|
+
if (node.type === 1) {
|
|
507
|
+
if (node.context?.tailwind?.hidden) return { skip: true };
|
|
421
508
|
}
|
|
422
509
|
}
|
|
423
510
|
});
|
|
424
511
|
}
|
|
512
|
+
//#endregion
|
|
425
513
|
export { filterPlugin as i, isolateMainPlugin as n, frontmatterPlugin as r, tailwindPlugin as t };
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { a as parseHtmlStream, n as createMarkdownProcessor, r as processPluginsForEvent } from "./markdown-processor.mjs";
|
|
2
|
+
//#region src/stream.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a markdown stream from an HTML stream
|
|
5
|
+
* @param htmlStream - ReadableStream of HTML content (as Uint8Array or string)
|
|
6
|
+
* @param options - Configuration options for conversion
|
|
7
|
+
* @returns An async generator yielding markdown chunks
|
|
8
|
+
*/
|
|
2
9
|
async function* streamHtmlToMarkdown(htmlStream, options = {}) {
|
|
3
10
|
if (!htmlStream) throw new Error("Invalid HTML stream provided");
|
|
4
11
|
const decoder = new TextDecoder();
|
|
@@ -30,4 +37,12 @@ async function* streamHtmlToMarkdown(htmlStream, options = {}) {
|
|
|
30
37
|
reader.releaseLock();
|
|
31
38
|
}
|
|
32
39
|
}
|
|
33
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/index.ts
|
|
42
|
+
function htmlToMarkdown(html, options = {}) {
|
|
43
|
+
const processor = createMarkdownProcessor(options);
|
|
44
|
+
processor.processHtml(html);
|
|
45
|
+
return processor.getMarkdown();
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { streamHtmlToMarkdown as n, htmlToMarkdown as t };
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import "./_chunks/const.mjs";
|
|
1
2
|
import "./_chunks/markdown-processor.mjs";
|
|
2
|
-
import
|
|
3
|
+
import "./_chunks/plugin.mjs";
|
|
4
|
+
import { n as streamHtmlToMarkdown } from "./_chunks/src.mjs";
|
|
5
|
+
import "./_chunks/extraction.mjs";
|
|
3
6
|
import { generateLlmsTxtArtifacts } from "./llms-txt.mjs";
|
|
7
|
+
import "./_chunks/plugins.mjs";
|
|
4
8
|
import { withMinimalPreset } from "./preset/minimal.mjs";
|
|
5
9
|
import { readFileSync } from "node:fs";
|
|
6
10
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
@@ -8,6 +12,7 @@ import { Readable } from "node:stream";
|
|
|
8
12
|
import { fileURLToPath } from "node:url";
|
|
9
13
|
import { cac } from "cac";
|
|
10
14
|
import { dirname, join, resolve } from "pathe";
|
|
15
|
+
//#region src/cli.ts
|
|
11
16
|
async function streamingConvert(options = {}) {
|
|
12
17
|
const outputStream = process.stdout;
|
|
13
18
|
let conversionOptions = { origin: options.origin };
|
|
@@ -58,4 +63,5 @@ cli.command("llms <patterns...>", "Generate llms.txt artifacts from HTML files")
|
|
|
58
63
|
});
|
|
59
64
|
});
|
|
60
65
|
cli.help().version(version).parse();
|
|
66
|
+
//#endregion
|
|
61
67
|
export {};
|
package/dist/iife.js
CHANGED
|
@@ -2,11 +2,12 @@ const e={"&":`&`,"<":`<`,">":`>`,""":`"`,"'":`'`,"'":`'`
|
|
|
2
2
|
|
|
3
3
|
`},3:{enter:()=>`<summary>`,exit:()=>`</summary>
|
|
4
4
|
|
|
5
|
-
`},4:{collapsesInnerWhiteSpace:!0,isNonNesting:!0,spacing:n},52:{excludesTextNodes:!0,isNonNesting:!0},53:{isNonNesting:!0,excludesTextNodes:!0},5:{collapsesInnerWhiteSpace:!0,isSelfClosing:!0,spacing:n},6:{enter:({node:e})=>c(e)?`<br>`:void 0,isSelfClosing:!0,spacing:n,collapsesInnerWhiteSpace:!0,isInline:!0},7:u(1),8:u(2),9:u(3),10:u(4),11:u(5),12:u(6),13:{enter:()=>`---`,isSelfClosing:!0},14:d,15:d,16:f,17:f,18:{enter:()=>`~~`,exit:()=>`~~`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},19:{enter:()=>`<sub>`,exit:()=>`</sub>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},20:{enter:()=>`<sup>`,exit:()=>`</sup>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},21:{enter:()=>`<ins>`,exit:()=>`</ins>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},22:{enter:({node:e})=>{let t=e.depthMap[22]||1,n=`> `.repeat(t);return e.depthMap[25]>0&&(n=`\n${` `.repeat(e.depthMap[25])}${n}`),n},spacing:i},23:{enter:({node:e})=>(e.depthMap[34]||0)>0?`\`\`\`${l(e.attributes?.class)}\n`:"`",exit:({node:e})=>e.depthMap[34]>0?"\n```":"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},24:{enter:({node:e})=>c(e)?`<ul>`:void 0,exit:({node:e})=>c(e)?`</ul>`:void 0},25:{enter:({node:e})=>{if(c(e))return`<li>`;let t=(e.depthMap[24]||0)+(e.depthMap[33]||0)-1,n=e.parent?.tagId===33;return`${` `.repeat(Math.max(0,t))}${n?`${e.index+1}. `:`- `}`},exit:({node:e})=>c(e)?`</li>`:void 0,spacing:a},26:{enter:({node:e})=>{if(e.attributes?.href)return`[`},exit:({node:e,state:t})=>{if(!e.attributes?.href)return``;let n=s(e.attributes?.href||``,t.options?.origin),r=e.attributes?.title;return t.lastContentCache===r&&(r=``),r?`](${n} "${r}")`:`](${n})`},collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},27:{enter:({node:e,state:t})=>`})`,collapsesInnerWhiteSpace:!0,isSelfClosing:!0,spacing:n,isInline:!0},28:{enter:({node:e,state:t})=>{if(c(e))return`<table>`;e.depthMap[28]<=1&&(t.tableRenderedTable=!1),t.tableColumnAlignments=[]},exit:({node:e})=>c(e)?`</table>`:void 0},29:{enter:({node:e})=>{if(c(e))return`<thead>`},exit:({node:e})=>c(e)?`</thead>`:void 0,spacing:o,excludesTextNodes:!0},30:{enter:({node:e,state:t})=>c(e)?`<tr>`:(t.tableCurrentRowCells=0,`| `),exit:({node:e,state:t})=>{if(c(e)||e.depthMap[28]>1)return`</tr>`;if(!t.tableRenderedTable){t.tableRenderedTable=!0;let e=t.tableColumnAlignments;for(;e.length<t.tableCurrentRowCells;)e.push(``);return` |\n| ${e.map(e=>{switch(e){case`left`:return`:---`;case`center`:return`:---:`;case`right`:return`---:`;default:return`---`}}).join(` | `)} |`}return` |`},excludesTextNodes:!0,spacing:o},31:{enter:({node:e,state:t})=>{if(e.depthMap[28]>1)return`<th>`;let n=e.attributes?.align?.toLowerCase();return n?t.tableColumnAlignments.push(n):t.tableColumnAlignments.length<=t.tableCurrentRowCells&&t.tableColumnAlignments.push(``),e.index===0?``:` | `},exit:({node:e,state:t})=>{if(e.depthMap[28]>1)return`</th>`;t.tableCurrentRowCells++},collapsesInnerWhiteSpace:!0,spacing:n},32:{enter:({node:e})=>e.depthMap[28]>1?`<td>`:e.index===0?``:` | `,exit:({node:e,state:t})=>{if(e.depthMap[28]>1)return`</td>`;t.tableCurrentRowCells++},collapsesInnerWhiteSpace:!0,spacing:n},35:{},36:{},37:{collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},41:{},42:{collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},43:{collapsesInnerWhiteSpace:!0,isInline:!0},44:{spacing:n},45:{enter:({node:e})=>{if(e.depthMap[28]>1)return`<center>`},exit:({node:e})=>{if(e.depthMap[28]>1)return`</center>`},spacing:n},38:{spacing:n,excludesTextNodes:!0},39:{spacing:o,excludesTextNodes:!0},46:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},47:{spacing:n},40:{spacing:n},54:{isSelfClosing:!0,spacing:n,collapsesInnerWhiteSpace:!0,isInline:!0},55:{isSelfClosing:!0,spacing:n,isInline:!0},56:{isSelfClosing:!0,spacing:n,isInline:!0},57:{isSelfClosing:!0,spacing:n},58:{isSelfClosing:!0,spacing:n},59:{isSelfClosing:!0,spacing:n,isInline:!0},60:{isSelfClosing:!0,spacing:n,isInline:!0},61:{isSelfClosing:!0,spacing:n},62:{isSelfClosing:!0,spacing:n},63:{isSelfClosing:!0,spacing:n},64:{isSelfClosing:!0,spacing:n,isInline:!0},49:{spacing:n},65:{spacing:n},66:{isNonNesting:!0,spacing:n},67:{isNonNesting:!0,spacing:n},68:{spacing:n},69:{spacing:n},70:{spacing:n},71:{spacing:n},72:{spacing:n},73:{isNonNesting:!0,spacing:n},74:{spacing:n},75:{spacing:n},76:{spacing:n},77:{spacing:n},78:{spacing:n},79:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},80:{enter:()=>`<mark>`,exit:()=>`</mark>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},81:{enter:()=>`"`,exit:()=>`"`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},82:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},83:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},84:{excludesTextNodes:!0,spacing:n},85:{isNonNesting:!0,spacing:n},86:{isNonNesting:!0,spacing:n},87:{isNonNesting:!0,spacing:n},88:{spacing:n},89:{enter:()=>`<u>`,exit:()=>`</u>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},90:{enter:()=>`*`,exit:()=>`*`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},91:{enter:()=>`**`,exit:()=>`**`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},92:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},93:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},94:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},95:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},96:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},97:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},100:{enter:()=>`<address>`,exit:()=>`</address>`,spacing:n,collapsesInnerWhiteSpace:!0},101:{spacing:n,enter:()=>`<dl>`,exit:()=>`</dl>`},99:{enter:()=>`<dt>`,exit:()=>`</dt>`,collapsesInnerWhiteSpace:!0,spacing:[0,1]},98:{enter:()=>`<dd>`,exit:()=>`</dd>`,spacing:[0,1]}};function m(t){let n=``,r=0;for(;r<t.length;){if(t[r]===`&`){let i=!1;for(let[a,o]of Object.entries(e))if(t.startsWith(a,r)){n+=o,r+=a.length,i=!0;break}if(i)continue;if(r+2<t.length&&t[r+1]===`#`){let e=r;r+=2;let i=t[r]===`x`||t[r]===`X`;i&&r++;let a=r;for(;r<t.length&&t[r]!==`;`;)r++;if(r<t.length&&t[r]===`;`){let e=t.substring(a,r),o=i?16:10;try{let t=Number.parseInt(e,o);if(!Number.isNaN(t)){n+=String.fromCodePoint(t),r++;continue}}catch{}}r=e}}n+=t[r],r++}return n}function h(e){let t=e,n=[t];for(;t.tagHandler?.isInline&&t.parent;)t=t.parent,n.push(t);return n}const g=Object.freeze({});function _(e){return new Uint8Array(e)}function v(e){return e===32||e===9||e===10||e===13}function y(e,t,n){return b(e,t,n)}function b(e,n,r){let i=``;n.depthMap??=new Uint8Array(108),n.depth??=0,n.lastCharWasWhitespace??=!0,n.justClosedTag??=!1,n.isFirstTextInElement??=!1,n.lastCharWasBackslash??=!1;let a=0,o=e.length;for(;a<o;){let s=e.charCodeAt(a);if(s!==60){if(s===38&&(n.hasEncodedHtmlEntity=!0),v(s)){let t=n.depthMap[34]>0;if(n.justClosedTag&&(n.justClosedTag=!1,n.lastCharWasWhitespace=!1),!t&&n.lastCharWasWhitespace){a++;continue}t?i+=e[a]:(s===32||!n.lastCharWasWhitespace)&&(i+=` `),n.lastCharWasWhitespace=!0,n.textBufferContainsWhitespace=!0,n.lastCharWasBackslash=!1}else n.textBufferContainsNonWhitespace=!0,n.lastCharWasWhitespace=!1,n.justClosedTag=!1,s===124&&n.depthMap[28]?i+=`\\|`:s===96&&(n.depthMap[23]||n.depthMap[34])?i+="\\`":s===91&&n.depthMap[26]?i+=`\\[`:s===93&&n.depthMap[26]?i+=`\\]`:s===62&&n.depthMap[22]?i+=`\\>`:i+=e[a],n.currentNode?.tagHandler?.isNonNesting&&(n.lastCharWasBackslash||(s===39&&!n.inDoubleQuote&&!n.inBacktick?n.inSingleQuote=!n.inSingleQuote:s===34&&!n.inSingleQuote&&!n.inBacktick?n.inDoubleQuote=!n.inDoubleQuote:s===96&&!n.inSingleQuote&&!n.inDoubleQuote&&(n.inBacktick=!n.inBacktick))),n.lastCharWasBackslash=s===92;a++;continue}if(a+1>=o){i+=e[a];break}let c=e.charCodeAt(a+1);if(c===33){i.length>0&&(x(i,n,r),i=``);let t=w(e,a);if(t.complete)a=t.newPosition;else{i+=t.remainingText;break}}else if(c===47){let t=n.inSingleQuote||n.inDoubleQuote||n.inBacktick;if(n.currentNode?.tagHandler?.isNonNesting&&t){i+=e[a],a++;continue}i.length>0&&(x(i,n,r),i=``);let o=S(e,a,n,r);if(o.complete)a=o.newPosition;else{i+=o.remainingText;break}}else{let s=a+1,c=s,l=-1;for(;s<o;){let t=e.charCodeAt(s);if(v(t)||t===47||t===62){l=s;break}s++}if(l===-1){i+=e.substring(a);break}let u=e.substring(c,l).toLowerCase();if(!u){a=l;break}let d=t[u]??-1;if(s=l,n.currentNode?.tagHandler?.isNonNesting&&d!==n.currentNode?.tagId){i+=e[a++];continue}i.length>0&&(x(i,n,r),i=``);let f=T(u,d,e,s,n,r);if(f.skip)i+=e[a++];else if(f.complete)a=f.newPosition,f.selfClosing||(n.isFirstTextInElement=!0);else{i+=f.remainingText;break}}}return i}function x(e,t,n){let r=t.textBufferContainsNonWhitespace,i=t.textBufferContainsWhitespace;if(t.textBufferContainsNonWhitespace=!1,t.textBufferContainsWhitespace=!1,!t.currentNode)return;let a=t.currentNode?.tagHandler?.excludesTextNodes,o=t.depthMap[34]>0;if(!o&&!r&&!t.currentNode.childTextNodeIndex)return;let s=e;if(s.length===0)return;let c=h(t.currentNode),l=c[c.length-1];if(i&&!l?.childTextNodeIndex){let e=0;for(;e<s.length&&(o?s.charCodeAt(e)===10||s.charCodeAt(e)===13:v(s.charCodeAt(e)));)e++;e>0&&(s=s.substring(e))}t.hasEncodedHtmlEntity&&=(s=m(String(s)),!1);let u={type:2,value:s,parent:t.currentNode,index:t.currentNode.currentWalkIndex++,depth:t.depth,containsWhitespace:i,excludedFromMarkdown:a};for(let e of c)e.childTextNodeIndex=(e.childTextNodeIndex||0)+1;n({type:0,node:u}),t.lastTextNode=u}function S(e,n,r,i){let a=n+2,o=a,s=e.length,c=!1;for(;a<s;){if(e.charCodeAt(a)===62){c=!0;break}a++}if(!c)return{complete:!1,newPosition:n,remainingText:e.substring(n)};let l=t[e.substring(o,a).toLowerCase()]??-1;if(r.currentNode?.tagHandler?.isNonNesting&&l!==r.currentNode.tagId)return{complete:!1,newPosition:n,remainingText:e.substring(n)};let u=r.currentNode;if(u){let e=u.tagId!==l;for(;u&&e;)C(u,r,i),u=u.parent,e=u?.tagId!==l}return u&&C(u,r,i),r.justClosedTag=!0,{complete:!0,newPosition:a+1,remainingText:``}}function C(e,t,n){if(e){if(e.tagId===26&&!e.childTextNodeIndex){let t=e.attributes?.title||e.attributes?.[`aria-label`]||``;if(t){e.childTextNodeIndex=1,n({type:0,node:{type:2,value:t,parent:e,index:0,depth:e.depth+1}});for(let t of h(e))t.childTextNodeIndex=(t.childTextNodeIndex||0)+1}}e.tagId&&(t.depthMap[e.tagId]=Math.max(0,t.depthMap[e.tagId]-1)),e.tagHandler?.isNonNesting&&(t.inSingleQuote=!1,t.inDoubleQuote=!1,t.inBacktick=!1,t.lastCharWasBackslash=!1),t.depth--,n({type:1,node:e}),t.currentNode=t.currentNode.parent,t.hasEncodedHtmlEntity=!1,t.justClosedTag=!0}}function w(e,t){let n=t,r=e.length;if(n+3<r&&e.charCodeAt(n+2)===45&&e.charCodeAt(n+3)===45){for(n+=4;n<r-2;){if(e.charCodeAt(n)===45&&e.charCodeAt(n+1)===45&&e.charCodeAt(n+2)===62)return n+=3,{complete:!0,newPosition:n,remainingText:``};n++}return{complete:!1,newPosition:t,remainingText:e.substring(t)}}else{for(n+=2;n<r;){if(e.charCodeAt(n)===62)return n++,{complete:!0,newPosition:n,remainingText:``};n++}return{complete:!1,newPosition:n,remainingText:e.substring(t,n)}}}function T(e,t,n,r,i,a){i.currentNode?.tagHandler?.isNonNesting&&C(i.currentNode,i,a);let o=p[t],s=E(n,r,o);if(!s.complete)return{complete:!1,newPosition:r,remainingText:`<${e}${s.attrBuffer}`,selfClosing:!1};let c=i.depthMap[t];i.depthMap[t]=c+1,i.depth++,r=s.newPosition,i.currentNode&&(i.currentNode.currentWalkIndex=i.currentNode.currentWalkIndex||0);let l=i.currentNode?i.currentNode.currentWalkIndex++:0,u={type:1,name:e,attributes:s.attributes,parent:i.currentNode,depthMap:_(i.depthMap),depth:i.depth,index:l,tagId:t,tagHandler:o};i.lastTextNode=u,a({type:0,node:u});let d=u;return d.currentWalkIndex=0,i.currentNode=d,i.hasEncodedHtmlEntity=!1,o?.isNonNesting&&!s.selfClosing&&(i.inSingleQuote=!1,i.inDoubleQuote=!1,i.inBacktick=!1,i.lastCharWasBackslash=!1),s.selfClosing?(C(u,i,a),i.justClosedTag=!0):i.justClosedTag=!1,{complete:!0,newPosition:r,remainingText:``,selfClosing:s.selfClosing}}function E(e,t,n){let r=t,i=e.length,a=n?.isSelfClosing||!1,o=r,s=!1,c=0,l=0;for(;r<i;){let t=e.charCodeAt(r);if(s){t===c&&l!==92&&(s=!1),r++;continue}else if(t===34||t===39)s=!0,c=t;else if(t===47&&r+1<i&&e.charCodeAt(r+1)===62){let t=e.substring(o,r).trim();return{complete:!0,newPosition:r+2,attributes:D(t),selfClosing:!0,attrBuffer:t}}else if(t===62){let t=e.substring(o,r).trim();return{complete:!0,newPosition:r+1,attributes:D(t),selfClosing:a,attrBuffer:t}}r++,l=t}return{complete:!1,newPosition:r,attributes:g,selfClosing:!1,attrBuffer:e.substring(o,r)}}function D(e){if(!e)return g;let t={},n=e.length,r=0,i=0,a=0,o=0,s=0,c=0,l=``;for(;r<n;){let u=e.charCodeAt(r),d=v(u);switch(i){case 0:d||(i=1,a=r,o=0);break;case 1:(u===61||d)&&(o=r,l=e.substring(a,o).toLowerCase(),i=u===61?3:2);break;case 2:u===61?i=3:d||(t[l]=``,i=1,a=r,o=0);break;case 3:u===34||u===39?(c=u,i=4,s=r+1):d||(i=5,s=r);break;case 4:u===92&&r+1<n?r++:u===c&&(t[l]=e.substring(s,r),i=0);break;case 5:(d||u===62)&&(t[l]=e.substring(s,r),i=0);break}r++}if(i===4||i===5)l&&(t[l]=e.substring(s,r));else if(i===1||i===2||i===3){o||=r;let n=e.substring(a,o).toLowerCase();n&&(t[n]=``)}return t}function O(e,t,n,r){if(t?.length){for(let r of t){let t=r.beforeNodeProcess?.(e,n);if(typeof t==`object`&&t.skip)return!0}if(e.node.type===1){let r=e.node;if(e.type===0)for(let e of t)e.processAttributes&&e.processAttributes(r,n);let i=e.type===0?`onNodeEnter`:`onNodeExit`,a=[];for(let e of t)if(e[i]){let t=e[i](r,n);t&&a.push(t)}a.length>0&&(r.pluginOutput=(r.pluginOutput||[]).concat(a))}else if(e.node.type===2&&e.type===0){let r=e.node;for(let e of t)if(e.processTextNode){let t=e.processTextNode(r,n);if(t){if(t.skip)return!0;r.value=t.content}}}}return r(e),!1}function k(e,t,n){if(e===` `||e===`
|
|
5
|
+
`},4:{collapsesInnerWhiteSpace:!0,isNonNesting:!0,spacing:n},52:{excludesTextNodes:!0,isNonNesting:!0},53:{isNonNesting:!0,excludesTextNodes:!0},5:{collapsesInnerWhiteSpace:!0,isSelfClosing:!0,spacing:n},6:{enter:({node:e})=>c(e)?`<br>`:void 0,isSelfClosing:!0,spacing:n,collapsesInnerWhiteSpace:!0,isInline:!0},7:u(1),8:u(2),9:u(3),10:u(4),11:u(5),12:u(6),13:{enter:()=>`---`,isSelfClosing:!0},14:d,15:d,16:f,17:f,18:{enter:()=>`~~`,exit:()=>`~~`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},19:{enter:()=>`<sub>`,exit:()=>`</sub>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},20:{enter:()=>`<sup>`,exit:()=>`</sup>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},21:{enter:()=>`<ins>`,exit:()=>`</ins>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},22:{enter:({node:e})=>{let t=e.depthMap[22]||1,n=`> `.repeat(t);return e.depthMap[25]>0&&(n=`\n${` `.repeat(e.depthMap[25])}${n}`),n},spacing:i},23:{enter:({node:e})=>(e.depthMap[34]||0)>0?`\`\`\`${l(e.attributes?.class)}\n`:"`",exit:({node:e})=>e.depthMap[34]>0?"\n```":"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},24:{enter:({node:e})=>c(e)?`<ul>`:void 0,exit:({node:e})=>c(e)?`</ul>`:void 0},25:{enter:({node:e})=>{if(c(e))return`<li>`;let t=(e.depthMap[24]||0)+(e.depthMap[33]||0)-1,n=e.parent?.tagId===33;return`${` `.repeat(Math.max(0,t))}${n?`${e.index+1}. `:`- `}`},exit:({node:e})=>c(e)?`</li>`:void 0,spacing:a},26:{enter:({node:e})=>{if(e.attributes?.href)return`[`},exit:({node:e,state:t})=>{if(!e.attributes?.href)return``;let n=s(e.attributes?.href||``,t.options?.origin),r=e.attributes?.title;return t.lastContentCache===r&&(r=``),r?`](${n} "${r}")`:`](${n})`},collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},27:{enter:({node:e,state:t})=>`})`,collapsesInnerWhiteSpace:!0,isSelfClosing:!0,spacing:n,isInline:!0},28:{enter:({node:e,state:t})=>{if(c(e))return`<table>`;e.depthMap[28]<=1&&(t.tableRenderedTable=!1),t.tableColumnAlignments=[]},exit:({node:e})=>c(e)?`</table>`:void 0},29:{enter:({node:e})=>{if(c(e))return`<thead>`},exit:({node:e})=>c(e)?`</thead>`:void 0,spacing:o,excludesTextNodes:!0},30:{enter:({node:e,state:t})=>c(e)?`<tr>`:(t.tableCurrentRowCells=0,`| `),exit:({node:e,state:t})=>{if(c(e)||e.depthMap[28]>1)return`</tr>`;if(!t.tableRenderedTable){t.tableRenderedTable=!0;let e=t.tableColumnAlignments;for(;e.length<t.tableCurrentRowCells;)e.push(``);return` |\n| ${e.map(e=>{switch(e){case`left`:return`:---`;case`center`:return`:---:`;case`right`:return`---:`;default:return`---`}}).join(` | `)} |`}return` |`},excludesTextNodes:!0,spacing:o},31:{enter:({node:e,state:t})=>{if(e.depthMap[28]>1)return`<th>`;let n=e.attributes?.align?.toLowerCase();return n?t.tableColumnAlignments.push(n):t.tableColumnAlignments.length<=t.tableCurrentRowCells&&t.tableColumnAlignments.push(``),e.index===0?``:` | `},exit:({node:e,state:t})=>{if(e.depthMap[28]>1)return`</th>`;t.tableCurrentRowCells++},collapsesInnerWhiteSpace:!0,spacing:n},32:{enter:({node:e})=>e.depthMap[28]>1?`<td>`:e.index===0?``:` | `,exit:({node:e,state:t})=>{if(e.depthMap[28]>1)return`</td>`;t.tableCurrentRowCells++},collapsesInnerWhiteSpace:!0,spacing:n},35:{enter:({node:e,state:t})=>{let n=e.depthMap[22];if(n>0){let e=t.buffer.at(-1),r=e?.charAt(e.length-1)||``;if(r&&r!==`
|
|
6
|
+
`&&r!==` `&&r!==`>`){let e=`> `.repeat(n);return`\n${e.trimEnd()}\n${e}`}}}},36:{},37:{collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},41:{},42:{collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},43:{collapsesInnerWhiteSpace:!0,isInline:!0},44:{spacing:n},45:{enter:({node:e})=>{if(e.depthMap[28]>1)return`<center>`},exit:({node:e})=>{if(e.depthMap[28]>1)return`</center>`},spacing:n},38:{spacing:n,excludesTextNodes:!0},39:{spacing:o,excludesTextNodes:!0},46:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},47:{spacing:n},40:{spacing:n},54:{isSelfClosing:!0,spacing:n,collapsesInnerWhiteSpace:!0,isInline:!0},55:{isSelfClosing:!0,spacing:n,isInline:!0},56:{isSelfClosing:!0,spacing:n,isInline:!0},57:{isSelfClosing:!0,spacing:n},58:{isSelfClosing:!0,spacing:n},59:{isSelfClosing:!0,spacing:n,isInline:!0},60:{isSelfClosing:!0,spacing:n,isInline:!0},61:{isSelfClosing:!0,spacing:n},62:{isSelfClosing:!0,spacing:n},63:{isSelfClosing:!0,spacing:n},64:{isSelfClosing:!0,spacing:n,isInline:!0},49:{spacing:n},65:{spacing:n},66:{isNonNesting:!0,spacing:n},67:{isNonNesting:!0,spacing:n},68:{spacing:n},69:{spacing:n},70:{spacing:n},71:{spacing:n},72:{spacing:n},73:{isNonNesting:!0,spacing:n},74:{spacing:n},75:{spacing:n},76:{spacing:n},77:{spacing:n},78:{spacing:n},79:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},80:{enter:()=>`<mark>`,exit:()=>`</mark>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},81:{enter:()=>`"`,exit:()=>`"`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},82:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},83:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},84:{excludesTextNodes:!0,spacing:n},85:{isNonNesting:!0,spacing:n},86:{isNonNesting:!0,spacing:n},87:{isNonNesting:!0,spacing:n},88:{spacing:n},89:{enter:()=>`<u>`,exit:()=>`</u>`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},90:{enter:()=>`*`,exit:()=>`*`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},91:{enter:()=>`**`,exit:()=>`**`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},92:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},93:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},94:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},95:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},96:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},97:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},100:{enter:()=>`<address>`,exit:()=>`</address>`,spacing:n,collapsesInnerWhiteSpace:!0},101:{spacing:n,enter:()=>`<dl>`,exit:()=>`</dl>`},99:{enter:()=>`<dt>`,exit:()=>`</dt>`,collapsesInnerWhiteSpace:!0,spacing:[0,1]},98:{enter:()=>`<dd>`,exit:()=>`</dd>`,spacing:[0,1]},102:{},106:{enter:()=>`_`,exit:()=>`_`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0}};function m(t){let n=``,r=0;for(;r<t.length;){if(t[r]===`&`){let i=!1;for(let[a,o]of Object.entries(e))if(t.startsWith(a,r)){n+=o,r+=a.length,i=!0;break}if(i)continue;if(r+2<t.length&&t[r+1]===`#`){let e=r;r+=2;let i=t[r]===`x`||t[r]===`X`;i&&r++;let a=r;for(;r<t.length&&t[r]!==`;`;)r++;if(r<t.length&&t[r]===`;`){let e=t.substring(a,r),o=i?16:10;try{let t=Number.parseInt(e,o);if(!Number.isNaN(t)){n+=String.fromCodePoint(t),r++;continue}}catch{}}r=e}}n+=t[r],r++}return n}function h(e){let t=e,n=[t];for(;t.tagHandler?.isInline&&t.parent;)t=t.parent,n.push(t);return n}const g=Object.freeze({});function _(e){return new Uint8Array(e)}function v(e){return e===32||e===9||e===10||e===13}function y(e,t,n){return b(e,t,n)}function b(e,n,r){let i=``;n.depthMap??=new Uint8Array(108),n.depth??=0,n.lastCharWasWhitespace??=!0,n.justClosedTag??=!1,n.isFirstTextInElement??=!1,n.lastCharWasBackslash??=!1;let a=0,o=e.length;for(;a<o;){let s=e.charCodeAt(a);if(s!==60){if(s===38&&(n.hasEncodedHtmlEntity=!0),v(s)){let t=n.depthMap[34]>0;if(n.justClosedTag&&(n.justClosedTag=!1,n.lastCharWasWhitespace=!1),!t&&n.lastCharWasWhitespace){a++;continue}t?i+=e[a]:(s===32||!n.lastCharWasWhitespace)&&(i+=` `),n.lastCharWasWhitespace=!0,n.textBufferContainsWhitespace=!0,n.lastCharWasBackslash=!1}else n.textBufferContainsNonWhitespace=!0,n.lastCharWasWhitespace=!1,n.justClosedTag=!1,s===124&&n.depthMap[28]?i+=`\\|`:s===96&&(n.depthMap[23]||n.depthMap[34])?i+="\\`":s===91&&n.depthMap[26]?i+=`\\[`:s===93&&n.depthMap[26]?i+=`\\]`:s===62&&n.depthMap[22]?i+=`\\>`:i+=e[a],n.currentNode?.tagHandler?.isNonNesting&&(n.lastCharWasBackslash||(s===39&&!n.inDoubleQuote&&!n.inBacktick?n.inSingleQuote=!n.inSingleQuote:s===34&&!n.inSingleQuote&&!n.inBacktick?n.inDoubleQuote=!n.inDoubleQuote:s===96&&!n.inSingleQuote&&!n.inDoubleQuote&&(n.inBacktick=!n.inBacktick))),n.lastCharWasBackslash=s===92;a++;continue}if(a+1>=o){i+=e[a];break}let c=e.charCodeAt(a+1);if(c===33){i.length>0&&(x(i,n,r),i=``);let t=w(e,a);if(t.complete)a=t.newPosition;else{i+=t.remainingText;break}}else if(c===47){let t=n.inSingleQuote||n.inDoubleQuote||n.inBacktick;if(n.currentNode?.tagHandler?.isNonNesting&&t){i+=e[a],a++;continue}i.length>0&&(x(i,n,r),i=``);let o=S(e,a,n,r);if(o.complete)a=o.newPosition;else{i+=o.remainingText;break}}else{let s=a+1,c=s,l=-1;for(;s<o;){let t=e.charCodeAt(s);if(v(t)||t===47||t===62){l=s;break}s++}if(l===-1){i+=e.substring(a);break}let u=e.substring(c,l).toLowerCase();if(!u){a=l;break}let d=t[u]??-1;if(s=l,n.currentNode?.tagHandler?.isNonNesting&&d!==n.currentNode?.tagId){i+=e[a++];continue}i.length>0&&(x(i,n,r),i=``);let f=T(u,d,e,s,n,r);if(f.skip)i+=e[a++];else if(f.complete)a=f.newPosition,f.selfClosing||(n.isFirstTextInElement=!0);else{i+=f.remainingText;break}}}return i}function x(e,t,n){let r=t.textBufferContainsNonWhitespace,i=t.textBufferContainsWhitespace;if(t.textBufferContainsNonWhitespace=!1,t.textBufferContainsWhitespace=!1,!t.currentNode)return;let a=t.currentNode?.tagHandler?.excludesTextNodes,o=t.depthMap[34]>0;if(!o&&!r&&!t.currentNode.childTextNodeIndex)return;let s=e;if(s.length===0)return;let c=h(t.currentNode),l=c.at(-1);if(i&&!l?.childTextNodeIndex){let e=0;for(;e<s.length&&(o?s.charCodeAt(e)===10||s.charCodeAt(e)===13:v(s.charCodeAt(e)));)e++;e>0&&(s=s.substring(e))}t.hasEncodedHtmlEntity&&=(s=m(String(s)),!1);let u={type:2,value:s,parent:t.currentNode,index:t.currentNode.currentWalkIndex++,depth:t.depth,containsWhitespace:i,excludedFromMarkdown:a};for(let e of c)e.childTextNodeIndex=(e.childTextNodeIndex||0)+1;n({type:0,node:u}),t.lastTextNode=u}function S(e,n,r,i){let a=n+2,o=a,s=e.length,c=!1;for(;a<s;){if(e.charCodeAt(a)===62){c=!0;break}a++}if(!c)return{complete:!1,newPosition:n,remainingText:e.substring(n)};let l=t[e.substring(o,a).toLowerCase()]??-1;if(r.currentNode?.tagHandler?.isNonNesting&&l!==r.currentNode.tagId)return{complete:!1,newPosition:n,remainingText:e.substring(n)};let u=r.currentNode;if(u){let e=u.tagId!==l;for(;u&&e;)C(u,r,i),u=u.parent,e=u?.tagId!==l}return u&&C(u,r,i),r.justClosedTag=!0,{complete:!0,newPosition:a+1,remainingText:``}}function C(e,t,n){if(e){if(e.tagId===26&&!e.childTextNodeIndex){let t=e.attributes?.title||e.attributes?.[`aria-label`]||``;if(t){e.childTextNodeIndex=1,n({type:0,node:{type:2,value:t,parent:e,index:0,depth:e.depth+1}});for(let t of h(e))t.childTextNodeIndex=(t.childTextNodeIndex||0)+1}}e.tagId&&(t.depthMap[e.tagId]=Math.max(0,t.depthMap[e.tagId]-1)),e.tagHandler?.isNonNesting&&(t.inSingleQuote=!1,t.inDoubleQuote=!1,t.inBacktick=!1,t.lastCharWasBackslash=!1),t.depth--,n({type:1,node:e}),t.currentNode=t.currentNode.parent,t.hasEncodedHtmlEntity=!1,t.justClosedTag=!0}}function w(e,t){let n=t,r=e.length;if(n+3<r&&e.charCodeAt(n+2)===45&&e.charCodeAt(n+3)===45){for(n+=4;n<r-2;){if(e.charCodeAt(n)===45&&e.charCodeAt(n+1)===45&&e.charCodeAt(n+2)===62)return n+=3,{complete:!0,newPosition:n,remainingText:``};n++}return{complete:!1,newPosition:t,remainingText:e.substring(t)}}else{for(n+=2;n<r;){if(e.charCodeAt(n)===62)return n++,{complete:!0,newPosition:n,remainingText:``};n++}return{complete:!1,newPosition:n,remainingText:e.substring(t,n)}}}function T(e,t,n,r,i,a){i.currentNode?.tagHandler?.isNonNesting&&C(i.currentNode,i,a);let o=p[t],s=E(n,r,o);if(!s.complete)return{complete:!1,newPosition:r,remainingText:`<${e}${s.attrBuffer}`,selfClosing:!1};let c=i.depthMap[t];i.depthMap[t]=c+1,i.depth++,r=s.newPosition,i.currentNode&&(i.currentNode.currentWalkIndex=i.currentNode.currentWalkIndex||0);let l=i.currentNode?i.currentNode.currentWalkIndex++:0,u={type:1,name:e,attributes:s.attributes,parent:i.currentNode,depthMap:_(i.depthMap),depth:i.depth,index:l,tagId:t,tagHandler:o};i.lastTextNode=u,a({type:0,node:u});let d=u;return d.currentWalkIndex=0,i.currentNode=d,i.hasEncodedHtmlEntity=!1,o?.isNonNesting&&!s.selfClosing&&(i.inSingleQuote=!1,i.inDoubleQuote=!1,i.inBacktick=!1,i.lastCharWasBackslash=!1),s.selfClosing?(C(u,i,a),i.justClosedTag=!0):i.justClosedTag=!1,{complete:!0,newPosition:r,remainingText:``,selfClosing:s.selfClosing}}function E(e,t,n){let r=t,i=e.length,a=n?.isSelfClosing||!1,o=r,s=!1,c=0,l=0;for(;r<i;){let t=e.charCodeAt(r);if(s){t===c&&l!==92&&(s=!1),r++;continue}else if(t===34||t===39)s=!0,c=t;else if(t===47&&r+1<i&&e.charCodeAt(r+1)===62){let t=e.substring(o,r).trim();return{complete:!0,newPosition:r+2,attributes:D(t),selfClosing:!0,attrBuffer:t}}else if(t===62){let t=e.substring(o,r).trim();return{complete:!0,newPosition:r+1,attributes:D(t),selfClosing:a,attrBuffer:t}}r++,l=t}return{complete:!1,newPosition:r,attributes:g,selfClosing:!1,attrBuffer:e.substring(o,r)}}function D(e){if(!e)return g;let t={},n=e.length,r=0,i=0,a=0,o=0,s=0,c=0,l=``;for(;r<n;){let u=e.charCodeAt(r),d=v(u);switch(i){case 0:d||(i=1,a=r,o=0);break;case 1:(u===61||d)&&(o=r,l=e.substring(a,o).toLowerCase(),i=u===61?3:2);break;case 2:u===61?i=3:d||(t[l]=``,i=1,a=r,o=0);break;case 3:u===34||u===39?(c=u,i=4,s=r+1):d||(i=5,s=r);break;case 4:u===92&&r+1<n?r++:u===c&&(t[l]=e.substring(s,r),i=0);break;case 5:(d||u===62)&&(t[l]=e.substring(s,r),i=0);break}r++}if(i===4||i===5)l&&(t[l]=e.substring(s,r));else if(i===1||i===2||i===3){o||=r;let n=e.substring(a,o).toLowerCase();n&&(t[n]=``)}return t}function O(e,t,n,r){if(t?.length){if(e.node.type===1&&e.type===0){let r=e.node;for(let e of t)e.processAttributes&&e.processAttributes(r,n)}let r=!1;for(let i of t){let t=i.beforeNodeProcess?.(e,n);typeof t==`object`&&(r=t.skip)}if(r)return!0;if(e.node.type===1){let r=e.node,i=e.type===0?`onNodeEnter`:`onNodeExit`,a=[];for(let e of t)if(e[i]){let t=e[i](r,n);t&&a.push(t)}a.length>0&&(r.pluginOutput=[...r.pluginOutput||[],...a])}else if(e.node.type===2&&e.type===0){let r=e.node;for(let e of t)if(e.processTextNode){let t=e.processTextNode(r,n);if(t){if(t.skip)return!0;r.value=t.content}}}}return r(e),!1}function k(e,t,n){if(e===` `||e===`
|
|
6
7
|
`||e===` `||t===` `||t===`
|
|
7
8
|
`||t===` `)return!1;let r=new Set([`[`,`(`,`>`,`*`,`_`,"`"]),i=new Set([`]`,`)`,`<`,`.`,`,`,`!`,`?`,`:`,`;`,`*`,`_`,"`"]);return e===`|`&&t===`<`&&n&&n.depthMap[28]>0?!0:!(r.has(e)||i.has(t))}function A(e,t,n){return!!e&&e!==`
|
|
8
|
-
`&&e!==` `&&e!==`[`&&e!==`>`&&!t?.tagHandler?.isInline&&n.value[0]!==` `}function j(e){let t=e.tagId,i=e.depthMap;if(t!==25&&i[25]>0||t!==22&&i[22]>0)return n;let a=t!==void 0&&(t>=7&&t<=12||t===35||t===36),o=e.parent;for(;o;){if(o.tagHandler?.collapsesInnerWhiteSpace){if(a&&o.tagId===37){o=o.parent;continue}return n}o=o.parent}return e.tagHandler?.spacing?e.tagHandler?.spacing:r}function M(e={}){let t={options:e,buffer:[],depthMap:new Uint8Array(108)},n=0;function r(e){let{type:n,node:r}=e,i=t.lastNode;t.lastNode=e.node,t.depth=r.depth;let a=t.buffer,o=a
|
|
9
|
+
`&&e!==` `&&e!==`[`&&e!==`>`&&!t?.tagHandler?.isInline&&n.value[0]!==` `}function j(e){let t=e.tagId,i=e.depthMap;if(t!==25&&i[25]>0||t!==22&&i[22]>0)return n;let a=t!==void 0&&(t>=7&&t<=12||t===35||t===36),o=e.parent;for(;o;){if(o.tagHandler?.collapsesInnerWhiteSpace){if(a&&o.tagId===37){o=o.parent;continue}return n}o=o.parent}return e.tagHandler?.spacing?e.tagHandler?.spacing:r}function M(e={}){let t={options:e,buffer:[],depthMap:new Uint8Array(108)},n=0;function r(e){let{type:n,node:r}=e,i=t.lastNode;t.lastNode=e.node,t.depth=r.depth;let a=t.buffer,o=a.at(-1),s=o?.charAt(o.length-1)||``,c;if(c=o?.length>1?o.charAt(o.length-2):a[a.length-2]?.charAt(a[a.length-2].length-1),r.type===2&&n===0){let e=r;if(e.value){if(e.excludedFromMarkdown||e.value===` `&&s===`
|
|
9
10
|
`)return;A(s,i,e)&&(e.value=` ${e.value}`),t.buffer.push(e.value),t.lastContentCache=e.value}t.lastTextNode=e;return}if(r.type!==1)return;let l={node:r,state:t},u=[],d=r;d.pluginOutput?.length&&(u.push(...d.pluginOutput),d.pluginOutput=[]);let f=t.lastContentCache,p=0;s===`
|
|
10
11
|
`&&p++,c===`
|
|
11
12
|
`&&p++;let m=n===0?`enter`:`exit`,h=r.tagHandler;if(!u.length&&h?.[m]){let e=h[m](l);e&&u.push(e)}let g=j(r)[n]||0,_=Math.max(0,g-p);if(_>0){if(!a.length){for(let e of u)e&&(t.buffer.push(e),t.lastContentCache=e);return}let e=`
|
|
12
|
-
`.repeat(_);s===` `&&a?.length&&(a[a.length-1]=a
|
|
13
|
+
`.repeat(_);s===` `&&a?.length&&(a[a.length-1]=a.at(-1).substring(0,a.at(-1).length-1)),n===0?u.unshift(e):u.push(e)}else if(f&&t.lastTextNode?.containsWhitespace&&r.parent&&`value`in t.lastTextNode&&typeof t.lastTextNode.value==`string`&&(!r.parent.depthMap[34]||r.parent.tagId===34)){let e=r.tagHandler?.isInline,i=r.tagHandler?.collapsesInnerWhiteSpace,o=r.tagHandler?.spacing&&Array.isArray(r.tagHandler.spacing);if((!e||n===1)&&!(!e&&!i&&g>0)&&!(i&&n===0)&&!(o&&n===0)){let e=f.length,t=f.trimEnd();e-t.length>0&&a?.length&&a.at(-1)===f&&(a[a.length-1]=t)}t.lastTextNode=void 0}u[0]?.[0]&&n===0&&s&&k(s,u[0][0],t)&&(t.buffer.push(` `),t.lastContentCache=` `);for(let e of u)e&&(t.buffer.push(e),t.lastContentCache=e)}function i(e){y(e,{depthMap:t.depthMap,depth:0,plugins:t.options?.plugins||[]},e=>{O(e,t.options?.plugins,t,r)})}function a(){let e=t.buffer.join(``).trimStart();return t.buffer.length=0,e.trimEnd()}function o(){let e=t.buffer.join(``).trimStart(),r=e.slice(n);return n=e.length,r}return{processEvent:r,processHtml:i,getMarkdown:a,getMarkdownChunk:o,state:t}}function N(e,t={}){let n=M(t);return n.processHtml(e),n.getMarkdown()}const P={htmlToMarkdown:N};typeof window<`u`&&(window.mdream=P);
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as parseHtml,
|
|
1
|
+
import { s as TagIdMap } from "./_chunks/const.mjs";
|
|
2
|
+
import { i as parseHtml, t as MarkdownProcessor } from "./_chunks/markdown-processor.mjs";
|
|
3
3
|
import { t as createPlugin } from "./_chunks/plugin.mjs";
|
|
4
|
-
import {
|
|
5
|
-
function htmlToMarkdown(html, options = {}) {
|
|
6
|
-
const processor = createMarkdownProcessor(options);
|
|
7
|
-
processor.processHtml(html);
|
|
8
|
-
return processor.getMarkdown();
|
|
9
|
-
}
|
|
4
|
+
import { n as streamHtmlToMarkdown, t as htmlToMarkdown } from "./_chunks/src.mjs";
|
|
10
5
|
export { MarkdownProcessor, TagIdMap, createPlugin, htmlToMarkdown, parseHtml, streamHtmlToMarkdown };
|