mdream 0.15.3 → 0.17.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.
@@ -1,7 +1,6 @@
1
- import { d as Plugin } from "./types.mjs";
1
+ import { u as Plugin } from "./types.mjs";
2
2
 
3
3
  //#region src/pluggable/plugin.d.ts
4
-
5
4
  /**
6
5
  * Create a plugin that implements the Plugin interface with improved type inference
7
6
  *
@@ -7,6 +7,5 @@
7
7
  function createPlugin(plugin) {
8
8
  return plugin;
9
9
  }
10
-
11
10
  //#endregion
12
- export { createPlugin as t };
11
+ export { createPlugin as t };
@@ -1,7 +1,5 @@
1
- import { $ as TAG_H2, $t as TAG_TBODY, A as TAG_BUTTON, At as TAG_P, Bt as TAG_SCRIPT, C as TAG_AUDIO, D as TAG_BLOCKQUOTE, Dt as TAG_OBJECT, F as TAG_CODE, G as TAG_EM, Gt as TAG_SPAN, H as TAG_DIV, Ht as TAG_SELECT, J as TAG_FIGCAPTION, K as TAG_EMBED, Kt as TAG_STRONG, L as TAG_DD, M as TAG_CAPTION, Nt as TAG_PRE, O as TAG_BODY, Ot as TAG_OL, Q as TAG_H1, Qt as TAG_TABLE, S as TAG_ASIDE, St as TAG_META, U as TAG_DL, Vt as TAG_SECTION, W as TAG_DT, X as TAG_FOOTER, Y as TAG_FIGURE, Yt as TAG_SUMMARY, Z as TAG_FORM, Zt as TAG_SVG, _ as TAG_A, _t as TAG_LI, an as TAG_THEAD, at as TAG_HEADER, bn as createBufferRegion, cn as TAG_TR, ct as TAG_I, dn as TAG_UL, dt as TAG_INPUT, en as TAG_TD, et as TAG_H3, gn as TEXT_NODE, in as TAG_TH, it as TAG_HEAD, k as TAG_BR, lt as TAG_IFRAME, nn as TAG_TEXTAREA, nt as TAG_H5, ot as TAG_HR, pn as TAG_VIDEO, q as TAG_FIELDSET, qt as TAG_STYLE, r as ELEMENT_NODE, rn as TAG_TFOOT, rt as TAG_H6, sn as TAG_TITLE, st as TAG_HTML, tt as TAG_H4, ut as TAG_IMG, w as TAG_B, wt as TAG_NAV, x as TAG_ARTICLE, y as TAG_ADDRESS, yn as collectNodeContent, yt as TAG_MAIN, z as TAG_DETAILS } from "./const.mjs";
2
1
  import { t as createPlugin } from "./plugin.mjs";
3
2
  import { n as parseSelector } from "./extraction.mjs";
4
-
5
3
  //#region src/plugins/filter.ts
6
4
  /**
7
5
  * Plugin that filters nodes based on CSS selectors.
@@ -27,15 +25,15 @@ function filterPlugin(options = {}) {
27
25
  const processChildren = options.processChildren !== false;
28
26
  return createPlugin({ beforeNodeProcess(event) {
29
27
  const { node } = event;
30
- if (node.type === TEXT_NODE) {
31
- let currentParent$1 = node.parent;
32
- while (currentParent$1 && excludeSelectors.length) {
33
- if (excludeSelectors.some((selector) => selector.matches(currentParent$1))) return { skip: true };
34
- currentParent$1 = currentParent$1.parent;
28
+ if (node.type === 2) {
29
+ let currentParent = node.parent;
30
+ while (currentParent && excludeSelectors.length) {
31
+ if (excludeSelectors.some((selector) => selector.matches(currentParent))) return { skip: true };
32
+ currentParent = currentParent.parent;
35
33
  }
36
34
  return;
37
35
  }
38
- if (node.type !== ELEMENT_NODE) return;
36
+ if (node.type !== 1) return;
39
37
  const element = node;
40
38
  if (excludeSelectors.length) {
41
39
  if (element.attributes.style?.includes("absolute") || element.attributes.style?.includes("fixed")) return { skip: true };
@@ -59,9 +57,9 @@ function filterPlugin(options = {}) {
59
57
  }
60
58
  } });
61
59
  }
62
-
63
60
  //#endregion
64
61
  //#region src/plugins/frontmatter.ts
62
+ const DOUBLE_QUOTE_RE = /"/g;
65
63
  /**
66
64
  * A plugin that manages frontmatter generation from HTML head elements
67
65
  * Extracts metadata from meta tags and title and generates YAML frontmatter
@@ -85,18 +83,18 @@ function frontmatterPlugin(options = {}) {
85
83
  };
86
84
  let inHead = false;
87
85
  const formatValue = options.formatValue || ((name, value) => {
88
- value = value.replace(/"/g, "\\\"");
86
+ value = value.replace(DOUBLE_QUOTE_RE, "\\\"");
89
87
  if (value.includes("\n") || value.includes(":") || value.includes("#") || value.includes(" ")) return `"${value}"`;
90
88
  return value;
91
89
  });
92
90
  return createPlugin({
93
91
  onNodeEnter(node) {
94
- if (node.tagId === TAG_HEAD) {
92
+ if (node.tagId === 1) {
95
93
  inHead = true;
96
94
  return;
97
95
  }
98
- if (inHead && node.type === ELEMENT_NODE && node.tagId === TAG_TITLE) return;
99
- if (inHead && node.type === ELEMENT_NODE && node.tagId === TAG_META) {
96
+ if (inHead && node.type === 1 && node.tagId === 4) return;
97
+ if (inHead && node.type === 1 && node.tagId === 5) {
100
98
  const { name, property, content } = node.attributes || {};
101
99
  const metaName = property || name;
102
100
  if (metaName && content && metaFields.has(metaName)) frontmatter.meta[metaName.includes(":") ? `"${metaName}"` : metaName] = formatValue(metaName, content);
@@ -104,18 +102,21 @@ function frontmatterPlugin(options = {}) {
104
102
  }
105
103
  },
106
104
  onNodeExit(node, state) {
107
- if (node.type === ELEMENT_NODE && node.tagId === TAG_HEAD) {
105
+ if (node.type === 1 && node.tagId === 1) {
108
106
  inHead = false;
109
- if (Object.keys(frontmatter).length > 0) collectNodeContent({
110
- type: 1,
111
- regionId: 0
112
- }, generateFrontmatter(), state);
107
+ if (Object.keys(frontmatter).length > 0) {
108
+ const frontmatterContent = generateFrontmatter();
109
+ if (frontmatterContent) {
110
+ state.buffer.push(frontmatterContent);
111
+ state.lastContentCache = frontmatterContent;
112
+ }
113
+ }
113
114
  }
114
115
  },
115
116
  processTextNode(node) {
116
117
  if (!inHead) return;
117
118
  const parent = node.parent;
118
- if (parent && parent.tagId === TAG_TITLE && node.value) {
119
+ if (parent && parent.tagId === 4 && node.value) {
119
120
  frontmatter.title = formatValue("title", node.value.trim());
120
121
  return {
121
122
  content: "",
@@ -146,7 +147,6 @@ function frontmatterPlugin(options = {}) {
146
147
  return `---\n${yamlLines.join("\n")}\n---\n\n`;
147
148
  }
148
149
  }
149
-
150
150
  //#endregion
151
151
  //#region src/plugins/isolate-main.ts
152
152
  /**
@@ -183,18 +183,18 @@ function isolateMainPlugin() {
183
183
  let firstHeaderElement = null;
184
184
  let afterFooter = false;
185
185
  const headerTagIds = new Set([
186
- TAG_H1,
187
- TAG_H2,
188
- TAG_H3,
189
- TAG_H4,
190
- TAG_H5,
191
- TAG_H6
186
+ 7,
187
+ 8,
188
+ 9,
189
+ 10,
190
+ 11,
191
+ 12
192
192
  ]);
193
193
  return createPlugin({ beforeNodeProcess(event) {
194
194
  const { node } = event;
195
- if (node.type === ELEMENT_NODE) {
195
+ if (node.type === 1) {
196
196
  const element = node;
197
- if (!mainElement && element.tagId === TAG_MAIN && element.depth <= 5) {
197
+ if (!mainElement && element.tagId === 104 && element.depth <= 5) {
198
198
  mainElement = element;
199
199
  return;
200
200
  }
@@ -215,7 +215,7 @@ function isolateMainPlugin() {
215
215
  let current = element.parent;
216
216
  let isInHeaderTag = false;
217
217
  while (current) {
218
- if (current.tagId === TAG_HEADER) {
218
+ if (current.tagId === 105) {
219
219
  isInHeaderTag = true;
220
220
  break;
221
221
  }
@@ -226,24 +226,24 @@ function isolateMainPlugin() {
226
226
  return;
227
227
  }
228
228
  }
229
- if (firstHeaderElement && !afterFooter && element.tagId === TAG_FOOTER) {
229
+ if (firstHeaderElement && !afterFooter && element.tagId === 47) {
230
230
  if (element.depth - firstHeaderElement.depth <= 5) {
231
231
  afterFooter = true;
232
232
  return { skip: true };
233
233
  }
234
234
  }
235
235
  if (!firstHeaderElement) {
236
- if (element.tagId === TAG_HEAD) return;
236
+ if (element.tagId === 1) return;
237
237
  let current = element.parent;
238
238
  while (current) {
239
- if (current.tagId === TAG_HEAD) return;
239
+ if (current.tagId === 1) return;
240
240
  current = current.parent;
241
241
  }
242
242
  return { skip: true };
243
243
  }
244
244
  if (afterFooter) return { skip: true };
245
245
  }
246
- if (node.type === TEXT_NODE) {
246
+ if (node.type === 2) {
247
247
  if (mainElement) {
248
248
  let current = node.parent;
249
249
  let isInsideMain = false;
@@ -260,7 +260,7 @@ function isolateMainPlugin() {
260
260
  if (!firstHeaderElement || afterFooter) {
261
261
  let current = node.parent;
262
262
  while (current) {
263
- if (current.tagId === TAG_HEAD) return;
263
+ if (current.tagId === 1) return;
264
264
  current = current.parent;
265
265
  }
266
266
  return { skip: true };
@@ -268,182 +268,6 @@ function isolateMainPlugin() {
268
268
  }
269
269
  } });
270
270
  }
271
-
272
- //#endregion
273
- //#region src/plugins/readability.ts
274
- const REGEXPS = {
275
- positive: /article|body|content|entry|main|page|post|text|blog|story|recipe|ingredient|instruction|description|docs?|guide|tutorial|reference|manual/i,
276
- negative: /ad|banner|combx|comment|disqus|extra|foot|header|menu|meta|nav|promo|related|scroll|share|sidebar|sponsor|social|tags|widget|sitemap|copyright|login|register|subscribe|newsletter|signup|category|author|date|publish|cta|button|apply|trial|likes|views|metrics|stats|breadcrumb|pagination|filter|sort|search/i,
277
- commas: /,/g,
278
- periodAtEnd: /\.( |$)/,
279
- hidden: /hidden|display:\s*none|visibility:\s*hidden/i,
280
- advertisement: /^ad-|^ad$|advertisement|sponsor|promo|banner/i,
281
- comments: /comment|disqus|replies/i
282
- };
283
- const TagScores = {
284
- [TAG_ARTICLE]: 15,
285
- [TAG_SECTION]: 8,
286
- [TAG_MAIN]: 15,
287
- [TAG_P]: 5,
288
- [TAG_DIV]: 2,
289
- [TAG_BLOCKQUOTE]: 5,
290
- [TAG_PRE]: 8,
291
- [TAG_CODE]: 6,
292
- [TAG_IMG]: 3,
293
- [TAG_FIGURE]: 4,
294
- [TAG_FIGCAPTION]: 3,
295
- [TAG_VIDEO]: 3,
296
- [TAG_AUDIO]: 3,
297
- [TAG_SVG]: 1,
298
- [TAG_TABLE]: 0,
299
- [TAG_CAPTION]: 2,
300
- [TAG_THEAD]: 0,
301
- [TAG_TBODY]: 0,
302
- [TAG_TFOOT]: 0,
303
- [TAG_TR]: -1,
304
- [TAG_TH]: -2,
305
- [TAG_TD]: 0,
306
- [TAG_UL]: -8,
307
- [TAG_OL]: -5,
308
- [TAG_LI]: -6,
309
- [TAG_DL]: 0,
310
- [TAG_DT]: 0,
311
- [TAG_DD]: 0,
312
- [TAG_H1]: 1,
313
- [TAG_H2]: 1,
314
- [TAG_H3]: 1,
315
- [TAG_H4]: 0,
316
- [TAG_H5]: 0,
317
- [TAG_H6]: 0,
318
- [TAG_HEADER]: -15,
319
- [TAG_FOOTER]: -25,
320
- [TAG_NAV]: -30,
321
- [TAG_ASIDE]: -25,
322
- [TAG_FORM]: -8,
323
- [TAG_BUTTON]: -5,
324
- [TAG_INPUT]: -5,
325
- [TAG_TEXTAREA]: -5,
326
- [TAG_SELECT]: -5,
327
- [TAG_FIELDSET]: -5,
328
- [TAG_IFRAME]: -3,
329
- [TAG_EMBED]: -3,
330
- [TAG_OBJECT]: -3,
331
- [TAG_A]: -8,
332
- [TAG_STRONG]: 1,
333
- [TAG_B]: 1,
334
- [TAG_EM]: 1,
335
- [TAG_I]: 1,
336
- [TAG_HR]: 0,
337
- [TAG_BR]: 0,
338
- [TAG_SPAN]: 0,
339
- [TAG_SCRIPT]: -25,
340
- [TAG_STYLE]: -25,
341
- [TAG_DETAILS]: 2,
342
- [TAG_SUMMARY]: 1,
343
- [TAG_ADDRESS]: -3
344
- };
345
- /**
346
- * Apply score adjustments based on class and ID names
347
- */
348
- function scoreClassAndId(node) {
349
- let scoreAdjustment = 0;
350
- if (node.attributes?.class) {
351
- const className = node.attributes.class;
352
- if (/nav|menu|header|footer|sidebar|ad-|advertisement|banner|promo|cta|button|apply|trial|engagement|sharing|likes|views|metrics|stats|breadcrumb|pagination|filter|sort|search/i.test(className)) scoreAdjustment -= 35;
353
- else if (REGEXPS.negative.test(className)) scoreAdjustment -= 15;
354
- else if (REGEXPS.positive.test(className)) {
355
- scoreAdjustment += 10;
356
- if (/docs?|guide|tutorial|reference|manual|article/i.test(className)) scoreAdjustment += 5;
357
- }
358
- }
359
- if (node.attributes?.id) {
360
- const id = node.attributes.id;
361
- if (/nav|menu|header|footer|sidebar|ad-|advertisement|banner|promo|cta|button|apply|trial|engagement|sharing|likes|views|metrics|stats|breadcrumb|pagination|filter|sort|search/i.test(id)) scoreAdjustment -= 35;
362
- else if (REGEXPS.negative.test(id)) scoreAdjustment -= 15;
363
- else if (REGEXPS.positive.test(id)) {
364
- scoreAdjustment += 10;
365
- if (/docs?|guide|tutorial|reference|manual|article/i.test(id)) scoreAdjustment += 5;
366
- }
367
- }
368
- return scoreAdjustment;
369
- }
370
- /**
371
- * Creates a plugin that implements readability.js style heuristics for content quality assessment
372
- * Controls content inclusion/exclusion using buffer regions
373
- */
374
- function readabilityPlugin() {
375
- let inHead = false;
376
- return createPlugin({
377
- onNodeEnter(node, state) {
378
- if (inHead) return;
379
- if (!node.context) node.context = {};
380
- if (node.tagId === TAG_BODY || node.tagId === TAG_HTML) return;
381
- if (node.tagId === TAG_HEAD) {
382
- createBufferRegion(node, state, true);
383
- inHead = true;
384
- return;
385
- }
386
- const tagScore = node.tagId !== void 0 ? TagScores[node.tagId] ?? 0 : 0;
387
- const classAndIdScore = scoreClassAndId(node);
388
- node.context.score = tagScore + classAndIdScore;
389
- node.context.tagCount = 1;
390
- node.context.linkTextLength = 0;
391
- node.context.textLength = 0;
392
- if (node.name && /nav|header|footer|aside|form|fieldset|button/i.test(node.name) || node.attributes?.class && /nav|menu|header|footer|sidebar|hidden|copyright|ad-|advertisement|banner|promo|related|comment|login|register|subscribe|newsletter|category|meta|tag|cta|button|apply|trial|engagement|sharing|likes|views|metrics|stats|breadcrumb|pagination|filter|sort|search/i.test(node.attributes.class) || node.attributes?.id && /nav|menu|header|footer|sidebar|hidden|copyright|ad-|advertisement|banner|promo|related|comment|login|register|subscribe|newsletter|category|meta|tag|cta|button|apply|trial|engagement|sharing|likes|views|metrics|stats|breadcrumb|pagination|filter|sort|search/i.test(node.attributes.id) || node.attributes?.style && /display:\s*none|visibility:\s*hidden/i.test(node.attributes.style) || node.attributes && Object.keys(node.attributes).some((attr) => attr.startsWith("aria-") && node.attributes[attr] === "true" && /hidden|invisible/i.test(attr))) createBufferRegion(node, state, false);
393
- else if (node.parent && node.parent.context) node.context.score = (node.context.score || 0) + (node.parent.context.score || 0);
394
- },
395
- processTextNode(node) {
396
- if (!node.parent || inHead) return void 0;
397
- const textValue = node.value;
398
- const len = textValue.length;
399
- const commaCount = Math.min(3, (textValue.match(REGEXPS.commas) || []).length);
400
- const isInsideLink = !!node.parent.depthMap?.[TAG_A];
401
- let parent = node.parent;
402
- while (parent) {
403
- if (!parent.context) parent.context = {};
404
- parent.context.score = (parent.context.score || 0) + commaCount;
405
- parent.context.textLength = (parent.context.textLength || 0) + len;
406
- if (isInsideLink) parent.context.linkTextLength = (parent.context.linkTextLength || 0) + len;
407
- parent = parent.parent;
408
- }
409
- },
410
- onNodeExit(node, state) {
411
- if (!node.context) return;
412
- if (node.tagId === TAG_BODY || node.tagId === TAG_HTML) return;
413
- if (node.tagId === TAG_HEAD) {
414
- inHead = false;
415
- return;
416
- }
417
- if (inHead) return;
418
- const textLength = node.context.textLength || 0;
419
- if (textLength === 0 && node.tagId !== TAG_BODY && !node.childTextNodeIndex) {} else if (textLength > 100) node.context.score = (node.context.score || 0) + 3;
420
- else if (textLength >= 50) node.context.score = (node.context.score || 0) + 2;
421
- else if (textLength >= 25) node.context.score = (node.context.score || 0) + 1;
422
- const linkTextLength = node.context.linkTextLength || 0;
423
- if (textLength > 0) {
424
- const linkDensity = linkTextLength / textLength;
425
- if (linkDensity > .4) if (linkDensity > .6) {
426
- node.context.score = (node.context.score || 0) * .02;
427
- if (linkTextLength > 50) node.context.isHighLinkDensity = true;
428
- } else node.context.score = (node.context.score || 0) * (1 - linkDensity * 2);
429
- else if (linkDensity > .2) node.context.score = (node.context.score || 0) * (1 - linkDensity * 1);
430
- }
431
- if (linkTextLength > 0 && textLength > 0) {
432
- const linkRatio = linkTextLength / textLength;
433
- const hasDocumentationMarkers = node.attributes?.class && /docs?|guide|tutorial|reference|manual|article|content/i.test(node.attributes.class) || node.attributes?.id && /docs?|guide|tutorial|reference|manual|article|content/i.test(node.attributes.id) || node.name && /main|article|section/i.test(node.name);
434
- if (linkRatio > .3 && linkTextLength > 30 && !hasDocumentationMarkers) node.context.score = (node.context.score || 0) - 10;
435
- }
436
- const finalScore = node.context.score || 0;
437
- if (finalScore <= -12) createBufferRegion(node, state, false);
438
- else if (node.context.isHighLinkDensity || linkTextLength > 50 && textLength > 0 && linkTextLength / textLength > .5) createBufferRegion(node, state, false);
439
- if (node.tagHandler?.isInline) {
440
- const parent = node.parent;
441
- if (parent && parent.context) parent.context.score = (parent.context.score || 0) + finalScore;
442
- }
443
- }
444
- });
445
- }
446
-
447
271
  //#endregion
