mdream 0.16.0 → 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,4 +1,5 @@
1
- import { $ as TAG_H5, $t as TAG_TH, A as TAG_CANVAS, At as TAG_PROGRESS, B as TAG_DIV, Bt as TAG_SPAN, C as TAG_B, D as TAG_BODY, Dt as TAG_PARAM, E as TAG_BLOCKQUOTE, Et as TAG_P, F as TAG_DD, Ft as TAG_SAMP, G as TAG_FIELDSET, Gt as TAG_SUP, H as TAG_DT, Ht as TAG_STYLE, I as TAG_DEL, It as TAG_SCRIPT, J as TAG_FORM, Jt as TAG_TBODY, Kt as TAG_SVG, L as TAG_DETAILS, Lt as TAG_SELECT, M as TAG_CITE, Mt as TAG_RP, N as TAG_CODE, Nt as TAG_RT, O as TAG_BR, Ot as TAG_PLAINTEXT, P as TAG_COL, Pt as TAG_RUBY, Q as TAG_H4, Qt as TAG_TFOOT, R as TAG_DFN, Rt as TAG_SMALL, S as TAG_AUDIO, St as TAG_NOSCRIPT, T as TAG_BDO, Tt as TAG_OPTION, U as TAG_EM, Ut as TAG_SUB, V as TAG_DL, Vt as TAG_STRONG, W as TAG_EMBED, Wt as TAG_SUMMARY, X as TAG_H2, Xt as TAG_TEMPLATE, Y as TAG_H1, Yt as TAG_TD, Z as TAG_H3, Zt as TAG_TEXTAREA, _ as TAG_A, _t as TAG_MARK, a as LIST_ITEM_SPACING, an as TAG_U, at as TAG_IFRAME, b as TAG_AREA, bt as TAG_NAV, c as MARKDOWN_HORIZONTAL_RULE, cn as TAG_VIDEO, ct as TAG_INS, d as MARKDOWN_STRONG, dn as TEXT_NODE, dt as TAG_LABEL, en as TAG_THEAD, et as TAG_H6, f as MAX_TAG_ID, fn as TagIdMap, ft as TAG_LEGEND, g as TABLE_ROW_SPACING, gt as TAG_MAP, h as NodeEventExit, i as HTML_ENTITIES, in as TAG_TRACK, it as TAG_I, j as TAG_CENTER, jt as TAG_Q, k as TAG_BUTTON, kt as TAG_PRE, l as MARKDOWN_INLINE_CODE, ln as TAG_WBR, lt as TAG_KBD, m as NodeEventEnter, mt as TAG_LINK, n as DEFAULT_BLOCK_SPACING, nn as TAG_TITLE, o as MARKDOWN_CODE_BLOCK, on as TAG_UL, ot as TAG_IMG, p as NO_SPACING, pt as TAG_LI, q as TAG_FOOTER, qt as TAG_TABLE, r as ELEMENT_NODE, rn as TAG_TR, rt as TAG_HR, s as MARKDOWN_EMPHASIS, sn as TAG_VAR, st as TAG_INPUT, t as BLOCKQUOTE_SPACING, tn as TAG_TIME, tt as TAG_HEAD, u as MARKDOWN_STRIKETHROUGH, un as TAG_XMP, ut as TAG_KEYGEN, v as TAG_ABBR, vt as TAG_META, w as TAG_BASE, wt as TAG_OL, x as TAG_ASIDE, xt as TAG_NOFRAMES, y as TAG_ADDRESS, yt as TAG_METER, z as TAG_DIALOG, zt as TAG_SOURCE } from "./const.mjs";
1
+ import { a as NO_SPACING, i as LIST_ITEM_SPACING, n as DEFAULT_BLOCK_SPACING, o as TABLE_ROW_SPACING, r as HTML_ENTITIES, s as TagIdMap, t as BLOCKQUOTE_SPACING } from "./const.mjs";
2
+ //#region src/tags.ts
2
3
  function resolveUrl(url, origin) {
3
4
  if (!url) return url;
4
5
  if (url.startsWith("//")) return `https:${url}`;
@@ -11,7 +12,7 @@ function resolveUrl(url, origin) {
11
12
  return url;
12
13
  }
13
14
  function isInsideTableCell(node) {
14
- return node.depthMap[TAG_TD] > 0;
15
+ return node.depthMap[32] > 0;
15
16
  }
16
17
  function getLanguageFromClass(className) {
17
18
  if (!className) return "";
@@ -21,23 +22,23 @@ function getLanguageFromClass(className) {
21
22
  function handleHeading(depth) {
22
23
  return {
23
24
  enter: ({ node }) => {
24
- if (node.depthMap[TAG_A]) return `<h${depth}>`;
25
+ if (node.depthMap[26]) return `<h${depth}>`;
25
26
  return `${"#".repeat(depth)} `;
26
27
  },
27
28
  exit: ({ node }) => {
28
- if (node.depthMap[TAG_A]) return `</h${depth}>`;
29
+ if (node.depthMap[26]) return `</h${depth}>`;
29
30
  },
30
31
  collapsesInnerWhiteSpace: true
31
32
  };
32
33
  }
33
34
  const Strong = {
34
35
  enter: ({ node }) => {
35
- if (node.depthMap[TAG_B] > 1) return "";
36
- return MARKDOWN_STRONG;
36
+ if (node.depthMap[15] > 1) return "";
37
+ return "**";
37
38
  },
38
39
  exit: ({ node }) => {
39
- if (node.depthMap[TAG_B] > 1) return "";
40
- return MARKDOWN_STRONG;
40
+ if (node.depthMap[15] > 1) return "";
41
+ return "**";
41
42
  },
42
43
  collapsesInnerWhiteSpace: true,
43
44
  spacing: NO_SPACING,
@@ -45,49 +46,49 @@ const Strong = {
45
46
  };
46
47
  const Emphasis = {
47
48
  enter: ({ node }) => {
48
- if (node.depthMap[TAG_I] > 1) return "";
49
- return MARKDOWN_EMPHASIS;
49
+ if (node.depthMap[17] > 1) return "";
50
+ return "_";
50
51
  },
51
52
  exit: ({ node }) => {
52
- if (node.depthMap[TAG_I] > 1) return "";
53
- return MARKDOWN_EMPHASIS;
53
+ if (node.depthMap[17] > 1) return "";
54
+ return "_";
54
55
  },
55
56
  collapsesInnerWhiteSpace: true,
56
57
  spacing: NO_SPACING,
57
58
  isInline: true
58
59
  };
59
60
  const tagHandlers = {
60
- [TAG_HEAD]: {
61
+ [1]: {
61
62
  spacing: NO_SPACING,
62
63
  collapsesInnerWhiteSpace: true
63
64
  },
64
- [TAG_DETAILS]: {
65
+ [2]: {
65
66
  enter: () => "<details>",
66
67
  exit: () => "</details>\n\n"
67
68
  },
68
- [TAG_SUMMARY]: {
69
+ [3]: {
69
70
  enter: () => "<summary>",
70
71
  exit: () => "</summary>\n\n"
71
72
  },
72
- [TAG_TITLE]: {
73
+ [4]: {
73
74
  collapsesInnerWhiteSpace: true,
74
75
  isNonNesting: true,
75
76
  spacing: NO_SPACING
76
77
  },
77
- [TAG_SCRIPT]: {
78
+ [52]: {
78
79
  excludesTextNodes: true,
79
80
  isNonNesting: true
80
81
  },
81
- [TAG_STYLE]: {
82
+ [53]: {
82
83
  isNonNesting: true,
83
84
  excludesTextNodes: true
84
85
  },
85
- [TAG_META]: {
86
+ [5]: {
86
87
  collapsesInnerWhiteSpace: true,
87
88
  isSelfClosing: true,
88
89
  spacing: NO_SPACING
89
90
  },
90
- [TAG_BR]: {
91
+ [6]: {
91
92
  enter: ({ node }) => {
92
93
  return isInsideTableCell(node) ? "<br>" : void 0;
93
94
  },
@@ -96,84 +97,84 @@ const tagHandlers = {
96
97
  collapsesInnerWhiteSpace: true,
97
98
  isInline: true
98
99
  },
99
- [TAG_H1]: handleHeading(1),
100
- [TAG_H2]: handleHeading(2),
101
- [TAG_H3]: handleHeading(3),
102
- [TAG_H4]: handleHeading(4),
103
- [TAG_H5]: handleHeading(5),
104
- [TAG_H6]: handleHeading(6),
105
- [TAG_HR]: {
106
- enter: () => MARKDOWN_HORIZONTAL_RULE,
100
+ [7]: handleHeading(1),
101
+ [8]: handleHeading(2),
102
+ [9]: handleHeading(3),
103
+ [10]: handleHeading(4),
104
+ [11]: handleHeading(5),
105
+ [12]: handleHeading(6),
106
+ [13]: {
107
+ enter: () => "---",
107
108
  isSelfClosing: true
108
109
  },
109
- [TAG_STRONG]: Strong,
110
- [TAG_B]: Strong,
111
- [TAG_EM]: Emphasis,
112
- [TAG_I]: Emphasis,
113
- [TAG_DEL]: {
114
- enter: () => MARKDOWN_STRIKETHROUGH,
115
- exit: () => MARKDOWN_STRIKETHROUGH,
110
+ [14]: Strong,
111
+ [15]: Strong,
112
+ [16]: Emphasis,
113
+ [17]: Emphasis,
114
+ [18]: {
115
+ enter: () => "~~",
116
+ exit: () => "~~",
116
117
  collapsesInnerWhiteSpace: true,
117
118
  spacing: NO_SPACING,
118
119
  isInline: true
119
120
  },
120
- [TAG_SUB]: {
121
+ [19]: {
121
122
  enter: () => "<sub>",
122
123
  exit: () => "</sub>",
123
124
  collapsesInnerWhiteSpace: true,
124
125
  spacing: NO_SPACING,
125
126
  isInline: true
126
127
  },
127
- [TAG_SUP]: {
128
+ [20]: {
128
129
  enter: () => "<sup>",
129
130
  exit: () => "</sup>",
130
131
  collapsesInnerWhiteSpace: true,
131
132
  spacing: NO_SPACING,
132
133
  isInline: true
133
134
  },
134
- [TAG_INS]: {
135
+ [21]: {
135
136
  enter: () => "<ins>",
136
137
  exit: () => "</ins>",
137
138
  collapsesInnerWhiteSpace: true,
138
139
  spacing: NO_SPACING,
139
140
  isInline: true
140
141
  },
141
- [TAG_BLOCKQUOTE]: {
142
+ [22]: {
142
143
  enter: ({ node }) => {
143
- const depth = node.depthMap[TAG_BLOCKQUOTE] || 1;
144
+ const depth = node.depthMap[22] || 1;
144
145
  let prefix = "> ".repeat(depth);
145
- if (node.depthMap[TAG_LI] > 0) prefix = `\n${" ".repeat(node.depthMap[TAG_LI])}${prefix}`;
146
+ if (node.depthMap[25] > 0) prefix = `\n${" ".repeat(node.depthMap[25])}${prefix}`;
146
147
  return prefix;
147
148
  },
148
149
  spacing: BLOCKQUOTE_SPACING
149
150
  },
150
- [TAG_CODE]: {
151
+ [23]: {
151
152
  enter: ({ node }) => {
152
- if ((node.depthMap[TAG_PRE] || 0) > 0) return `${MARKDOWN_CODE_BLOCK}${getLanguageFromClass(node.attributes?.class)}\n`;
153
- return MARKDOWN_INLINE_CODE;
153
+ if ((node.depthMap[34] || 0) > 0) return `\`\`\`${getLanguageFromClass(node.attributes?.class)}\n`;
154
+ return "`";
154
155
  },
155
156
  exit: ({ node }) => {
156
- return node.depthMap[TAG_PRE] > 0 ? `\n${MARKDOWN_CODE_BLOCK}` : MARKDOWN_INLINE_CODE;
157
+ return node.depthMap[34] > 0 ? `\n\`\`\`` : "`";
157
158
  },
158
159
  collapsesInnerWhiteSpace: true,
159
160
  spacing: NO_SPACING,
160
161
  isInline: true
161
162
  },
162
- [TAG_UL]: {
163
+ [24]: {
163
164
  enter: ({ node }) => isInsideTableCell(node) ? "<ul>" : void 0,
164
165
  exit: ({ node }) => isInsideTableCell(node) ? "</ul>" : void 0
165
166
  },
166
- [TAG_LI]: {
167
+ [25]: {
167
168
  enter: ({ node }) => {
168
169
  if (isInsideTableCell(node)) return "<li>";
169
- const depth = (node.depthMap[TAG_UL] || 0) + (node.depthMap[TAG_OL] || 0) - 1;
170
- const isOrdered = node.parent?.tagId === TAG_OL;
170
+ const depth = (node.depthMap[24] || 0) + (node.depthMap[33] || 0) - 1;
171
+ const isOrdered = node.parent?.tagId === 33;
171
172
  return `${" ".repeat(Math.max(0, depth))}${isOrdered ? `${node.index + 1}. ` : "- "}`;
172
173
  },
173
174
  exit: ({ node }) => isInsideTableCell(node) ? "</li>" : void 0,
174
175
  spacing: LIST_ITEM_SPACING
175
176
  },
176
- [TAG_A]: {
177
+ [26]: {
177
178
  enter: ({ node }) => {
178
179
  if (node.attributes?.href) return "[";
179
180
  },
@@ -188,7 +189,7 @@ const tagHandlers = {
188
189
  spacing: NO_SPACING,
189
190
  isInline: true
190
191
  },
191
- [TAG_IMG]: {
192
+ [27]: {
192
193
  enter: ({ node, state }) => {
193
194
  return `![${node.attributes?.alt || ""}](${resolveUrl(node.attributes?.src || "", state.options?.origin)})`;
194
195
  },
@@ -197,15 +198,15 @@ const tagHandlers = {
197
198
  spacing: NO_SPACING,
198
199
  isInline: true
199
200
  },
200
- [TAG_TABLE]: {
201
+ [28]: {
201
202
  enter: ({ node, state }) => {
202
203
  if (isInsideTableCell(node)) return "<table>";
203
- if (node.depthMap[TAG_TABLE] <= 1) state.tableRenderedTable = false;
204
+ if (node.depthMap[28] <= 1) state.tableRenderedTable = false;
204
205
  state.tableColumnAlignments = [];
205
206
  },
206
207
  exit: ({ node }) => isInsideTableCell(node) ? "</table>" : void 0
207
208
  },
208
- [TAG_THEAD]: {
209
+ [29]: {
209
210
  enter: ({ node }) => {
210
211
  if (isInsideTableCell(node)) return "<thead>";
211
212
  },
@@ -213,14 +214,14 @@ const tagHandlers = {
213
214
  spacing: TABLE_ROW_SPACING,
214
215
  excludesTextNodes: true
215
216
  },
216
- [TAG_TR]: {
217
+ [30]: {
217
218
  enter: ({ node, state }) => {
218
219
  if (isInsideTableCell(node)) return "<tr>";
219
220
  state.tableCurrentRowCells = 0;
220
221
  return "| ";
221
222
  },
222
223
  exit: ({ node, state }) => {
223
- if (isInsideTableCell(node) || node.depthMap[TAG_TABLE] > 1) return "</tr>";
224
+ if (isInsideTableCell(node) || node.depthMap[28] > 1) return "</tr>";
224
225
  if (!state.tableRenderedTable) {
225
226
  state.tableRenderedTable = true;
226
227
  const alignments = state.tableColumnAlignments;
@@ -239,205 +240,205 @@ const tagHandlers = {
239
240
  excludesTextNodes: true,
240
241
  spacing: TABLE_ROW_SPACING
241
242
  },
242
- [TAG_TH]: {
243
+ [31]: {
243
244
  enter: ({ node, state }) => {
244
- if (node.depthMap[TAG_TABLE] > 1) return "<th>";
245
+ if (node.depthMap[28] > 1) return "<th>";
245
246
  const align = node.attributes?.align?.toLowerCase();
246
247
  if (align) state.tableColumnAlignments.push(align);
247
248
  else if (state.tableColumnAlignments.length <= state.tableCurrentRowCells) state.tableColumnAlignments.push("");
248
249
  return node.index === 0 ? "" : " | ";
249
250
  },
250
251
  exit: ({ node, state }) => {
251
- if (node.depthMap[TAG_TABLE] > 1) return "</th>";
252
+ if (node.depthMap[28] > 1) return "</th>";
252
253
  state.tableCurrentRowCells++;
253
254
  },
254
255
  collapsesInnerWhiteSpace: true,
255
256
  spacing: NO_SPACING
256
257
  },
257
- [TAG_TD]: {
258
+ [32]: {
258
259
  enter: ({ node }) => {
259
- if (node.depthMap[TAG_TABLE] > 1) return "<td>";
260
+ if (node.depthMap[28] > 1) return "<td>";
260
261
  return node.index === 0 ? "" : " | ";
261
262
  },
262
263
  exit: ({ node, state }) => {
263
- if (node.depthMap[TAG_TABLE] > 1) return "</td>";
264
+ if (node.depthMap[28] > 1) return "</td>";
264
265
  state.tableCurrentRowCells++;
265
266
  },
266
267
  collapsesInnerWhiteSpace: true,
267
268
  spacing: NO_SPACING
268
269
  },
269
- [TAG_P]: {},
270
- [TAG_DIV]: {},
271
- [TAG_SPAN]: {
270
+ [35]: {},
271
+ [36]: {},
272
+ [37]: {
272
273
  collapsesInnerWhiteSpace: true,
273
274
  spacing: NO_SPACING,
274
275
  isInline: true
275
276
  },
276
- [TAG_NAV]: {},
277
- [TAG_LABEL]: {
277
+ [41]: {},
278
+ [42]: {
278
279
  collapsesInnerWhiteSpace: true,
279
280
  spacing: NO_SPACING,
280
281
  isInline: true
281
282
  },
282
- [TAG_BUTTON]: {
283
+ [43]: {
283
284
  collapsesInnerWhiteSpace: true,
284
285
  isInline: true
285
286
  },
286
- [TAG_BODY]: { spacing: NO_SPACING },
287
- [TAG_CENTER]: {
287
+ [44]: { spacing: NO_SPACING },
288
+ [45]: {
288
289
  enter: ({ node }) => {
289
- if (node.depthMap[TAG_TABLE] > 1) return "<center>";
290
+ if (node.depthMap[28] > 1) return "<center>";
290
291
  },
291
292
  exit: ({ node }) => {
292
- if (node.depthMap[TAG_TABLE] > 1) return "</center>";
293
+ if (node.depthMap[28] > 1) return "</center>";
293
294
  },
294
295
  spacing: NO_SPACING
295
296
  },
296
- [TAG_TBODY]: {
297
+ [38]: {
297
298
  spacing: NO_SPACING,
298
299
  excludesTextNodes: true
299
300
  },
300
- [TAG_TFOOT]: {
301
+ [39]: {
301
302
  spacing: TABLE_ROW_SPACING,
302
303
  excludesTextNodes: true
303
304
  },
304
- [TAG_KBD]: {
305
+ [46]: {
305
306
  enter: () => "`",
306
307
  exit: () => "`",
307
308
  collapsesInnerWhiteSpace: true,
308
309
  spacing: NO_SPACING,
309
310
  isInline: true
310
311
  },
311
- [TAG_FOOTER]: { spacing: NO_SPACING },
312
- [TAG_FORM]: { spacing: NO_SPACING },
313
- [TAG_LINK]: {
312
+ [47]: { spacing: NO_SPACING },
313
+ [40]: { spacing: NO_SPACING },
314
+ [54]: {
314
315
  isSelfClosing: true,
315
316
  spacing: NO_SPACING,
316
317
  collapsesInnerWhiteSpace: true,
317
318
  isInline: true
318
319
  },
319
- [TAG_AREA]: {
320
+ [55]: {
320
321
  isSelfClosing: true,
321
322
  spacing: NO_SPACING,
322
323
  isInline: true
323
324
  },
324
- [TAG_BASE]: {
325
+ [56]: {
325
326
  isSelfClosing: true,
326
327
  spacing: NO_SPACING,
327
328
  isInline: true
328
329
  },
329
- [TAG_COL]: {
330
+ [57]: {
330
331
  isSelfClosing: true,
331
332
  spacing: NO_SPACING
332
333
  },
333
- [TAG_EMBED]: {
334
+ [58]: {
334
335
  isSelfClosing: true,
335
336
  spacing: NO_SPACING
336
337
  },
337
- [TAG_INPUT]: {
338
+ [59]: {
338
339
  isSelfClosing: true,
339
340
  spacing: NO_SPACING,
340
341
  isInline: true
341
342
  },
342
- [TAG_KEYGEN]: {
343
+ [60]: {
343
344
  isSelfClosing: true,
344
345
  spacing: NO_SPACING,
345
346
  isInline: true
346
347
  },
347
- [TAG_PARAM]: {
348
+ [61]: {
348
349
  isSelfClosing: true,
349
350
  spacing: NO_SPACING
350
351
  },
351
- [TAG_SOURCE]: {
352
+ [62]: {
352
353
  isSelfClosing: true,
353
354
  spacing: NO_SPACING
354
355
  },
355
- [TAG_TRACK]: {
356
+ [63]: {
356
357
  isSelfClosing: true,
357
358
  spacing: NO_SPACING
358
359
  },
359
- [TAG_WBR]: {
360
+ [64]: {
360
361
  isSelfClosing: true,
361
362
  spacing: NO_SPACING,
362
363
  isInline: true
363
364
  },
364
- [TAG_SVG]: { spacing: NO_SPACING },
365
- [TAG_SELECT]: { spacing: NO_SPACING },
366
- [TAG_TEXTAREA]: {
365
+ [49]: { spacing: NO_SPACING },
366
+ [65]: { spacing: NO_SPACING },
367
+ [66]: {
367
368
  isNonNesting: true,
368
369
  spacing: NO_SPACING
369
370
  },
370
- [TAG_OPTION]: {
371
+ [67]: {
371
372
  isNonNesting: true,
372
373
  spacing: NO_SPACING
373
374
  },
374
- [TAG_FIELDSET]: { spacing: NO_SPACING },
375
- [TAG_LEGEND]: { spacing: NO_SPACING },
376
- [TAG_AUDIO]: { spacing: NO_SPACING },
377
- [TAG_VIDEO]: { spacing: NO_SPACING },
378
- [TAG_CANVAS]: { spacing: NO_SPACING },
379
- [TAG_IFRAME]: {
375
+ [68]: { spacing: NO_SPACING },
376
+ [69]: { spacing: NO_SPACING },
377
+ [70]: { spacing: NO_SPACING },
378
+ [71]: { spacing: NO_SPACING },
379
+ [72]: { spacing: NO_SPACING },
380
+ [73]: {
380
381
  isNonNesting: true,
381
382
  spacing: NO_SPACING
382
383
  },
383
- [TAG_MAP]: { spacing: NO_SPACING },
384
- [TAG_DIALOG]: { spacing: NO_SPACING },
385
- [TAG_METER]: { spacing: NO_SPACING },
386
- [TAG_PROGRESS]: { spacing: NO_SPACING },
387
- [TAG_TEMPLATE]: { spacing: NO_SPACING },
388
- [TAG_ABBR]: {
384
+ [74]: { spacing: NO_SPACING },
385
+ [75]: { spacing: NO_SPACING },
386
+ [76]: { spacing: NO_SPACING },
387
+ [77]: { spacing: NO_SPACING },
388
+ [78]: { spacing: NO_SPACING },
389
+ [79]: {
389
390
  enter: () => "",
390
391
  exit: () => "",
391
392
  collapsesInnerWhiteSpace: true,
392
393
  spacing: NO_SPACING,
393
394
  isInline: true
394
395
  },
395
- [TAG_MARK]: {
396
+ [80]: {
396
397
  enter: () => "<mark>",
397
398
  exit: () => "</mark>",
398
399
  collapsesInnerWhiteSpace: true,
399
400
  spacing: NO_SPACING,
400
401
  isInline: true
401
402
  },
402
- [TAG_Q]: {
403
+ [81]: {
403
404
  enter: () => "\"",
404
405
  exit: () => "\"",
405
406
  collapsesInnerWhiteSpace: true,
406
407
  spacing: NO_SPACING,
407
408
  isInline: true
408
409
  },
409
- [TAG_SAMP]: {
410
+ [82]: {
410
411
  enter: () => "`",
411
412
  exit: () => "`",
412
413
  collapsesInnerWhiteSpace: true,
413
414
  spacing: NO_SPACING,
414
415
  isInline: true
415
416
  },
416
- [TAG_SMALL]: {
417
+ [83]: {
417
418
  enter: () => "",
418
419
  exit: () => "",
419
420
  collapsesInnerWhiteSpace: true,
420
421
  spacing: NO_SPACING,
421
422
  isInline: true
422
423
  },
423
- [TAG_NOSCRIPT]: {
424
+ [84]: {
424
425
  excludesTextNodes: true,
425
426
  spacing: NO_SPACING
426
427
  },
427
- [TAG_NOFRAMES]: {
428
+ [85]: {
428
429
  isNonNesting: true,
429
430
  spacing: NO_SPACING
430
431
  },
431
- [TAG_XMP]: {
432
+ [86]: {
432
433
  isNonNesting: true,
433
434
  spacing: NO_SPACING
434
435
  },
435
- [TAG_PLAINTEXT]: {
436
+ [87]: {
436
437
  isNonNesting: true,
437
438
  spacing: NO_SPACING
438
439
  },
439
- [TAG_ASIDE]: { spacing: NO_SPACING },
440
- [TAG_U]: {
440
+ [88]: { spacing: NO_SPACING },
441
+ [89]: {
441
442
  enter: () => {
442
443
  return "<u>";
443
444
  },
@@ -448,85 +449,98 @@ const tagHandlers = {
448
449
  spacing: NO_SPACING,
449
450
  isInline: true
450
451
  },
451
- [TAG_CITE]: {
452
+ [90]: {
452
453
  enter: () => "*",
453
454
  exit: () => "*",
454
455
  collapsesInnerWhiteSpace: true,
455
456
  spacing: NO_SPACING,
456
457
  isInline: true
457
458
  },
458
- [TAG_DFN]: {
459
+ [91]: {
459
460
  enter: () => "**",
460
461
  exit: () => "**",
461
462
  collapsesInnerWhiteSpace: true,
462
463
  spacing: NO_SPACING,
463
464
  isInline: true
464
465
  },
465
- [TAG_VAR]: {
466
+ [92]: {
466
467
  enter: () => "`",
467
468
  exit: () => "`",
468
469
  collapsesInnerWhiteSpace: true,
469
470
  spacing: NO_SPACING,
470
471
  isInline: true
471
472
  },
472
- [TAG_TIME]: {
473
+ [93]: {
473
474
  enter: () => "",
474
475
  exit: () => "",
475
476
  collapsesInnerWhiteSpace: true,
476
477
  spacing: NO_SPACING,
477
478
  isInline: true
478
479
  },
479
- [TAG_BDO]: {
480
+ [94]: {
480
481
  enter: () => "",
481
482
  exit: () => "",
482
483
  collapsesInnerWhiteSpace: true,
483
484
  spacing: NO_SPACING,
484
485
  isInline: true
485
486
  },
486
- [TAG_RUBY]: {
487
+ [95]: {
487
488
  enter: () => "",
488
489
  exit: () => "",
489
490
  collapsesInnerWhiteSpace: true,
490
491
  spacing: NO_SPACING,
491
492
  isInline: true
492
493
  },
493
- [TAG_RT]: {
494
+ [96]: {
494
495
  enter: () => "",
495
496
  exit: () => "",
496
497
  collapsesInnerWhiteSpace: true,
497
498
  spacing: NO_SPACING,
498
499
  isInline: true
499
500
  },
500
- [TAG_RP]: {
501
+ [97]: {
501
502
  enter: () => "",
502
503
  exit: () => "",
503
504
  collapsesInnerWhiteSpace: true,
504
505
  spacing: NO_SPACING,
505
506
  isInline: true
506
507
  },
507
- [TAG_ADDRESS]: {
508
+ [100]: {
508
509
  enter: () => "<address>",
509
510
  exit: () => "</address>",
510
511
  spacing: NO_SPACING,
511
512
  collapsesInnerWhiteSpace: true
512
513
  },
513
- [TAG_DL]: {
514
+ [101]: {
514
515
  spacing: NO_SPACING,
515
516
  enter: () => "<dl>",
516
517
  exit: () => "</dl>"
517
518
  },
518
- [TAG_DT]: {
519
+ [99]: {
519
520
  enter: () => "<dt>",
520
521
  exit: () => "</dt>",
521
522
  collapsesInnerWhiteSpace: true,
522
523
  spacing: [0, 1]
523
524
  },
524
- [TAG_DD]: {
525
+ [98]: {
525
526
  enter: () => "<dd>",
526
527
  exit: () => "</dd>",
527
528
  spacing: [0, 1]
529
+ },
530
+ [102]: {},
531
+ [106]: {
532
+ enter: () => "_",
533
+ exit: () => "_",
534
+ collapsesInnerWhiteSpace: true,
535
+ spacing: NO_SPACING,
536
+ isInline: true
528
537
  }
529
538
  };
539
+ //#endregion
540
+ //#region src/utils.ts
541
+ /**
542
+ * Decode HTML entities - optimized version with single pass
543
+ */
530
544
  function decodeHTMLEntities(text) {
531
545
  let result = "";
532
546
  let i = 0;
@@ -577,6 +591,8 @@ function traverseUpToFirstBlockNode(node) {
577
591
  }
578
592
  return parentsToIncrement;
579
593
  }
594
+ //#endregion
595
+ //#region src/parse.ts
580
596
  const LT_CHAR = 60;
581
597
  const GT_CHAR = 62;
582
598
  const SLASH_CHAR = 47;
@@ -599,15 +615,22 @@ const EMPTY_ATTRIBUTES = Object.freeze({});
599
615
  function copyDepthMap(depthMap) {
600
616
  return new Uint8Array(depthMap);
601
617
  }
618
+ /**
619
+ * Fast whitespace check using direct character code comparison
620
+ */
602
621
  function isWhitespace(charCode) {
603
622
  return charCode === SPACE_CHAR || charCode === TAB_CHAR || charCode === NEWLINE_CHAR || charCode === CARRIAGE_RETURN_CHAR;
604
623
  }
624
+ /**
625
+ * Pure HTML parser that emits DOM events
626
+ * Completely decoupled from markdown generation
627
+ */
605
628
  function parseHtml(html, options = {}) {
606
629
  const events = [];
607
630
  return {
608
631
  events,
609
632
  remainingHtml: parseHtmlInternal(html, {
610
- depthMap: new Uint8Array(MAX_TAG_ID),
633
+ depthMap: new Uint8Array(108),
611
634
  depth: 0,
612
635
  plugins: options.plugins || []
613
636
  }, (event) => {
@@ -615,12 +638,18 @@ function parseHtml(html, options = {}) {
615
638
  })
616
639
  };
617
640
  }
641
+ /**
642
+ * Streaming HTML parser - calls onEvent for each DOM event
643
+ */
618
644
  function parseHtmlStream(html, state, onEvent) {
619
645
  return parseHtmlInternal(html, state, onEvent);
620
646
  }
647
+ /**
648
+ * Internal parsing function - extracted from original parseHTML
649
+ */
621
650
  function parseHtmlInternal(htmlChunk, state, handleEvent) {
622
651
  let textBuffer = "";
623
- state.depthMap ??= new Uint8Array(MAX_TAG_ID);
652
+ state.depthMap ??= new Uint8Array(108);
624
653
  state.depth ??= 0;
625
654
  state.lastCharWasWhitespace ??= true;
626
655
  state.justClosedTag ??= false;
@@ -633,7 +662,7 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
633
662
  if (currentCharCode !== LT_CHAR) {
634
663
  if (currentCharCode === AMPERSAND_CHAR) state.hasEncodedHtmlEntity = true;
635
664
  if (isWhitespace(currentCharCode)) {
636
- const inPreTag = state.depthMap[TAG_PRE] > 0;
665
+ const inPreTag = state.depthMap[34] > 0;
637
666
  if (state.justClosedTag) {
638
667
  state.justClosedTag = false;
639
668
  state.lastCharWasWhitespace = false;
@@ -651,11 +680,11 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
651
680
  state.textBufferContainsNonWhitespace = true;
652
681
  state.lastCharWasWhitespace = false;
653
682
  state.justClosedTag = false;
654
- if (currentCharCode === PIPE_CHAR && state.depthMap[TAG_TABLE]) textBuffer += "\\|";
655
- else if (currentCharCode === BACKTICK_CHAR && (state.depthMap[TAG_CODE] || state.depthMap[TAG_PRE])) textBuffer += "\\`";
656
- else if (currentCharCode === OPEN_BRACKET_CHAR && state.depthMap[TAG_A]) textBuffer += "\\[";
657
- else if (currentCharCode === CLOSE_BRACKET_CHAR && state.depthMap[TAG_A]) textBuffer += "\\]";
658
- else if (currentCharCode === GT_CHAR && state.depthMap[TAG_BLOCKQUOTE]) textBuffer += "\\>";
683
+ if (currentCharCode === PIPE_CHAR && state.depthMap[28]) textBuffer += "\\|";
684
+ else if (currentCharCode === BACKTICK_CHAR && (state.depthMap[23] || state.depthMap[34])) textBuffer += "\\`";
685
+ else if (currentCharCode === OPEN_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\[";
686
+ else if (currentCharCode === CLOSE_BRACKET_CHAR && state.depthMap[26]) textBuffer += "\\]";
687
+ else if (currentCharCode === GT_CHAR && state.depthMap[22]) textBuffer += "\\>";
659
688
  else textBuffer += htmlChunk[i];
660
689
  if (state.currentNode?.tagHandler?.isNonNesting) {
661
690
  if (!state.lastCharWasBackslash) {
@@ -748,6 +777,9 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
748
777
  }
749
778
  return textBuffer;
750
779
  }
780
+ /**
781
+ * Process accumulated text buffer and create text node event
782
+ */
751
783
  function processTextBuffer(textBuffer, state, handleEvent) {
752
784
  const containsNonWhitespace = state.textBufferContainsNonWhitespace;
753
785
  const containsWhitespace = state.textBufferContainsWhitespace;
@@ -755,12 +787,12 @@ function processTextBuffer(textBuffer, state, handleEvent) {
755
787
  state.textBufferContainsWhitespace = false;
756
788
  if (!state.currentNode) return;
757
789
  const excludesTextNodes = state.currentNode?.tagHandler?.excludesTextNodes;
758
- const inPreTag = state.depthMap[TAG_PRE] > 0;
790
+ const inPreTag = state.depthMap[34] > 0;
759
791
  if (!inPreTag && !containsNonWhitespace && !state.currentNode.childTextNodeIndex) return;
760
792
  let text = textBuffer;
761
793
  if (text.length === 0) return;
762
794
  const parentsToIncrement = traverseUpToFirstBlockNode(state.currentNode);
763
- const firstBlockParent = parentsToIncrement[parentsToIncrement.length - 1];
795
+ const firstBlockParent = parentsToIncrement.at(-1);
764
796
  if (containsWhitespace && !firstBlockParent?.childTextNodeIndex) {
765
797
  let start = 0;
766
798
  while (start < text.length && (inPreTag ? text.charCodeAt(start) === NEWLINE_CHAR || text.charCodeAt(start) === CARRIAGE_RETURN_CHAR : isWhitespace(text.charCodeAt(start)))) start++;
@@ -771,7 +803,7 @@ function processTextBuffer(textBuffer, state, handleEvent) {
771
803
  state.hasEncodedHtmlEntity = false;
772
804
  }
773
805
  const textNode = {
774
- type: TEXT_NODE,
806
+ type: 2,
775
807
  value: text,
776
808
  parent: state.currentNode,
777
809
  index: state.currentNode.currentWalkIndex++,
@@ -781,11 +813,14 @@ function processTextBuffer(textBuffer, state, handleEvent) {
781
813
  };
782
814
  for (const parent of parentsToIncrement) parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
783
815
  handleEvent({
784
- type: NodeEventEnter,
816
+ type: 0,
785
817
  node: textNode
786
818
  });
787
819
  state.lastTextNode = textNode;
788
820
  }
821
+ /**
822
+ * Process HTML closing tag
823
+ */
789
824
  function processClosingTag(htmlChunk, position, state, handleEvent) {
790
825
  let i = position + 2;
791
826
  const tagNameStart = i;
@@ -826,16 +861,19 @@ function processClosingTag(htmlChunk, position, state, handleEvent) {
826
861
  remainingText: ""
827
862
  };
828
863
  }
864
+ /**
865
+ * Close a node and emit exit event
866
+ */
829
867
  function closeNode(node, state, handleEvent) {
830
868
  if (!node) return;
831
- if (node.tagId === TAG_A && !node.childTextNodeIndex) {
869
+ if (node.tagId === 26 && !node.childTextNodeIndex) {
832
870
  const prefix = node.attributes?.title || node.attributes?.["aria-label"] || "";
833
871
  if (prefix) {
834
872
  node.childTextNodeIndex = 1;
835
873
  handleEvent({
836
- type: NodeEventEnter,
874
+ type: 0,
837
875
  node: {
838
- type: TEXT_NODE,
876
+ type: 2,
839
877
  value: prefix,
840
878
  parent: node,
841
879
  index: 0,
@@ -854,13 +892,16 @@ function closeNode(node, state, handleEvent) {
854
892
  }
855
893
  state.depth--;
856
894
  handleEvent({
857
- type: NodeEventExit,
895
+ type: 1,
858
896
  node
859
897
  });
860
898
  state.currentNode = state.currentNode.parent;
861
899
  state.hasEncodedHtmlEntity = false;
862
900
  state.justClosedTag = true;
863
901
  }
902
+ /**
903
+ * Process HTML comment or doctype
904
+ */
864
905
  function processCommentOrDoctype(htmlChunk, position) {
865
906
  let i = position;
866
907
  const chunkLength = htmlChunk.length;
@@ -902,6 +943,9 @@ function processCommentOrDoctype(htmlChunk, position) {
902
943
  };
903
944
  }
904
945
  }
946
+ /**
947
+ * Process HTML opening tag
948
+ */
905
949
  function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
906
950
  if (state.currentNode?.tagHandler?.isNonNesting) closeNode(state.currentNode, state, handleEvent);
907
951
  const tagHandler = tagHandlers[tagId];
@@ -919,7 +963,7 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
919
963
  if (state.currentNode) state.currentNode.currentWalkIndex = state.currentNode.currentWalkIndex || 0;
920
964
  const currentWalkIndex = state.currentNode ? state.currentNode.currentWalkIndex++ : 0;
921
965
  const tag = {
922
- type: ELEMENT_NODE,
966
+ type: 1,
923
967
  name: tagName,
924
968
  attributes: result.attributes,
925
969
  parent: state.currentNode,
@@ -931,7 +975,7 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
931
975
  };
932
976
  state.lastTextNode = tag;
933
977
  handleEvent({
934
- type: NodeEventEnter,
978
+ type: 0,
935
979
  node: tag
936
980
  });
937
981
  const parentNode = tag;
@@ -955,6 +999,9 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
955
999
  selfClosing: result.selfClosing
956
1000
  };
957
1001
  }
1002
+ /**
1003
+ * Extract and process HTML tag attributes
1004
+ */
958
1005
  function processTagAttributes(htmlChunk, position, tagHandler) {
959
1006
  let i = position;
960
1007
  const chunkLength = htmlChunk.length;
@@ -1002,6 +1049,9 @@ function processTagAttributes(htmlChunk, position, tagHandler) {
1002
1049
  attrBuffer: htmlChunk.substring(attrStartPos, i)
1003
1050
  };
1004
1051
  }
1052
+ /**
1053
+ * Parse HTML attributes string into key-value object
1054
+ */
1005
1055
  function parseAttributes(attrStr) {
1006
1056
  if (!attrStr) return EMPTY_ATTRIBUTES;
1007
1057
  const result = {};
@@ -1081,25 +1131,39 @@ function parseAttributes(attrStr) {
1081
1131
  }
1082
1132
  return result;
1083
1133
  }
1134
+ //#endregion
1135
+ //#region src/plugin-processor.ts
1136
+ /**
1137
+ * Processes plugins for a given node event
1138
+ * Shared logic between markdown-processor.ts and stream.ts
1139
+ *
1140
+ * @param event - The node event to process
1141
+ * @param plugins - Array of plugins to apply
1142
+ * @param state - The current runtime state
1143
+ * @param processEvent - Callback to process the event after plugin processing
1144
+ * @returns true if the event should be skipped, false to continue processing
1145
+ */
1084
1146
  function processPluginsForEvent(event, plugins, state, processEvent) {
1085
1147
  if (plugins?.length) {
1148
+ let shouldSkip = false;
1086
1149
  for (const plugin of plugins) {
1087
1150
  const res = plugin.beforeNodeProcess?.(event, state);
1088
- if (typeof res === "object" && res.skip) return true;
1151
+ if (typeof res === "object") shouldSkip = res.skip;
1089
1152
  }
1090
- if (event.node.type === ELEMENT_NODE) {
1153
+ if (shouldSkip) return true;
1154
+ if (event.node.type === 1) {
1091
1155
  const element = event.node;
1092
- if (event.type === NodeEventEnter) {
1156
+ if (event.type === 0) {
1093
1157
  for (const plugin of plugins) if (plugin.processAttributes) plugin.processAttributes(element, state);
1094
1158
  }
1095
- const fn = event.type === NodeEventEnter ? "onNodeEnter" : "onNodeExit";
1159
+ const fn = event.type === 0 ? "onNodeEnter" : "onNodeExit";
1096
1160
  const pluginOutputs = [];
1097
1161
  for (const plugin of plugins) if (plugin[fn]) {
1098
1162
  const result = plugin[fn](element, state);
1099
1163
  if (result) pluginOutputs.push(result);
1100
1164
  }
1101
- if (pluginOutputs.length > 0) element.pluginOutput = (element.pluginOutput || []).concat(pluginOutputs);
1102
- } else if (event.node.type === TEXT_NODE && event.type === NodeEventEnter) {
1165
+ if (pluginOutputs.length > 0) element.pluginOutput = [...element.pluginOutput || [], ...pluginOutputs];
1166
+ } else if (event.node.type === 2 && event.type === 0) {
1103
1167
  const textNode = event.node;
1104
1168
  for (const plugin of plugins) if (plugin.processTextNode) {
1105
1169
  const result = plugin.processTextNode(textNode, state);
@@ -1113,6 +1177,11 @@ function processPluginsForEvent(event, plugins, state, processEvent) {
1113
1177
  processEvent(event);
1114
1178
  return false;
1115
1179
  }
1180
+ //#endregion
1181
+ //#region src/markdown-processor.ts
1182
+ /**
1183
+ * Determines if spacing is needed between two characters
1184
+ */
1116
1185
  function needsSpacing(lastChar, firstChar, state) {
1117
1186
  if (lastChar === " " || lastChar === "\n" || lastChar === " ") return false;
1118
1187
  if (firstChar === " " || firstChar === "\n" || firstChar === " ") return false;
@@ -1138,22 +1207,28 @@ function needsSpacing(lastChar, firstChar, state) {
1138
1207
  "_",
1139
1208
  "`"
1140
1209
  ]);
1141
- if (lastChar === "|" && firstChar === "<" && state && state.depthMap[TAG_TABLE] > 0) return true;
1210
+ if (lastChar === "|" && firstChar === "<" && state && state.depthMap[28] > 0) return true;
1142
1211
  if (noSpaceAfter.has(lastChar) || noSpaceBefore.has(firstChar)) return false;
1143
1212
  return true;
1144
1213
  }
1214
+ /**
1215
+ * Determines if spacing should be added before text content
1216
+ */
1145
1217
  function shouldAddSpacingBeforeText(lastChar, lastNode, textNode) {
1146
1218
  return !!lastChar && lastChar !== "\n" && lastChar !== " " && lastChar !== "[" && lastChar !== ">" && !lastNode?.tagHandler?.isInline && textNode.value[0] !== " ";
1147
1219
  }
1220
+ /**
1221
+ * Calculate newline configuration based on tag handler spacing config
1222
+ */
1148
1223
  function calculateNewLineConfig(node) {
1149
1224
  const tagId = node.tagId;
1150
1225
  const depthMap = node.depthMap;
1151
- if (tagId !== TAG_LI && depthMap[TAG_LI] > 0 || tagId !== TAG_BLOCKQUOTE && depthMap[TAG_BLOCKQUOTE] > 0) return NO_SPACING;
1152
- const isBlockElement = tagId !== void 0 && (tagId >= TAG_H1 && tagId <= TAG_H6 || tagId === TAG_P || tagId === TAG_DIV);
1226
+ if (tagId !== 25 && depthMap[25] > 0 || tagId !== 22 && depthMap[22] > 0) return NO_SPACING;
1227
+ const isBlockElement = tagId !== void 0 && (tagId >= 7 && tagId <= 12 || tagId === 35 || tagId === 36);
1153
1228
  let currParent = node.parent;
1154
1229
  while (currParent) {
1155
1230
  if (currParent.tagHandler?.collapsesInnerWhiteSpace) {
1156
- if (isBlockElement && currParent.tagId === TAG_SPAN) {
1231
+ if (isBlockElement && currParent.tagId === 37) {
1157
1232
  currParent = currParent.parent;
1158
1233
  continue;
1159
1234
  }
@@ -1164,25 +1239,31 @@ function calculateNewLineConfig(node) {
1164
1239
  if (node.tagHandler?.spacing) return node.tagHandler?.spacing;
1165
1240
  return DEFAULT_BLOCK_SPACING;
1166
1241
  }
1242
+ /**
1243
+ * Creates a markdown processor that consumes DOM events and generates markdown
1244
+ */
1167
1245
  function createMarkdownProcessor(options = {}) {
1168
1246
  const state = {
1169
1247
  options,
1170
1248
  buffer: [],
1171
- depthMap: new Uint8Array(MAX_TAG_ID)
1249
+ depthMap: new Uint8Array(108)
1172
1250
  };
1173
1251
  let lastYieldedLength = 0;
1252
+ /**
1253
+ * Process a DOM event and generate markdown
1254
+ */
1174
1255
  function processEvent(event) {
1175
1256
  const { type: eventType, node } = event;
1176
1257
  const lastNode = state.lastNode;
1177
1258
  state.lastNode = event.node;
1178
1259
  state.depth = node.depth;
1179
1260
  const buff = state.buffer;
1180
- const lastBuffEntry = buff[buff.length - 1];
1261
+ const lastBuffEntry = buff.at(-1);
1181
1262
  const lastChar = lastBuffEntry?.charAt(lastBuffEntry.length - 1) || "";
1182
1263
  let secondLastChar;
1183
1264
  if (lastBuffEntry?.length > 1) secondLastChar = lastBuffEntry.charAt(lastBuffEntry.length - 2);
1184
1265
  else secondLastChar = buff[buff.length - 2]?.charAt(buff[buff.length - 2].length - 1);
1185
- if (node.type === TEXT_NODE && eventType === NodeEventEnter) {
1266
+ if (node.type === 2 && eventType === 0) {
1186
1267
  const textNode = node;
1187
1268
  if (textNode.value) {
1188
1269
  if (textNode.excludedFromMarkdown) return;
@@ -1194,7 +1275,7 @@ function createMarkdownProcessor(options = {}) {
1194
1275
  state.lastTextNode = textNode;
1195
1276
  return;
1196
1277
  }
1197
- if (node.type !== ELEMENT_NODE) return;
1278
+ if (node.type !== 1) return;
1198
1279
  const context = {
1199
1280
  node,
1200
1281
  state
@@ -1209,7 +1290,7 @@ function createMarkdownProcessor(options = {}) {
1209
1290
  let lastNewLines = 0;
1210
1291
  if (lastChar === "\n") lastNewLines++;
1211
1292
  if (secondLastChar === "\n") lastNewLines++;
1212
- const eventFn = eventType === NodeEventEnter ? "enter" : "exit";
1293
+ const eventFn = eventType === 0 ? "enter" : "exit";
1213
1294
  const handler = node.tagHandler;
1214
1295
  if (!output.length && handler?.[eventFn]) {
1215
1296
  const res = handler[eventFn](context);
@@ -1226,25 +1307,25 @@ function createMarkdownProcessor(options = {}) {
1226
1307
  return;
1227
1308
  }
1228
1309
  const newlinesStr = "\n".repeat(newLines);
1229
- if (lastChar === " " && buff?.length) buff[buff.length - 1] = buff[buff.length - 1].substring(0, buff[buff.length - 1].length - 1);
1230
- if (eventType === NodeEventEnter) output.unshift(newlinesStr);
1310
+ if (lastChar === " " && buff?.length) buff[buff.length - 1] = buff.at(-1).substring(0, buff.at(-1).length - 1);
1311
+ if (eventType === 0) output.unshift(newlinesStr);
1231
1312
  else output.push(newlinesStr);
1232
1313
  } else if (lastFragment && state.lastTextNode?.containsWhitespace && !!node.parent && "value" in state.lastTextNode && typeof state.lastTextNode.value === "string") {
1233
- if (!node.parent.depthMap[TAG_PRE] || node.parent.tagId === TAG_PRE) {
1314
+ if (!node.parent.depthMap[34] || node.parent.tagId === 34) {
1234
1315
  const isInlineElement = node.tagHandler?.isInline;
1235
1316
  const collapsesWhiteSpace = node.tagHandler?.collapsesInnerWhiteSpace;
1236
1317
  const hasSpacing = node.tagHandler?.spacing && Array.isArray(node.tagHandler.spacing);
1237
- if ((!isInlineElement || eventType === NodeEventExit) && !(!isInlineElement && !collapsesWhiteSpace && configuredNewLines > 0) && !(collapsesWhiteSpace && eventType === NodeEventEnter) && !(hasSpacing && eventType === NodeEventEnter)) {
1318
+ if ((!isInlineElement || eventType === 1) && !(!isInlineElement && !collapsesWhiteSpace && configuredNewLines > 0) && !(collapsesWhiteSpace && eventType === 0) && !(hasSpacing && eventType === 0)) {
1238
1319
  const originalLength = lastFragment.length;
1239
1320
  const trimmed = lastFragment.trimEnd();
1240
1321
  if (originalLength - trimmed.length > 0) {
1241
- if (buff?.length && buff[buff.length - 1] === lastFragment) buff[buff.length - 1] = trimmed;
1322
+ if (buff?.length && buff.at(-1) === lastFragment) buff[buff.length - 1] = trimmed;
1242
1323
  }
1243
1324
  }
1244
1325
  state.lastTextNode = void 0;
1245
1326
  }
1246
1327
  }
1247
- if (output[0]?.[0] && eventType === NodeEventEnter && lastChar && needsSpacing(lastChar, output[0][0], state)) {
1328
+ if (output[0]?.[0] && eventType === 0 && lastChar && needsSpacing(lastChar, output[0][0], state)) {
1248
1329
  state.buffer.push(" ");
1249
1330
  state.lastContentCache = " ";
1250
1331
  }
@@ -1253,6 +1334,9 @@ function createMarkdownProcessor(options = {}) {
1253
1334
  state.lastContentCache = fragment;
1254
1335
  }
1255
1336
  }
1337
+ /**
1338
+ * Process HTML string and generate events
1339
+ */
1256
1340
  function processHtml(html) {
1257
1341
  parseHtmlStream(html, {
1258
1342
  depthMap: state.depthMap,
@@ -1262,11 +1346,17 @@ function createMarkdownProcessor(options = {}) {
1262
1346
  processPluginsForEvent(event, state.options?.plugins, state, processEvent);
1263
1347
  });
1264
1348
  }
1349
+ /**
1350
+ * Get the final markdown output
1351
+ */
1265
1352
  function getMarkdown() {
1266
1353
  const result = state.buffer.join("").trimStart();
1267
1354
  state.buffer.length = 0;
1268
1355
  return result.trimEnd();
1269
1356
  }
1357
+ /**
1358
+ * Get new markdown content since the last call (for streaming)
1359
+ */
1270
1360
  function getMarkdownChunk() {
1271
1361
  const currentContent = state.buffer.join("").trimStart();
1272
1362
  const newContent = currentContent.slice(lastYieldedLength);
@@ -1282,4 +1372,5 @@ function createMarkdownProcessor(options = {}) {
1282
1372
  };
1283
1373
  }
1284
1374
  const MarkdownProcessor = createMarkdownProcessor;
1375
+ //#endregion
1285
1376
  export { parseHtmlStream as a, parseHtml as i, createMarkdownProcessor as n, processPluginsForEvent as r, MarkdownProcessor as t };