448
272
  //#region src/plugins/tailwind.ts
449
273
  /**
@@ -519,7 +343,7 @@ function sortByBreakpoint(classes) {
519
343
  "xl:": 4,
520
344
  "2xl:": 5
521
345
  };
522
- return [...classes].sort((a, b) => {
346
+ return classes.toSorted((a, b) => {
523
347
  const aBreakpoint = extractBaseClass(a).breakpoint;
524
348
  const bBreakpoint = extractBaseClass(b).breakpoint;
525
349
  return breakpointOrder[aBreakpoint] - breakpointOrder[bBreakpoint];
@@ -655,7 +479,7 @@ function tailwindPlugin() {
655
479
  },
656
480
  processTextNode(node) {
657
481
  const parentNode = node.parent;
658
- if (!parentNode || parentNode.type !== ELEMENT_NODE) return;
482
+ if (!parentNode || parentNode.type !== 1) return;
659
483
  const tailwindData = parentNode.context?.tailwind;
660
484
  if (tailwindData?.hidden) return {
661
485
  content: "",
@@ -674,12 +498,11 @@ function tailwindPlugin() {
674
498
  };
675
499
  },
676
500
  beforeNodeProcess({ node }) {
677
- if (node.type === ELEMENT_NODE) {
501
+ if (node.type === 1) {
678
502
  if ((node.context?.tailwind)?.hidden) return { skip: true };
679
503
  }
680
504
  }
681
505
  });
682
506
  }
683
-
684
507
  //#endregion
685
- export { filterPlugin as a, frontmatterPlugin as i, readabilityPlugin as n, isolateMainPlugin as r, tailwindPlugin as t };
508
+ export { filterPlugin as i, isolateMainPlugin as n, frontmatterPlugin as r, tailwindPlugin as t };
@@ -1,5 +1,4 @@
1
1
  import { a as parseHtmlStream, n as createMarkdownProcessor, r as processPluginsForEvent } from "./markdown-processor.mjs";
2
-
3
2
  //#region src/stream.ts
4
3
  /**
5
4
  * Creates a markdown stream from an HTML stream
@@ -38,7 +37,6 @@ async function* streamHtmlToMarkdown(htmlStream, options = {}) {
38
37
  reader.releaseLock();
39
38
  }
40
39
  }
41
-
42
40
  //#endregion
43
41
  //#region src/index.ts
44
42
  function htmlToMarkdown(html, options = {}) {
@@ -46,6 +44,5 @@ function htmlToMarkdown(html, options = {}) {
46
44
  processor.processHtml(html);
47
45
  return processor.getMarkdown();
48
46
  }
49
-
50
47
  //#endregion
51
- export { streamHtmlToMarkdown as n, htmlToMarkdown as t };
48
+ export { streamHtmlToMarkdown as n, htmlToMarkdown as t };
@@ -22,7 +22,7 @@ interface Plugin {
22
22
  onNodeEnter?: (node: ElementNode, state: MdreamRuntimeState) => string | undefined | void;
23
23
  /**
24
24
  * Hook that runs when exiting a node
25
- * @param event - The node event
25
+ * @param node - The node event
26
26
  * @param state - The current runtime state
27
27
  * @returns String to add to the output, or PluginHookResult with content
28
28
  */
@@ -118,17 +118,6 @@ interface Node {
118
118
  parent?: ElementNode | null;
119
119
  /** Custom data added by plugins */
120
120
  context?: PluginContext;
121
- /** Region ID for buffer region tracking */
122
- regionId?: number;
123
- }
124
- /**
125
- * Buffer region for tracking content inclusion/exclusion
126
- */
127
- interface BufferRegion {
128
- /** Unique identifier */
129
- id: number;
130
- /** Inclusion state */
131
- include: boolean;
132
121
  }
133
122
  /**
134
123
  * State interface for HTML parsing and processing
@@ -182,10 +171,8 @@ interface MdreamRuntimeState extends Partial<MdreamProcessingState> {
182
171
  tableColumnAlignments?: string[];
183
172
  /** Plugin instances array for efficient iteration */
184
173
  plugins?: Plugin[];
185
- /** Map of region IDs to buffer regions for O(1) lookups */
186
- regionToggles: Map<number, boolean>;
187
- /** Content buffers for regions */
188
- regionContentBuffers: Map<number, string[]>;
174
+ /** Content buffer for markdown output */
175
+ buffer: string[];
189
176
  /** Performance cache for last content to avoid iteration */
190
177
  lastContentCache?: string;
191
178
  /** Reference to the last processed node */
@@ -260,11 +247,8 @@ interface MarkdownChunk {
260
247
  content: string;
261
248
  /** Metadata extracted during chunking */
262
249
  metadata: {
263
- /** Header hierarchy at this chunk position */
264
- headers?: Record<string, string>;
265
- /** Code block language if chunk is/contains code */
266
- code?: string;
267
- /** Line number range in original document */
250
+ /** Header hierarchy at this chunk position */headers?: Record<string, string>; /** Code block language if chunk is/contains code */
251
+ code?: string; /** Line number range in original document */
268
252
  loc?: {
269
253
  lines: {
270
254
  from: number;
@@ -317,4 +301,4 @@ interface SplitterOptions extends HTMLToMarkdownOptions {
317
301
  keepSeparator?: boolean;
318
302
  }
319
303
  //#endregion
320
- export { TagHandler as _, HandlerContext as a, ExtractedElement as b, MdreamRuntimeState as c, Plugin as d, PluginContext as f, TEXT_NODE as g, SplitterOptions as h, HTMLToMarkdownOptions as i, Node as l, ReadabilityContext as m, ELEMENT_NODE as n, MarkdownChunk as o, PluginCreationOptions as p, ElementNode as r, MdreamProcessingState as s, BufferRegion as t, NodeEvent as u, TailwindContext as v, extractionPlugin as x, TextNode as y };
304
+ export { TailwindContext as _, MarkdownChunk as a, extractionPlugin as b, Node as c, PluginContext as d, PluginCreationOptions as f, TagHandler as g, TEXT_NODE as h, HandlerContext as i, NodeEvent as l, SplitterOptions as m, ElementNode as n, MdreamProcessingState as o, ReadabilityContext as p, HTMLToMarkdownOptions as r, MdreamRuntimeState as s, ELEMENT_NODE as t, Plugin as u, TextNode as v, ExtractedElement as y };
package/dist/cli.mjs CHANGED
@@ -1,15 +1,17 @@
1
+ import "./_chunks/const.mjs";
1
2
  import "./_chunks/markdown-processor.mjs";
3
+ import "./_chunks/plugin.mjs";
2
4
  import { n as streamHtmlToMarkdown } from "./_chunks/src.mjs";
3
- import { n as generateLlmsTxtArtifacts } from "./_chunks/llms-txt.mjs";
5
+ import "./_chunks/extraction.mjs";
6
+ import { generateLlmsTxtArtifacts } from "./llms-txt.mjs";
4
7
  import "./_chunks/plugins.mjs";
5
- import { t as withMinimalPreset } from "./_chunks/minimal.mjs";
8
+ import { withMinimalPreset } from "./preset/minimal.mjs";
6
9
  import { readFileSync } from "node:fs";
7
10
  import { mkdir, writeFile } from "node:fs/promises";
8
11
  import { Readable } from "node:stream";
9
12
  import { fileURLToPath } from "node:url";
10
13
  import { cac } from "cac";
11
14
  import { dirname, join, resolve } from "pathe";
12
-
13
15
  //#region src/cli.ts
14
16
  async function streamingConvert(options = {}) {
15
17
  const outputStream = process.stdout;
@@ -61,6 +63,5 @@ cli.command("llms <patterns...>", "Generate llms.txt artifacts from HTML files")
61
63
  });
62
64
  });
63
65
  cli.help().version(version).parse();
64
-
65
66
  //#endregion
66
- export { };
67
+ export {};
package/dist/iife.js CHANGED
@@ -1,12 +1,12 @@
1
- function e(e,t,n){if(!t)return;let r=e.regionId||0,i=n.regionContentBuffers.get(r);i&&(i.push(t),n.lastContentCache=t)}function t(e){let t=[];for(let[n,r]of Array.from(e.regionContentBuffers.entries()))e.regionToggles.get(n)&&t.push(...r);return e.regionToggles.clear(),e.regionContentBuffers.clear(),t.join(``).trimStart()}const n={"&amp;":`&`,"&lt;":`<`,"&gt;":`>`,"&quot;":`"`,"&#39;":`'`,"&apos;":`'`,"&nbsp;":` `},r={html:0,head:1,details:2,summary:3,title:4,meta:5,br:6,h1:7,h2:8,h3:9,h4:10,h5:11,h6:12,hr:13,strong:14,b:15,em:16,i:17,del:18,sub:19,sup:20,ins:21,blockquote:22,code:23,ul:24,li:25,a:26,img:27,table:28,thead:29,tr:30,th:31,td:32,ol:33,pre:34,p:35,div:36,span:37,tbody:38,tfoot:39,form:40,nav:41,label:42,button:43,body:44,center:45,kbd:46,footer:47,path:48,svg:49,article:50,section:51,script:52,style:53,link:54,area:55,base:56,col:57,embed:58,input:59,keygen:60,param:61,source:62,track:63,wbr:64,select:65,textarea:66,option:67,fieldset:68,legend:69,audio:70,video:71,canvas:72,iframe:73,map:74,dialog:75,meter:76,progress:77,template:78,abbr:79,mark:80,q:81,samp:82,small:83,noscript:84,noframes:85,xmp:86,plaintext:87,aside:88,u:89,cite:90,dfn:91,var:92,time:93,bdo:94,ruby:95,rt:96,rp:97,dd:98,dt:99,dl:101,address:100,figure:102,object:103,main:104,header:105,figcaption:106,caption:107},i=[0,0],a=[2,2],o=[1,1],s=[1,0],c=[0,1];function l(e,t){if(!e)return e;if(e.startsWith(`//`))return`https:${e}`;if(e.startsWith(`#`))return e;if(t){if(e.startsWith(`/`)&&t)return`${t.endsWith(`/`)?t.slice(0,-1):t}${e}`;if(e.startsWith(`./`))return`${t}/${e.slice(2)}`;if(!e.startsWith(`http`))return`${t}/${e.startsWith(`/`)?e.slice(1):e}`}return e}function u(e){return e.depthMap[32]>0}function d(e){if(!e)return``;let t=e.split(` `).map(e=>e.split(`language-`)[1]).filter(Boolean);return t.length>0?t[0].trim():``}function f(e){return{enter:({node:t})=>t.depthMap[26]?`<h${e}>`:`${`#`.repeat(e)} `,exit:({node:t})=>{if(t.depthMap[26])return`</h${e}>`},collapsesInnerWhiteSpace:!0}}const p={enter:({node:e})=>e.depthMap[15]>1?``:`**`,exit:({node:e})=>e.depthMap[15]>1?``:`**`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},m={enter:({node:e})=>e.depthMap[17]>1?``:`_`,exit:({node:e})=>e.depthMap[17]>1?``:`_`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},h={1:{spacing:i,collapsesInnerWhiteSpace:!0},2:{enter:()=>`<details>`,exit:()=>`</details>
1
+ const e={"&amp;":`&`,"&lt;":`<`,"&gt;":`>`,"&quot;":`"`,"&#39;":`'`,"&apos;":`'`,"&nbsp;":` `},t={html:0,head:1,details:2,summary:3,title:4,meta:5,br:6,h1:7,h2:8,h3:9,h4:10,h5:11,h6:12,hr:13,strong:14,b:15,em:16,i:17,del:18,sub:19,sup:20,ins:21,blockquote:22,code:23,ul:24,li:25,a:26,img:27,table:28,thead:29,tr:30,th:31,td:32,ol:33,pre:34,p:35,div:36,span:37,tbody:38,tfoot:39,form:40,nav:41,label:42,button:43,body:44,center:45,kbd:46,footer:47,path:48,svg:49,article:50,section:51,script:52,style:53,link:54,area:55,base:56,col:57,embed:58,input:59,keygen:60,param:61,source:62,track:63,wbr:64,select:65,textarea:66,option:67,fieldset:68,legend:69,audio:70,video:71,canvas:72,iframe:73,map:74,dialog:75,meter:76,progress:77,template:78,abbr:79,mark:80,q:81,samp:82,small:83,noscript:84,noframes:85,xmp:86,plaintext:87,aside:88,u:89,cite:90,dfn:91,var:92,time:93,bdo:94,ruby:95,rt:96,rp:97,dd:98,dt:99,dl:101,address:100,figure:102,object:103,main:104,header:105,figcaption:106,caption:107},n=[0,0],r=[2,2],i=[1,1],a=[1,0],o=[0,1];function s(e,t){if(!e)return e;if(e.startsWith(`//`))return`https:${e}`;if(e.startsWith(`#`))return e;if(t){if(e.startsWith(`/`)&&t)return`${t.endsWith(`/`)?t.slice(0,-1):t}${e}`;if(e.startsWith(`./`))return`${t}/${e.slice(2)}`;if(!e.startsWith(`http`))return`${t}/${e.startsWith(`/`)?e.slice(1):e}`}return e}function c(e){return e.depthMap[32]>0}function l(e){if(!e)return``;let t=e.split(` `).map(e=>e.split(`language-`)[1]).filter(Boolean);return t.length>0?t[0].trim():``}function u(e){return{enter:({node:t})=>t.depthMap[26]?`<h${e}>`:`${`#`.repeat(e)} `,exit:({node:t})=>{if(t.depthMap[26])return`</h${e}>`},collapsesInnerWhiteSpace:!0}}const d={enter:({node:e})=>e.depthMap[15]>1?``:`**`,exit:({node:e})=>e.depthMap[15]>1?``:`**`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},f={enter:({node:e})=>e.depthMap[17]>1?``:`_`,exit:({node:e})=>e.depthMap[17]>1?``:`_`,collapsesInnerWhiteSpace:!0,spacing:n,isInline:!0},p={1:{spacing:n,collapsesInnerWhiteSpace:!0},2:{enter:()=>`<details>`,exit:()=>`</details>
2
2
 
3
3
  `},3:{enter:()=>`<summary>`,exit:()=>`</summary>
4
4
 
5
- `},4:{collapsesInnerWhiteSpace:!0,isNonNesting:!0,spacing:i},52:{excludesTextNodes:!0,isNonNesting:!0},53:{isNonNesting:!0,excludesTextNodes:!0},5:{collapsesInnerWhiteSpace:!0,isSelfClosing:!0,spacing:i},6:{enter:({node:e})=>u(e)?`<br>`:void 0,isSelfClosing:!0,spacing:i,collapsesInnerWhiteSpace:!0,isInline:!0},7:f(1),8:f(2),9:f(3),10:f(4),11:f(5),12:f(6),13:{enter:()=>`---`,isSelfClosing:!0},14:p,15:p,16:m,17:m,18:{enter:()=>`~~`,exit:()=>`~~`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},19:{enter:()=>`<sub>`,exit:()=>`</sub>`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},20:{enter:()=>`<sup>`,exit:()=>`</sup>`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},21:{enter:()=>`<ins>`,exit:()=>`</ins>`,collapsesInnerWhiteSpace:!0,spacing:i,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:o},23:{enter:({node:e})=>(e.depthMap[34]||0)>0?`\`\`\`${d(e.attributes?.class)}\n`:"`",exit:({node:e})=>e.depthMap[34]>0?"\n```":"`",collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},24:{enter:({node:e})=>u(e)?`<ul>`:void 0,exit:({node:e})=>u(e)?`</ul>`:void 0},25:{enter:({node:e})=>{if(u(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})=>u(e)?`</li>`:void 0,spacing:s},26:{enter:({node:e})=>{if(e.attributes?.href)return`[`},exit:({node:e,state:t})=>{if(!e.attributes?.href)return``;let n=l(e.attributes?.href||``,t.options?.origin),r=e.attributes?.title;return t.lastContentCache===r&&(r=``),r?`](${n} "${r}")`:`](${n})`},collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},27:{enter:({node:e,state:t})=>`![${e.attributes?.alt||``}](${l(e.attributes?.src||``,t.options?.origin)})`,collapsesInnerWhiteSpace:!0,isSelfClosing:!0,spacing:i,isInline:!0},28:{enter:({node:e,state:t})=>{if(u(e))return`<table>`;e.depthMap[28]<=1&&(t.tableRenderedTable=!1),t.tableColumnAlignments=[]},exit:({node:e})=>u(e)?`</table>`:void 0},29:{enter:({node:e})=>{if(u(e))return`<thead>`},exit:({node:e})=>u(e)?`</thead>`:void 0,spacing:c,excludesTextNodes:!0},30:{enter:({node:e,state:t})=>u(e)?`<tr>`:(t.tableCurrentRowCells=0,`| `),exit:({node:e,state:t})=>{if(u(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:c},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:i},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:i},35:{},36:{},37:{collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},41:{},42:{collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},43:{collapsesInnerWhiteSpace:!0,isInline:!0},44:{spacing:i},45:{enter:({node:e})=>{if(e.depthMap[28]>1)return`<center>`},exit:({node:e})=>{if(e.depthMap[28]>1)return`</center>`},spacing:i},38:{spacing:i,excludesTextNodes:!0},39:{spacing:c,excludesTextNodes:!0},46:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},47:{spacing:i},40:{spacing:i},54:{isSelfClosing:!0,spacing:i,collapsesInnerWhiteSpace:!0,isInline:!0},55:{isSelfClosing:!0,spacing:i,isInline:!0},56:{isSelfClosing:!0,spacing:i,isInline:!0},57:{isSelfClosing:!0,spacing:i},58:{isSelfClosing:!0,spacing:i},59:{isSelfClosing:!0,spacing:i,isInline:!0},60:{isSelfClosing:!0,spacing:i,isInline:!0},61:{isSelfClosing:!0,spacing:i},62:{isSelfClosing:!0,spacing:i},63:{isSelfClosing:!0,spacing:i},64:{isSelfClosing:!0,spacing:i,isInline:!0},49:{spacing:i},65:{spacing:i},66:{isNonNesting:!0,spacing:i},67:{isNonNesting:!0,spacing:i},68:{spacing:i},69:{spacing:i},70:{spacing:i},71:{spacing:i},72:{spacing:i},73:{isNonNesting:!0,spacing:i},74:{spacing:i},75:{spacing:i},76:{spacing:i},77:{spacing:i},78:{spacing:i},79:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},80:{enter:()=>`<mark>`,exit:()=>`</mark>`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},81:{enter:()=>`"`,exit:()=>`"`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},82:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},83:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},84:{excludesTextNodes:!0,spacing:i},85:{isNonNesting:!0,spacing:i},86:{isNonNesting:!0,spacing:i},87:{isNonNesting:!0,spacing:i},88:{spacing:i},89:{enter:()=>`<u>`,exit:()=>`</u>`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},90:{enter:()=>`*`,exit:()=>`*`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},91:{enter:()=>`**`,exit:()=>`**`,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},92:{enter:()=>"`",exit:()=>"`",collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},93:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},94:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},95:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},96:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},97:{enter:()=>``,exit:()=>``,collapsesInnerWhiteSpace:!0,spacing:i,isInline:!0},100:{enter:()=>`<address>`,exit:()=>`</address>`,spacing:i,collapsesInnerWhiteSpace:!0},101:{spacing:i,enter:()=>`<dl>`,exit:()=>`</dl>`},99:{enter:()=>`<dt>`,exit:()=>`</dt>`,collapsesInnerWhiteSpace:!0,spacing:[0,1]},98:{enter:()=>`<dd>`,exit:()=>`</dd>`,spacing:[0,1]}};function g(e){let t=``,r=0;for(;r<e.length;){if(e[r]===`&`){let i=!1;for(let[a,o]of Object.entries(n))if(e.startsWith(a,r)){t+=o,r+=a.length,i=!0;break}if(i)continue;if(r+2<e.length&&e[r+1]===`#`){let n=r;r+=2;let i=e[r]===`x`||e[r]===`X`;i&&r++;let a=r;for(;r<e.length&&e[r]!==`;`;)r++;if(r<e.length&&e[r]===`;`){let n=e.substring(a,r),o=i?16:10;try{let e=Number.parseInt(n,o);if(!Number.isNaN(e)){t+=String.fromCodePoint(e),r++;continue}}catch{}}r=n}}t+=e[r],r++}return t}function _(e){let t=e,n=[t];for(;t.tagHandler?.isInline&&t.parent;)t=t.parent,n.push(t);return n}const v=Object.freeze({});function y(e){return new Uint8Array(e)}function b(e){return e===32||e===9||e===10||e===13}function x(e,t,n){return S(e,t,n)}function S(e,t,n){let i=``;t.depthMap??=new Uint8Array(108),t.depth??=0,t.lastCharWasWhitespace??=!0,t.justClosedTag??=!1,t.isFirstTextInElement??=!1,t.lastCharWasBackslash??=!1;let a=0,o=e.length;for(;a<o;){let s=e.charCodeAt(a);if(s!==60){if(s===38&&(t.hasEncodedHtmlEntity=!0),b(s)){let n=t.depthMap[34]>0;if(t.justClosedTag&&(t.justClosedTag=!1,t.lastCharWasWhitespace=!1),!n&&t.lastCharWasWhitespace){a++;continue}n?i+=e[a]:(s===32||!t.lastCharWasWhitespace)&&(i+=` `),t.lastCharWasWhitespace=!0,t.textBufferContainsWhitespace=!0,t.lastCharWasBackslash=!1}else t.textBufferContainsNonWhitespace=!0,t.lastCharWasWhitespace=!1,t.justClosedTag=!1,s===124&&t.depthMap[28]?i+=`\\|`:s===96&&(t.depthMap[23]||t.depthMap[34])?i+="\\`":s===91&&t.depthMap[26]?i+=`\\[`:s===93&&t.depthMap[26]?i+=`\\]`:s===62&&t.depthMap[22]?i+=`\\>`:i+=e[a],t.currentNode?.tagHandler?.isNonNesting&&(t.lastCharWasBackslash||(s===39&&!t.inDoubleQuote&&!t.inBacktick?t.inSingleQuote=!t.inSingleQuote:s===34&&!t.inSingleQuote&&!t.inBacktick?t.inDoubleQuote=!t.inDoubleQuote:s===96&&!t.inSingleQuote&&!t.inDoubleQuote&&(t.inBacktick=!t.inBacktick))),t.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&&(C(i,t,n),i=``);let r=E(e,a);if(r.complete)a=r.newPosition;else{i+=r.remainingText;break}}else if(c===47){let r=t.inSingleQuote||t.inDoubleQuote||t.inBacktick;if(t.currentNode?.tagHandler?.isNonNesting&&r){i+=e[a],a++;continue}i.length>0&&(C(i,t,n),i=``);let o=w(e,a,t,n);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(b(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=r[u]??-1;if(s=l,t.currentNode?.tagHandler?.isNonNesting&&d!==t.currentNode?.tagId){i+=e[a++];continue}i.length>0&&(C(i,t,n),i=``);let f=D(u,d,e,s,t,n);if(f.skip)i+=e[a++];else if(f.complete)a=f.newPosition,f.selfClosing||(t.isFirstTextInElement=!0);else{i+=f.remainingText;break}}}return i}function C(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=_(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:b(s.charCodeAt(e)));)e++;e>0&&(s=s.substring(e))}t.hasEncodedHtmlEntity&&=(s=g(String(s)),!1);let u={type:2,value:s,parent:t.currentNode,regionId:t.currentNode?.regionId,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 w(e,t,n,i){let a=t+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:t,remainingText:e.substring(t)};let l=r[e.substring(o,a).toLowerCase()]??-1;if(n.currentNode?.tagHandler?.isNonNesting&&l!==n.currentNode.tagId)return{complete:!1,newPosition:t,remainingText:e.substring(t)};let u=n.currentNode;if(u){let e=u.tagId!==l;for(;u&&e;)T(u,n,i),u=u.parent,e=u?.tagId!==l}return u&&T(u,n,i),n.justClosedTag=!0,{complete:!0,newPosition:a+1,remainingText:``}}function T(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 _(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 E(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 D(e,t,n,r,i,a){i.currentNode?.tagHandler?.isNonNesting&&T(i.currentNode,i,a);let o=h[t],s=O(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:y(i.depthMap),depth:i.depth,index:l,regionId:i.currentNode?.regionId,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?(T(u,i,a),i.justClosedTag=!0):i.justClosedTag=!1,{complete:!0,newPosition:r,remainingText:``,selfClosing:s.selfClosing}}function O(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:k(t),selfClosing:!0,attrBuffer:t}}else if(t===62){let t=e.substring(o,r).trim();return{complete:!0,newPosition:r+1,attributes:k(t),selfClosing:a,attrBuffer:t}}r++,l=t}return{complete:!1,newPosition:r,attributes:v,selfClosing:!1,attrBuffer:e.substring(o,r)}}function k(e){if(!e)return v;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=b(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 A(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 j(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})=>`![${e.attributes?.alt||``}](${s(e.attributes?.src||``,t.options?.origin)})`,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]},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){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;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||[],...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
6
  `||e===` `||t===` `||t===`
7
- `||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 M(e,t,n){return!!e&&e!==`
8
- `&&e!==` `&&e!==`[`&&e!==`>`&&!t?.tagHandler?.isInline&&n.value[0]!==` `}function N(e){let t=e.tagId,n=e.depthMap;if(t!==25&&n[25]>0||t!==22&&n[22]>0)return i;let r=t!==void 0&&(t>=7&&t<=12||t===35||t===36),o=e.parent;for(;o;){if(o.tagHandler?.collapsesInnerWhiteSpace){if(r&&o.tagId===37){o=o.parent;continue}return i}o=o.parent}return e.tagHandler?.spacing?e.tagHandler?.spacing:a}function P(n={}){let r={options:n,regionToggles:new Map,regionContentBuffers:new Map,depthMap:new Uint8Array(108)};r.regionToggles.set(0,!0),r.regionContentBuffers.set(0,[]);let i=0;function a(t){let{type:n,node:i}=t,a=r.lastNode;r.lastNode=t.node,r.depth=i.depth;let o=r.regionContentBuffers.get(i.regionId||0)||[],s=o[o.length-1],c=s?.charAt(s.length-1)||``,l;if(l=s?.length>1?s.charAt(s.length-2):o[o.length-2]?.charAt(o[o.length-2].length-1),i.type===2&&n===0){let t=i;if(t.value){if(t.excludedFromMarkdown||t.value===` `&&c===`
9
- `)return;M(c,a,t)&&(t.value=` ${t.value}`),e(t,t.value,r)}r.lastTextNode=t;return}if(i.type!==1)return;let u={node:i,state:r},d=[],f=i;f.pluginOutput?.length&&(d.push(...f.pluginOutput),f.pluginOutput=[]);let p=r.lastContentCache,m=0;c===`
10
- `&&m++,l===`
11
- `&&m++;let h=n===0?`enter`:`exit`,g=i.tagHandler;if(!d.length&&g?.[h]){let e=g[h](u);e&&d.push(e)}let _=N(i)[n]||0,v=Math.max(0,_-m);if(v>0){if(!o.length){for(let t of d)e(i,t,r);return}let t=`
12
- `.repeat(v);c===` `&&o?.length&&(o[o.length-1]=o[o.length-1].substring(0,o[o.length-1].length-1)),n===0?d.unshift(t):d.push(t)}else if(p&&r.lastTextNode?.containsWhitespace&&i.parent&&`value`in r.lastTextNode&&typeof r.lastTextNode.value==`string`&&(!i.parent.depthMap[34]||i.parent.tagId===34)){let e=i.tagHandler?.isInline,t=i.tagHandler?.collapsesInnerWhiteSpace,a=i.tagHandler?.spacing&&Array.isArray(i.tagHandler.spacing);if((!e||n===1)&&!(!e&&!t&&_>0)&&!(t&&n===0)&&!(a&&n===0)){let e=p.length,t=p.trimEnd();e-t.length>0&&o?.length&&o[o.length-1]===p&&(o[o.length-1]=t)}r.lastTextNode=void 0}d[0]?.[0]&&n===0&&c&&j(c,d[0][0],r)&&e(i,` `,r);for(let t of d)e(i,t,r)}function o(e){x(e,{depthMap:r.depthMap,depth:0,plugins:r.options?.plugins||[]},e=>{A(e,r.options?.plugins,r,a)})}function s(){return t(r).trimEnd()}function c(){let e=[];for(let[t,n]of Array.from(r.regionContentBuffers.entries()))r.regionToggles.get(t)&&e.push(...n);let t=e.join(``).trimStart(),n=t.slice(i);return i=t.length,n}return{processEvent:a,processHtml:o,getMarkdown:s,getMarkdownChunk:c,state:r}}function F(e,t={}){let n=P(t);return n.processHtml(e),n.getMarkdown()}const I={htmlToMarkdown:F};typeof window<`u`&&(window.mdream=I);var L=I;
7
+ `||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.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
+ `)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
+ `&&p++,c===`
11
+ `&&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.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);