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.
- package/README.md +20 -10
- package/dist/_chunks/const.mjs +109 -268
- package/dist/_chunks/extraction.mjs +3 -5
- package/dist/_chunks/markdown-processor.mjs +195 -186
- package/dist/_chunks/plugin.d.mts +1 -2
- package/dist/_chunks/plugin.mjs +1 -2
- package/dist/_chunks/plugins.mjs +38 -215
- package/dist/_chunks/src.mjs +1 -4
- package/dist/_chunks/types.d.mts +6 -22
- package/dist/cli.mjs +6 -5
- package/dist/iife.js +8 -8
- package/dist/index.d.mts +4 -7
- package/dist/index.mjs +2 -3
- package/dist/llms-txt.mjs +468 -4
- package/dist/negotiate.d.mts +26 -0
- package/dist/negotiate.mjs +92 -0
- package/dist/plugins.d.mts +4 -15
- package/dist/plugins.mjs +3 -3
- package/dist/preset/minimal.d.mts +1 -2
- package/dist/preset/minimal.mjs +40 -4
- package/dist/splitter.d.mts +1 -2
- package/dist/splitter.mjs +26 -28
- package/package.json +10 -2
- package/dist/_chunks/llms-txt.mjs +0 -464
- package/dist/_chunks/minimal.mjs +0 -40
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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";
|
|
3
2
|
//#region src/tags.ts
|
|
4
3
|
function resolveUrl(url, origin) {
|
|
5
4
|
if (!url) return url;
|
|
@@ -13,7 +12,7 @@ function resolveUrl(url, origin) {
|
|
|
13
12
|
return url;
|
|
14
13
|
}
|
|
15
14
|
function isInsideTableCell(node) {
|
|
16
|
-
return node.depthMap[
|
|
15
|
+
return node.depthMap[32] > 0;
|
|
17
16
|
}
|
|
18
17
|
function getLanguageFromClass(className) {
|
|
19
18
|
if (!className) return "";
|
|
@@ -23,23 +22,23 @@ function getLanguageFromClass(className) {
|
|
|
23
22
|
function handleHeading(depth) {
|
|
24
23
|
return {
|
|
25
24
|
enter: ({ node }) => {
|
|
26
|
-
if (node.depthMap[
|
|
25
|
+
if (node.depthMap[26]) return `<h${depth}>`;
|
|
27
26
|
return `${"#".repeat(depth)} `;
|
|
28
27
|
},
|
|
29
28
|
exit: ({ node }) => {
|
|
30
|
-
if (node.depthMap[
|
|
29
|
+
if (node.depthMap[26]) return `</h${depth}>`;
|
|
31
30
|
},
|
|
32
31
|
collapsesInnerWhiteSpace: true
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
const Strong = {
|
|
36
35
|
enter: ({ node }) => {
|
|
37
|
-
if (node.depthMap[
|
|
38
|
-
return
|
|
36
|
+
if (node.depthMap[15] > 1) return "";
|
|
37
|
+
return "**";
|
|
39
38
|
},
|
|
40
39
|
exit: ({ node }) => {
|
|
41
|
-
if (node.depthMap[
|
|
42
|
-
return
|
|
40
|
+
if (node.depthMap[15] > 1) return "";
|
|
41
|
+
return "**";
|
|
43
42
|
},
|
|
44
43
|
collapsesInnerWhiteSpace: true,
|
|
45
44
|
spacing: NO_SPACING,
|
|
@@ -47,49 +46,49 @@ const Strong = {
|
|
|
47
46
|
};
|
|
48
47
|
const Emphasis = {
|
|
49
48
|
enter: ({ node }) => {
|
|
50
|
-
if (node.depthMap[
|
|
51
|
-
return
|
|
49
|
+
if (node.depthMap[17] > 1) return "";
|
|
50
|
+
return "_";
|
|
52
51
|
},
|
|
53
52
|
exit: ({ node }) => {
|
|
54
|
-
if (node.depthMap[
|
|
55
|
-
return
|
|
53
|
+
if (node.depthMap[17] > 1) return "";
|
|
54
|
+
return "_";
|
|
56
55
|
},
|
|
57
56
|
collapsesInnerWhiteSpace: true,
|
|
58
57
|
spacing: NO_SPACING,
|
|
59
58
|
isInline: true
|
|
60
59
|
};
|
|
61
60
|
const tagHandlers = {
|
|
62
|
-
[
|
|
61
|
+
[1]: {
|
|
63
62
|
spacing: NO_SPACING,
|
|
64
63
|
collapsesInnerWhiteSpace: true
|
|
65
64
|
},
|
|
66
|
-
[
|
|
65
|
+
[2]: {
|
|
67
66
|
enter: () => "<details>",
|
|
68
67
|
exit: () => "</details>\n\n"
|
|
69
68
|
},
|
|
70
|
-
[
|
|
69
|
+
[3]: {
|
|
71
70
|
enter: () => "<summary>",
|
|
72
71
|
exit: () => "</summary>\n\n"
|
|
73
72
|
},
|
|
74
|
-
[
|
|
73
|
+
[4]: {
|
|
75
74
|
collapsesInnerWhiteSpace: true,
|
|
76
75
|
isNonNesting: true,
|
|
77
76
|
spacing: NO_SPACING
|
|
78
77
|
},
|
|
79
|
-
[
|
|
78
|
+
[52]: {
|
|
80
79
|
excludesTextNodes: true,
|
|
81
80
|
isNonNesting: true
|
|
82
81
|
},
|
|
83
|
-
[
|
|
82
|
+
[53]: {
|
|
84
83
|
isNonNesting: true,
|
|
85
84
|
excludesTextNodes: true
|
|
86
85
|
},
|
|
87
|
-
[
|
|
86
|
+
[5]: {
|
|
88
87
|
collapsesInnerWhiteSpace: true,
|
|
89
88
|
isSelfClosing: true,
|
|
90
89
|
spacing: NO_SPACING
|
|
91
90
|
},
|
|
92
|
-
[
|
|
91
|
+
[6]: {
|
|
93
92
|
enter: ({ node }) => {
|
|
94
93
|
return isInsideTableCell(node) ? "<br>" : void 0;
|
|
95
94
|
},
|
|
@@ -98,84 +97,84 @@ const tagHandlers = {
|
|
|
98
97
|
collapsesInnerWhiteSpace: true,
|
|
99
98
|
isInline: true
|
|
100
99
|
},
|
|
101
|
-
[
|
|
102
|
-
[
|
|
103
|
-
[
|
|
104
|
-
[
|
|
105
|
-
[
|
|
106
|
-
[
|
|
107
|
-
[
|
|
108
|
-
enter: () =>
|
|
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: () => "---",
|
|
109
108
|
isSelfClosing: true
|
|
110
109
|
},
|
|
111
|
-
[
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[
|
|
115
|
-
[
|
|
116
|
-
enter: () =>
|
|
117
|
-
exit: () =>
|
|
110
|
+
[14]: Strong,
|
|
111
|
+
[15]: Strong,
|
|
112
|
+
[16]: Emphasis,
|
|
113
|
+
[17]: Emphasis,
|
|
114
|
+
[18]: {
|
|
115
|
+
enter: () => "~~",
|
|
116
|
+
exit: () => "~~",
|
|
118
117
|
collapsesInnerWhiteSpace: true,
|
|
119
118
|
spacing: NO_SPACING,
|
|
120
119
|
isInline: true
|
|
121
120
|
},
|
|
122
|
-
[
|
|
121
|
+
[19]: {
|
|
123
122
|
enter: () => "<sub>",
|
|
124
123
|
exit: () => "</sub>",
|
|
125
124
|
collapsesInnerWhiteSpace: true,
|
|
126
125
|
spacing: NO_SPACING,
|
|
127
126
|
isInline: true
|
|
128
127
|
},
|
|
129
|
-
[
|
|
128
|
+
[20]: {
|
|
130
129
|
enter: () => "<sup>",
|
|
131
130
|
exit: () => "</sup>",
|
|
132
131
|
collapsesInnerWhiteSpace: true,
|
|
133
132
|
spacing: NO_SPACING,
|
|
134
133
|
isInline: true
|
|
135
134
|
},
|
|
136
|
-
[
|
|
135
|
+
[21]: {
|
|
137
136
|
enter: () => "<ins>",
|
|
138
137
|
exit: () => "</ins>",
|
|
139
138
|
collapsesInnerWhiteSpace: true,
|
|
140
139
|
spacing: NO_SPACING,
|
|
141
140
|
isInline: true
|
|
142
141
|
},
|
|
143
|
-
[
|
|
142
|
+
[22]: {
|
|
144
143
|
enter: ({ node }) => {
|
|
145
|
-
const depth = node.depthMap[
|
|
144
|
+
const depth = node.depthMap[22] || 1;
|
|
146
145
|
let prefix = "> ".repeat(depth);
|
|
147
|
-
if (node.depthMap[
|
|
146
|
+
if (node.depthMap[25] > 0) prefix = `\n${" ".repeat(node.depthMap[25])}${prefix}`;
|
|
148
147
|
return prefix;
|
|
149
148
|
},
|
|
150
149
|
spacing: BLOCKQUOTE_SPACING
|
|
151
150
|
},
|
|
152
|
-
[
|
|
151
|
+
[23]: {
|
|
153
152
|
enter: ({ node }) => {
|
|
154
|
-
if ((node.depthMap[
|
|
155
|
-
return
|
|
153
|
+
if ((node.depthMap[34] || 0) > 0) return `\`\`\`${getLanguageFromClass(node.attributes?.class)}\n`;
|
|
154
|
+
return "`";
|
|
156
155
|
},
|
|
157
156
|
exit: ({ node }) => {
|
|
158
|
-
return node.depthMap[
|
|
157
|
+
return node.depthMap[34] > 0 ? `\n\`\`\`` : "`";
|
|
159
158
|
},
|
|
160
159
|
collapsesInnerWhiteSpace: true,
|
|
161
160
|
spacing: NO_SPACING,
|
|
162
161
|
isInline: true
|
|
163
162
|
},
|
|
164
|
-
[
|
|
163
|
+
[24]: {
|
|
165
164
|
enter: ({ node }) => isInsideTableCell(node) ? "<ul>" : void 0,
|
|
166
165
|
exit: ({ node }) => isInsideTableCell(node) ? "</ul>" : void 0
|
|
167
166
|
},
|
|
168
|
-
[
|
|
167
|
+
[25]: {
|
|
169
168
|
enter: ({ node }) => {
|
|
170
169
|
if (isInsideTableCell(node)) return "<li>";
|
|
171
|
-
const depth = (node.depthMap[
|
|
172
|
-
const isOrdered = node.parent?.tagId ===
|
|
170
|
+
const depth = (node.depthMap[24] || 0) + (node.depthMap[33] || 0) - 1;
|
|
171
|
+
const isOrdered = node.parent?.tagId === 33;
|
|
173
172
|
return `${" ".repeat(Math.max(0, depth))}${isOrdered ? `${node.index + 1}. ` : "- "}`;
|
|
174
173
|
},
|
|
175
174
|
exit: ({ node }) => isInsideTableCell(node) ? "</li>" : void 0,
|
|
176
175
|
spacing: LIST_ITEM_SPACING
|
|
177
176
|
},
|
|
178
|
-
[
|
|
177
|
+
[26]: {
|
|
179
178
|
enter: ({ node }) => {
|
|
180
179
|
if (node.attributes?.href) return "[";
|
|
181
180
|
},
|
|
@@ -190,7 +189,7 @@ const tagHandlers = {
|
|
|
190
189
|
spacing: NO_SPACING,
|
|
191
190
|
isInline: true
|
|
192
191
|
},
|
|
193
|
-
[
|
|
192
|
+
[27]: {
|
|
194
193
|
enter: ({ node, state }) => {
|
|
195
194
|
return `})`;
|
|
196
195
|
},
|
|
@@ -199,15 +198,15 @@ const tagHandlers = {
|
|
|
199
198
|
spacing: NO_SPACING,
|
|
200
199
|
isInline: true
|
|
201
200
|
},
|
|
202
|
-
[
|
|
201
|
+
[28]: {
|
|
203
202
|
enter: ({ node, state }) => {
|
|
204
203
|
if (isInsideTableCell(node)) return "<table>";
|
|
205
|
-
if (node.depthMap[
|
|
204
|
+
if (node.depthMap[28] <= 1) state.tableRenderedTable = false;
|
|
206
205
|
state.tableColumnAlignments = [];
|
|
207
206
|
},
|
|
208
207
|
exit: ({ node }) => isInsideTableCell(node) ? "</table>" : void 0
|
|
209
208
|
},
|
|
210
|
-
[
|
|
209
|
+
[29]: {
|
|
211
210
|
enter: ({ node }) => {
|
|
212
211
|
if (isInsideTableCell(node)) return "<thead>";
|
|
213
212
|
},
|
|
@@ -215,14 +214,14 @@ const tagHandlers = {
|
|
|
215
214
|
spacing: TABLE_ROW_SPACING,
|
|
216
215
|
excludesTextNodes: true
|
|
217
216
|
},
|
|
218
|
-
[
|
|
217
|
+
[30]: {
|
|
219
218
|
enter: ({ node, state }) => {
|
|
220
219
|
if (isInsideTableCell(node)) return "<tr>";
|
|
221
220
|
state.tableCurrentRowCells = 0;
|
|
222
221
|
return "| ";
|
|
223
222
|
},
|
|
224
223
|
exit: ({ node, state }) => {
|
|
225
|
-
if (isInsideTableCell(node) || node.depthMap[
|
|
224
|
+
if (isInsideTableCell(node) || node.depthMap[28] > 1) return "</tr>";
|
|
226
225
|
if (!state.tableRenderedTable) {
|
|
227
226
|
state.tableRenderedTable = true;
|
|
228
227
|
const alignments = state.tableColumnAlignments;
|
|
@@ -241,205 +240,205 @@ const tagHandlers = {
|
|
|
241
240
|
excludesTextNodes: true,
|
|
242
241
|
spacing: TABLE_ROW_SPACING
|
|
243
242
|
},
|
|
244
|
-
[
|
|
243
|
+
[31]: {
|
|
245
244
|
enter: ({ node, state }) => {
|
|
246
|
-
if (node.depthMap[
|
|
245
|
+
if (node.depthMap[28] > 1) return "<th>";
|
|
247
246
|
const align = node.attributes?.align?.toLowerCase();
|
|
248
247
|
if (align) state.tableColumnAlignments.push(align);
|
|
249
248
|
else if (state.tableColumnAlignments.length <= state.tableCurrentRowCells) state.tableColumnAlignments.push("");
|
|
250
249
|
return node.index === 0 ? "" : " | ";
|
|
251
250
|
},
|
|
252
251
|
exit: ({ node, state }) => {
|
|
253
|
-
if (node.depthMap[
|
|
252
|
+
if (node.depthMap[28] > 1) return "</th>";
|
|
254
253
|
state.tableCurrentRowCells++;
|
|
255
254
|
},
|
|
256
255
|
collapsesInnerWhiteSpace: true,
|
|
257
256
|
spacing: NO_SPACING
|
|
258
257
|
},
|
|
259
|
-
[
|
|
258
|
+
[32]: {
|
|
260
259
|
enter: ({ node }) => {
|
|
261
|
-
if (node.depthMap[
|
|
260
|
+
if (node.depthMap[28] > 1) return "<td>";
|
|
262
261
|
return node.index === 0 ? "" : " | ";
|
|
263
262
|
},
|
|
264
263
|
exit: ({ node, state }) => {
|
|
265
|
-
if (node.depthMap[
|
|
264
|
+
if (node.depthMap[28] > 1) return "</td>";
|
|
266
265
|
state.tableCurrentRowCells++;
|
|
267
266
|
},
|
|
268
267
|
collapsesInnerWhiteSpace: true,
|
|
269
268
|
spacing: NO_SPACING
|
|
270
269
|
},
|
|
271
|
-
[
|
|
272
|
-
[
|
|
273
|
-
[
|
|
270
|
+
[35]: {},
|
|
271
|
+
[36]: {},
|
|
272
|
+
[37]: {
|
|
274
273
|
collapsesInnerWhiteSpace: true,
|
|
275
274
|
spacing: NO_SPACING,
|
|
276
275
|
isInline: true
|
|
277
276
|
},
|
|
278
|
-
[
|
|
279
|
-
[
|
|
277
|
+
[41]: {},
|
|
278
|
+
[42]: {
|
|
280
279
|
collapsesInnerWhiteSpace: true,
|
|
281
280
|
spacing: NO_SPACING,
|
|
282
281
|
isInline: true
|
|
283
282
|
},
|
|
284
|
-
[
|
|
283
|
+
[43]: {
|
|
285
284
|
collapsesInnerWhiteSpace: true,
|
|
286
285
|
isInline: true
|
|
287
286
|
},
|
|
288
|
-
[
|
|
289
|
-
[
|
|
287
|
+
[44]: { spacing: NO_SPACING },
|
|
288
|
+
[45]: {
|
|
290
289
|
enter: ({ node }) => {
|
|
291
|
-
if (node.depthMap[
|
|
290
|
+
if (node.depthMap[28] > 1) return "<center>";
|
|
292
291
|
},
|
|
293
292
|
exit: ({ node }) => {
|
|
294
|
-
if (node.depthMap[
|
|
293
|
+
if (node.depthMap[28] > 1) return "</center>";
|
|
295
294
|
},
|
|
296
295
|
spacing: NO_SPACING
|
|
297
296
|
},
|
|
298
|
-
[
|
|
297
|
+
[38]: {
|
|
299
298
|
spacing: NO_SPACING,
|
|
300
299
|
excludesTextNodes: true
|
|
301
300
|
},
|
|
302
|
-
[
|
|
301
|
+
[39]: {
|
|
303
302
|
spacing: TABLE_ROW_SPACING,
|
|
304
303
|
excludesTextNodes: true
|
|
305
304
|
},
|
|
306
|
-
[
|
|
305
|
+
[46]: {
|
|
307
306
|
enter: () => "`",
|
|
308
307
|
exit: () => "`",
|
|
309
308
|
collapsesInnerWhiteSpace: true,
|
|
310
309
|
spacing: NO_SPACING,
|
|
311
310
|
isInline: true
|
|
312
311
|
},
|
|
313
|
-
[
|
|
314
|
-
[
|
|
315
|
-
[
|
|
312
|
+
[47]: { spacing: NO_SPACING },
|
|
313
|
+
[40]: { spacing: NO_SPACING },
|
|
314
|
+
[54]: {
|
|
316
315
|
isSelfClosing: true,
|
|
317
316
|
spacing: NO_SPACING,
|
|
318
317
|
collapsesInnerWhiteSpace: true,
|
|
319
318
|
isInline: true
|
|
320
319
|
},
|
|
321
|
-
[
|
|
320
|
+
[55]: {
|
|
322
321
|
isSelfClosing: true,
|
|
323
322
|
spacing: NO_SPACING,
|
|
324
323
|
isInline: true
|
|
325
324
|
},
|
|
326
|
-
[
|
|
325
|
+
[56]: {
|
|
327
326
|
isSelfClosing: true,
|
|
328
327
|
spacing: NO_SPACING,
|
|
329
328
|
isInline: true
|
|
330
329
|
},
|
|
331
|
-
[
|
|
330
|
+
[57]: {
|
|
332
331
|
isSelfClosing: true,
|
|
333
332
|
spacing: NO_SPACING
|
|
334
333
|
},
|
|
335
|
-
[
|
|
334
|
+
[58]: {
|
|
336
335
|
isSelfClosing: true,
|
|
337
336
|
spacing: NO_SPACING
|
|
338
337
|
},
|
|
339
|
-
[
|
|
338
|
+
[59]: {
|
|
340
339
|
isSelfClosing: true,
|
|
341
340
|
spacing: NO_SPACING,
|
|
342
341
|
isInline: true
|
|
343
342
|
},
|
|
344
|
-
[
|
|
343
|
+
[60]: {
|
|
345
344
|
isSelfClosing: true,
|
|
346
345
|
spacing: NO_SPACING,
|
|
347
346
|
isInline: true
|
|
348
347
|
},
|
|
349
|
-
[
|
|
348
|
+
[61]: {
|
|
350
349
|
isSelfClosing: true,
|
|
351
350
|
spacing: NO_SPACING
|
|
352
351
|
},
|
|
353
|
-
[
|
|
352
|
+
[62]: {
|
|
354
353
|
isSelfClosing: true,
|
|
355
354
|
spacing: NO_SPACING
|
|
356
355
|
},
|
|
357
|
-
[
|
|
356
|
+
[63]: {
|
|
358
357
|
isSelfClosing: true,
|
|
359
358
|
spacing: NO_SPACING
|
|
360
359
|
},
|
|
361
|
-
[
|
|
360
|
+
[64]: {
|
|
362
361
|
isSelfClosing: true,
|
|
363
362
|
spacing: NO_SPACING,
|
|
364
363
|
isInline: true
|
|
365
364
|
},
|
|
366
|
-
[
|
|
367
|
-
[
|
|
368
|
-
[
|
|
365
|
+
[49]: { spacing: NO_SPACING },
|
|
366
|
+
[65]: { spacing: NO_SPACING },
|
|
367
|
+
[66]: {
|
|
369
368
|
isNonNesting: true,
|
|
370
369
|
spacing: NO_SPACING
|
|
371
370
|
},
|
|
372
|
-
[
|
|
371
|
+
[67]: {
|
|
373
372
|
isNonNesting: true,
|
|
374
373
|
spacing: NO_SPACING
|
|
375
374
|
},
|
|
376
|
-
[
|
|
377
|
-
[
|
|
378
|
-
[
|
|
379
|
-
[
|
|
380
|
-
[
|
|
381
|
-
[
|
|
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]: {
|
|
382
381
|
isNonNesting: true,
|
|
383
382
|
spacing: NO_SPACING
|
|
384
383
|
},
|
|
385
|
-
[
|
|
386
|
-
[
|
|
387
|
-
[
|
|
388
|
-
[
|
|
389
|
-
[
|
|
390
|
-
[
|
|
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]: {
|
|
391
390
|
enter: () => "",
|
|
392
391
|
exit: () => "",
|
|
393
392
|
collapsesInnerWhiteSpace: true,
|
|
394
393
|
spacing: NO_SPACING,
|
|
395
394
|
isInline: true
|
|
396
395
|
},
|
|
397
|
-
[
|
|
396
|
+
[80]: {
|
|
398
397
|
enter: () => "<mark>",
|
|
399
398
|
exit: () => "</mark>",
|
|
400
399
|
collapsesInnerWhiteSpace: true,
|
|
401
400
|
spacing: NO_SPACING,
|
|
402
401
|
isInline: true
|
|
403
402
|
},
|
|
404
|
-
[
|
|
403
|
+
[81]: {
|
|
405
404
|
enter: () => "\"",
|
|
406
405
|
exit: () => "\"",
|
|
407
406
|
collapsesInnerWhiteSpace: true,
|
|
408
407
|
spacing: NO_SPACING,
|
|
409
408
|
isInline: true
|
|
410
409
|
},
|
|
411
|
-
[
|
|
410
|
+
[82]: {
|
|
412
411
|
enter: () => "`",
|
|
413
412
|
exit: () => "`",
|
|
414
413
|
collapsesInnerWhiteSpace: true,
|
|
415
414
|
spacing: NO_SPACING,
|
|
416
415
|
isInline: true
|
|
417
416
|
},
|
|
418
|
-
[
|
|
417
|
+
[83]: {
|
|
419
418
|
enter: () => "",
|
|
420
419
|
exit: () => "",
|
|
421
420
|
collapsesInnerWhiteSpace: true,
|
|
422
421
|
spacing: NO_SPACING,
|
|
423
422
|
isInline: true
|
|
424
423
|
},
|
|
425
|
-
[
|
|
424
|
+
[84]: {
|
|
426
425
|
excludesTextNodes: true,
|
|
427
426
|
spacing: NO_SPACING
|
|
428
427
|
},
|
|
429
|
-
[
|
|
428
|
+
[85]: {
|
|
430
429
|
isNonNesting: true,
|
|
431
430
|
spacing: NO_SPACING
|
|
432
431
|
},
|
|
433
|
-
[
|
|
432
|
+
[86]: {
|
|
434
433
|
isNonNesting: true,
|
|
435
434
|
spacing: NO_SPACING
|
|
436
435
|
},
|
|
437
|
-
[
|
|
436
|
+
[87]: {
|
|
438
437
|
isNonNesting: true,
|
|
439
438
|
spacing: NO_SPACING
|
|
440
439
|
},
|
|
441
|
-
[
|
|
442
|
-
[
|
|
440
|
+
[88]: { spacing: NO_SPACING },
|
|
441
|
+
[89]: {
|
|
443
442
|
enter: () => {
|
|
444
443
|
return "<u>";
|
|
445
444
|
},
|
|
@@ -450,86 +449,93 @@ const tagHandlers = {
|
|
|
450
449
|
spacing: NO_SPACING,
|
|
451
450
|
isInline: true
|
|
452
451
|
},
|
|
453
|
-
[
|
|
452
|
+
[90]: {
|
|
454
453
|
enter: () => "*",
|
|
455
454
|
exit: () => "*",
|
|
456
455
|
collapsesInnerWhiteSpace: true,
|
|
457
456
|
spacing: NO_SPACING,
|
|
458
457
|
isInline: true
|
|
459
458
|
},
|
|
460
|
-
[
|
|
459
|
+
[91]: {
|
|
461
460
|
enter: () => "**",
|
|
462
461
|
exit: () => "**",
|
|
463
462
|
collapsesInnerWhiteSpace: true,
|
|
464
463
|
spacing: NO_SPACING,
|
|
465
464
|
isInline: true
|
|
466
465
|
},
|
|
467
|
-
[
|
|
466
|
+
[92]: {
|
|
468
467
|
enter: () => "`",
|
|
469
468
|
exit: () => "`",
|
|
470
469
|
collapsesInnerWhiteSpace: true,
|
|
471
470
|
spacing: NO_SPACING,
|
|
472
471
|
isInline: true
|
|
473
472
|
},
|
|
474
|
-
[
|
|
473
|
+
[93]: {
|
|
475
474
|
enter: () => "",
|
|
476
475
|
exit: () => "",
|
|
477
476
|
collapsesInnerWhiteSpace: true,
|
|
478
477
|
spacing: NO_SPACING,
|
|
479
478
|
isInline: true
|
|
480
479
|
},
|
|
481
|
-
[
|
|
480
|
+
[94]: {
|
|
482
481
|
enter: () => "",
|
|
483
482
|
exit: () => "",
|
|
484
483
|
collapsesInnerWhiteSpace: true,
|
|
485
484
|
spacing: NO_SPACING,
|
|
486
485
|
isInline: true
|
|
487
486
|
},
|
|
488
|
-
[
|
|
487
|
+
[95]: {
|
|
489
488
|
enter: () => "",
|
|
490
489
|
exit: () => "",
|
|
491
490
|
collapsesInnerWhiteSpace: true,
|
|
492
491
|
spacing: NO_SPACING,
|
|
493
492
|
isInline: true
|
|
494
493
|
},
|
|
495
|
-
[
|
|
494
|
+
[96]: {
|
|
496
495
|
enter: () => "",
|
|
497
496
|
exit: () => "",
|
|
498
497
|
collapsesInnerWhiteSpace: true,
|
|
499
498
|
spacing: NO_SPACING,
|
|
500
499
|
isInline: true
|
|
501
500
|
},
|
|
502
|
-
[
|
|
501
|
+
[97]: {
|
|
503
502
|
enter: () => "",
|
|
504
503
|
exit: () => "",
|
|
505
504
|
collapsesInnerWhiteSpace: true,
|
|
506
505
|
spacing: NO_SPACING,
|
|
507
506
|
isInline: true
|
|
508
507
|
},
|
|
509
|
-
[
|
|
508
|
+
[100]: {
|
|
510
509
|
enter: () => "<address>",
|
|
511
510
|
exit: () => "</address>",
|
|
512
511
|
spacing: NO_SPACING,
|
|
513
512
|
collapsesInnerWhiteSpace: true
|
|
514
513
|
},
|
|
515
|
-
[
|
|
514
|
+
[101]: {
|
|
516
515
|
spacing: NO_SPACING,
|
|
517
516
|
enter: () => "<dl>",
|
|
518
517
|
exit: () => "</dl>"
|
|
519
518
|
},
|
|
520
|
-
[
|
|
519
|
+
[99]: {
|
|
521
520
|
enter: () => "<dt>",
|
|
522
521
|
exit: () => "</dt>",
|
|
523
522
|
collapsesInnerWhiteSpace: true,
|
|
524
523
|
spacing: [0, 1]
|
|
525
524
|
},
|
|
526
|
-
[
|
|
525
|
+
[98]: {
|
|
527
526
|
enter: () => "<dd>",
|
|
528
527
|
exit: () => "</dd>",
|
|
529
528
|
spacing: [0, 1]
|
|
529
|
+
},
|
|
530
|
+
[102]: {},
|
|
531
|
+
[106]: {
|
|
532
|
+
enter: () => "_",
|
|
533
|
+
exit: () => "_",
|
|
534
|
+
collapsesInnerWhiteSpace: true,
|
|
535
|
+
spacing: NO_SPACING,
|
|
536
|
+
isInline: true
|
|
530
537
|
}
|
|
531
538
|
};
|
|
532
|
-
|
|
533
539
|
//#endregion
|
|
534
540
|
//#region src/utils.ts
|
|
535
541
|
/**
|
|
@@ -585,7 +591,6 @@ function traverseUpToFirstBlockNode(node) {
|
|
|
585
591
|
}
|
|
586
592
|
return parentsToIncrement;
|
|
587
593
|
}
|
|
588
|
-
|
|
589
594
|
//#endregion
|
|
590
595
|
//#region src/parse.ts
|
|
591
596
|
const LT_CHAR = 60;
|
|
@@ -625,7 +630,7 @@ function parseHtml(html, options = {}) {
|
|
|
625
630
|
return {
|
|
626
631
|
events,
|
|
627
632
|
remainingHtml: parseHtmlInternal(html, {
|
|
628
|
-
depthMap: new Uint8Array(
|
|
633
|
+
depthMap: new Uint8Array(108),
|
|
629
634
|
depth: 0,
|
|
630
635
|
plugins: options.plugins || []
|
|
631
636
|
}, (event) => {
|
|
@@ -644,7 +649,7 @@ function parseHtmlStream(html, state, onEvent) {
|
|
|
644
649
|
*/
|
|
645
650
|
function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
646
651
|
let textBuffer = "";
|
|
647
|
-
state.depthMap ??= new Uint8Array(
|
|
652
|
+
state.depthMap ??= new Uint8Array(108);
|
|
648
653
|
state.depth ??= 0;
|
|
649
654
|
state.lastCharWasWhitespace ??= true;
|
|
650
655
|
state.justClosedTag ??= false;
|
|
@@ -657,7 +662,7 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
657
662
|
if (currentCharCode !== LT_CHAR) {
|
|
658
663
|
if (currentCharCode === AMPERSAND_CHAR) state.hasEncodedHtmlEntity = true;
|
|
659
664
|
if (isWhitespace(currentCharCode)) {
|
|
660
|
-
const inPreTag = state.depthMap[
|
|
665
|
+
const inPreTag = state.depthMap[34] > 0;
|
|
661
666
|
if (state.justClosedTag) {
|
|
662
667
|
state.justClosedTag = false;
|
|
663
668
|
state.lastCharWasWhitespace = false;
|
|
@@ -675,11 +680,11 @@ function parseHtmlInternal(htmlChunk, state, handleEvent) {
|
|
|
675
680
|
state.textBufferContainsNonWhitespace = true;
|
|
676
681
|
state.lastCharWasWhitespace = false;
|
|
677
682
|
state.justClosedTag = false;
|
|
678
|
-
if (currentCharCode === PIPE_CHAR && state.depthMap[
|
|
679
|
-
else if (currentCharCode === BACKTICK_CHAR && (state.depthMap[
|
|
680
|
-
else if (currentCharCode === OPEN_BRACKET_CHAR && state.depthMap[
|
|
681
|
-
else if (currentCharCode === CLOSE_BRACKET_CHAR && state.depthMap[
|
|
682
|
-
else if (currentCharCode === GT_CHAR && state.depthMap[
|
|
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 += "\\>";
|
|
683
688
|
else textBuffer += htmlChunk[i];
|
|
684
689
|
if (state.currentNode?.tagHandler?.isNonNesting) {
|
|
685
690
|
if (!state.lastCharWasBackslash) {
|
|
@@ -782,12 +787,12 @@ function processTextBuffer(textBuffer, state, handleEvent) {
|
|
|
782
787
|
state.textBufferContainsWhitespace = false;
|
|
783
788
|
if (!state.currentNode) return;
|
|
784
789
|
const excludesTextNodes = state.currentNode?.tagHandler?.excludesTextNodes;
|
|
785
|
-
const inPreTag = state.depthMap[
|
|
790
|
+
const inPreTag = state.depthMap[34] > 0;
|
|
786
791
|
if (!inPreTag && !containsNonWhitespace && !state.currentNode.childTextNodeIndex) return;
|
|
787
792
|
let text = textBuffer;
|
|
788
793
|
if (text.length === 0) return;
|
|
789
794
|
const parentsToIncrement = traverseUpToFirstBlockNode(state.currentNode);
|
|
790
|
-
const firstBlockParent = parentsToIncrement
|
|
795
|
+
const firstBlockParent = parentsToIncrement.at(-1);
|
|
791
796
|
if (containsWhitespace && !firstBlockParent?.childTextNodeIndex) {
|
|
792
797
|
let start = 0;
|
|
793
798
|
while (start < text.length && (inPreTag ? text.charCodeAt(start) === NEWLINE_CHAR || text.charCodeAt(start) === CARRIAGE_RETURN_CHAR : isWhitespace(text.charCodeAt(start)))) start++;
|
|
@@ -798,10 +803,9 @@ function processTextBuffer(textBuffer, state, handleEvent) {
|
|
|
798
803
|
state.hasEncodedHtmlEntity = false;
|
|
799
804
|
}
|
|
800
805
|
const textNode = {
|
|
801
|
-
type:
|
|
806
|
+
type: 2,
|
|
802
807
|
value: text,
|
|
803
808
|
parent: state.currentNode,
|
|
804
|
-
regionId: state.currentNode?.regionId,
|
|
805
809
|
index: state.currentNode.currentWalkIndex++,
|
|
806
810
|
depth: state.depth,
|
|
807
811
|
containsWhitespace,
|
|
@@ -809,7 +813,7 @@ function processTextBuffer(textBuffer, state, handleEvent) {
|
|
|
809
813
|
};
|
|
810
814
|
for (const parent of parentsToIncrement) parent.childTextNodeIndex = (parent.childTextNodeIndex || 0) + 1;
|
|
811
815
|
handleEvent({
|
|
812
|
-
type:
|
|
816
|
+
type: 0,
|
|
813
817
|
node: textNode
|
|
814
818
|
});
|
|
815
819
|
state.lastTextNode = textNode;
|
|
@@ -862,14 +866,14 @@ function processClosingTag(htmlChunk, position, state, handleEvent) {
|
|
|
862
866
|
*/
|
|
863
867
|
function closeNode(node, state, handleEvent) {
|
|
864
868
|
if (!node) return;
|
|
865
|
-
if (node.tagId ===
|
|
869
|
+
if (node.tagId === 26 && !node.childTextNodeIndex) {
|
|
866
870
|
const prefix = node.attributes?.title || node.attributes?.["aria-label"] || "";
|
|
867
871
|
if (prefix) {
|
|
868
872
|
node.childTextNodeIndex = 1;
|
|
869
873
|
handleEvent({
|
|
870
|
-
type:
|
|
874
|
+
type: 0,
|
|
871
875
|
node: {
|
|
872
|
-
type:
|
|
876
|
+
type: 2,
|
|
873
877
|
value: prefix,
|
|
874
878
|
parent: node,
|
|
875
879
|
index: 0,
|
|
@@ -888,7 +892,7 @@ function closeNode(node, state, handleEvent) {
|
|
|
888
892
|
}
|
|
889
893
|
state.depth--;
|
|
890
894
|
handleEvent({
|
|
891
|
-
type:
|
|
895
|
+
type: 1,
|
|
892
896
|
node
|
|
893
897
|
});
|
|
894
898
|
state.currentNode = state.currentNode.parent;
|
|
@@ -959,20 +963,19 @@ function processOpeningTag(tagName, tagId, htmlChunk, i, state, handleEvent) {
|
|
|
959
963
|
if (state.currentNode) state.currentNode.currentWalkIndex = state.currentNode.currentWalkIndex || 0;
|
|
960
964
|
const currentWalkIndex = state.currentNode ? state.currentNode.currentWalkIndex++ : 0;
|
|
961
965
|
const tag = {
|
|
962
|
-
type:
|
|
966
|
+
type: 1,
|
|
963
967
|
name: tagName,
|
|
964
968
|
attributes: result.attributes,
|
|
965
969
|
parent: state.currentNode,
|
|
966
970
|
depthMap: copyDepthMap(state.depthMap),
|
|
967
971
|
depth: state.depth,
|
|
968
972
|
index: currentWalkIndex,
|
|
969
|
-
regionId: state.currentNode?.regionId,
|
|
970
973
|
tagId,
|
|
971
974
|
tagHandler
|
|
972
975
|
};
|
|
973
976
|
state.lastTextNode = tag;
|
|
974
977
|
handleEvent({
|
|
975
|
-
type:
|
|
978
|
+
type: 0,
|
|
976
979
|
node: tag
|
|
977
980
|
});
|
|
978
981
|
const parentNode = tag;
|
|
@@ -1128,7 +1131,6 @@ function parseAttributes(attrStr) {
|
|
|
1128
1131
|
}
|
|
1129
1132
|
return result;
|
|
1130
1133
|
}
|
|
1131
|
-
|
|
1132
1134
|
//#endregion
|
|
1133
1135
|
//#region src/plugin-processor.ts
|
|
1134
1136
|
/**
|
|
@@ -1143,23 +1145,25 @@ function parseAttributes(attrStr) {
|
|
|
1143
1145
|
*/
|
|
1144
1146
|
function processPluginsForEvent(event, plugins, state, processEvent) {
|
|
1145
1147
|
if (plugins?.length) {
|
|
1148
|
+
let shouldSkip = false;
|
|
1146
1149
|
for (const plugin of plugins) {
|
|
1147
1150
|
const res = plugin.beforeNodeProcess?.(event, state);
|
|
1148
|
-
if (typeof res === "object"
|
|
1151
|
+
if (typeof res === "object") shouldSkip = res.skip;
|
|
1149
1152
|
}
|
|
1150
|
-
if (
|
|
1153
|
+
if (shouldSkip) return true;
|
|
1154
|
+
if (event.node.type === 1) {
|
|
1151
1155
|
const element = event.node;
|
|
1152
|
-
if (event.type ===
|
|
1156
|
+
if (event.type === 0) {
|
|
1153
1157
|
for (const plugin of plugins) if (plugin.processAttributes) plugin.processAttributes(element, state);
|
|
1154
1158
|
}
|
|
1155
|
-
const fn = event.type ===
|
|
1159
|
+
const fn = event.type === 0 ? "onNodeEnter" : "onNodeExit";
|
|
1156
1160
|
const pluginOutputs = [];
|
|
1157
1161
|
for (const plugin of plugins) if (plugin[fn]) {
|
|
1158
1162
|
const result = plugin[fn](element, state);
|
|
1159
1163
|
if (result) pluginOutputs.push(result);
|
|
1160
1164
|
}
|
|
1161
|
-
if (pluginOutputs.length > 0) element.pluginOutput =
|
|
1162
|
-
} else if (event.node.type ===
|
|
1165
|
+
if (pluginOutputs.length > 0) element.pluginOutput = [...element.pluginOutput || [], ...pluginOutputs];
|
|
1166
|
+
} else if (event.node.type === 2 && event.type === 0) {
|
|
1163
1167
|
const textNode = event.node;
|
|
1164
1168
|
for (const plugin of plugins) if (plugin.processTextNode) {
|
|
1165
1169
|
const result = plugin.processTextNode(textNode, state);
|
|
@@ -1173,7 +1177,6 @@ function processPluginsForEvent(event, plugins, state, processEvent) {
|
|
|
1173
1177
|
processEvent(event);
|
|
1174
1178
|
return false;
|
|
1175
1179
|
}
|
|
1176
|
-
|
|
1177
1180
|
//#endregion
|
|
1178
1181
|
//#region src/markdown-processor.ts
|
|
1179
1182
|
/**
|
|
@@ -1204,7 +1207,7 @@ function needsSpacing(lastChar, firstChar, state) {
|
|
|
1204
1207
|
"_",
|
|
1205
1208
|
"`"
|
|
1206
1209
|
]);
|
|
1207
|
-
if (lastChar === "|" && firstChar === "<" && state && state.depthMap[
|
|
1210
|
+
if (lastChar === "|" && firstChar === "<" && state && state.depthMap[28] > 0) return true;
|
|
1208
1211
|
if (noSpaceAfter.has(lastChar) || noSpaceBefore.has(firstChar)) return false;
|
|
1209
1212
|
return true;
|
|
1210
1213
|
}
|
|
@@ -1220,12 +1223,12 @@ function shouldAddSpacingBeforeText(lastChar, lastNode, textNode) {
|
|
|
1220
1223
|
function calculateNewLineConfig(node) {
|
|
1221
1224
|
const tagId = node.tagId;
|
|
1222
1225
|
const depthMap = node.depthMap;
|
|
1223
|
-
if (tagId !==
|
|
1224
|
-
const isBlockElement = tagId !== void 0 && (tagId >=
|
|
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);
|
|
1225
1228
|
let currParent = node.parent;
|
|
1226
1229
|
while (currParent) {
|
|
1227
1230
|
if (currParent.tagHandler?.collapsesInnerWhiteSpace) {
|
|
1228
|
-
if (isBlockElement && currParent.tagId ===
|
|
1231
|
+
if (isBlockElement && currParent.tagId === 37) {
|
|
1229
1232
|
currParent = currParent.parent;
|
|
1230
1233
|
continue;
|
|
1231
1234
|
}
|
|
@@ -1242,12 +1245,9 @@ function calculateNewLineConfig(node) {
|
|
|
1242
1245
|
function createMarkdownProcessor(options = {}) {
|
|
1243
1246
|
const state = {
|
|
1244
1247
|
options,
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
depthMap: new Uint8Array(MAX_TAG_ID)
|
|
1248
|
+
buffer: [],
|
|
1249
|
+
depthMap: new Uint8Array(108)
|
|
1248
1250
|
};
|
|
1249
|
-
state.regionToggles.set(0, true);
|
|
1250
|
-
state.regionContentBuffers.set(0, []);
|
|
1251
1251
|
let lastYieldedLength = 0;
|
|
1252
1252
|
/**
|
|
1253
1253
|
* Process a DOM event and generate markdown
|
|
@@ -1257,24 +1257,25 @@ function createMarkdownProcessor(options = {}) {
|
|
|
1257
1257
|
const lastNode = state.lastNode;
|
|
1258
1258
|
state.lastNode = event.node;
|
|
1259
1259
|
state.depth = node.depth;
|
|
1260
|
-
const buff = state.
|
|
1261
|
-
const lastBuffEntry = buff
|
|
1260
|
+
const buff = state.buffer;
|
|
1261
|
+
const lastBuffEntry = buff.at(-1);
|
|
1262
1262
|
const lastChar = lastBuffEntry?.charAt(lastBuffEntry.length - 1) || "";
|
|
1263
1263
|
let secondLastChar;
|
|
1264
1264
|
if (lastBuffEntry?.length > 1) secondLastChar = lastBuffEntry.charAt(lastBuffEntry.length - 2);
|
|
1265
1265
|
else secondLastChar = buff[buff.length - 2]?.charAt(buff[buff.length - 2].length - 1);
|
|
1266
|
-
if (node.type ===
|
|
1266
|
+
if (node.type === 2 && eventType === 0) {
|
|
1267
1267
|
const textNode = node;
|
|
1268
1268
|
if (textNode.value) {
|
|
1269
1269
|
if (textNode.excludedFromMarkdown) return;
|
|
1270
1270
|
if (textNode.value === " " && lastChar === "\n") return;
|
|
1271
1271
|
if (shouldAddSpacingBeforeText(lastChar, lastNode, textNode)) textNode.value = ` ${textNode.value}`;
|
|
1272
|
-
|
|
1272
|
+
state.buffer.push(textNode.value);
|
|
1273
|
+
state.lastContentCache = textNode.value;
|
|
1273
1274
|
}
|
|
1274
1275
|
state.lastTextNode = textNode;
|
|
1275
1276
|
return;
|
|
1276
1277
|
}
|
|
1277
|
-
if (node.type !==
|
|
1278
|
+
if (node.type !== 1) return;
|
|
1278
1279
|
const context = {
|
|
1279
1280
|
node,
|
|
1280
1281
|
state
|
|
@@ -1289,7 +1290,7 @@ function createMarkdownProcessor(options = {}) {
|
|
|
1289
1290
|
let lastNewLines = 0;
|
|
1290
1291
|
if (lastChar === "\n") lastNewLines++;
|
|
1291
1292
|
if (secondLastChar === "\n") lastNewLines++;
|
|
1292
|
-
const eventFn = eventType ===
|
|
1293
|
+
const eventFn = eventType === 0 ? "enter" : "exit";
|
|
1293
1294
|
const handler = node.tagHandler;
|
|
1294
1295
|
if (!output.length && handler?.[eventFn]) {
|
|
1295
1296
|
const res = handler[eventFn](context);
|
|
@@ -1299,30 +1300,39 @@ function createMarkdownProcessor(options = {}) {
|
|
|
1299
1300
|
const newLines = Math.max(0, configuredNewLines - lastNewLines);
|
|
1300
1301
|
if (newLines > 0) {
|
|
1301
1302
|
if (!buff.length) {
|
|
1302
|
-
for (const fragment of output)
|
|
1303
|
+
for (const fragment of output) if (fragment) {
|
|
1304
|
+
state.buffer.push(fragment);
|
|
1305
|
+
state.lastContentCache = fragment;
|
|
1306
|
+
}
|
|
1303
1307
|
return;
|
|
1304
1308
|
}
|
|
1305
1309
|
const newlinesStr = "\n".repeat(newLines);
|
|
1306
|
-
if (lastChar === " " && buff?.length) buff[buff.length - 1] = buff
|
|
1307
|
-
if (eventType ===
|
|
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);
|
|
1308
1312
|
else output.push(newlinesStr);
|
|
1309
1313
|
} else if (lastFragment && state.lastTextNode?.containsWhitespace && !!node.parent && "value" in state.lastTextNode && typeof state.lastTextNode.value === "string") {
|
|
1310
|
-
if (!node.parent.depthMap[
|
|
1314
|
+
if (!node.parent.depthMap[34] || node.parent.tagId === 34) {
|
|
1311
1315
|
const isInlineElement = node.tagHandler?.isInline;
|
|
1312
1316
|
const collapsesWhiteSpace = node.tagHandler?.collapsesInnerWhiteSpace;
|
|
1313
1317
|
const hasSpacing = node.tagHandler?.spacing && Array.isArray(node.tagHandler.spacing);
|
|
1314
|
-
if ((!isInlineElement || eventType ===
|
|
1318
|
+
if ((!isInlineElement || eventType === 1) && !(!isInlineElement && !collapsesWhiteSpace && configuredNewLines > 0) && !(collapsesWhiteSpace && eventType === 0) && !(hasSpacing && eventType === 0)) {
|
|
1315
1319
|
const originalLength = lastFragment.length;
|
|
1316
1320
|
const trimmed = lastFragment.trimEnd();
|
|
1317
1321
|
if (originalLength - trimmed.length > 0) {
|
|
1318
|
-
if (buff?.length && buff
|
|
1322
|
+
if (buff?.length && buff.at(-1) === lastFragment) buff[buff.length - 1] = trimmed;
|
|
1319
1323
|
}
|
|
1320
1324
|
}
|
|
1321
1325
|
state.lastTextNode = void 0;
|
|
1322
1326
|
}
|
|
1323
1327
|
}
|
|
1324
|
-
if (output[0]?.[0] && eventType ===
|
|
1325
|
-
|
|
1328
|
+
if (output[0]?.[0] && eventType === 0 && lastChar && needsSpacing(lastChar, output[0][0], state)) {
|
|
1329
|
+
state.buffer.push(" ");
|
|
1330
|
+
state.lastContentCache = " ";
|
|
1331
|
+
}
|
|
1332
|
+
for (const fragment of output) if (fragment) {
|
|
1333
|
+
state.buffer.push(fragment);
|
|
1334
|
+
state.lastContentCache = fragment;
|
|
1335
|
+
}
|
|
1326
1336
|
}
|
|
1327
1337
|
/**
|
|
1328
1338
|
* Process HTML string and generate events
|
|
@@ -1340,15 +1350,15 @@ function createMarkdownProcessor(options = {}) {
|
|
|
1340
1350
|
* Get the final markdown output
|
|
1341
1351
|
*/
|
|
1342
1352
|
function getMarkdown() {
|
|
1343
|
-
|
|
1353
|
+
const result = state.buffer.join("").trimStart();
|
|
1354
|
+
state.buffer.length = 0;
|
|
1355
|
+
return result.trimEnd();
|
|
1344
1356
|
}
|
|
1345
1357
|
/**
|
|
1346
1358
|
* Get new markdown content since the last call (for streaming)
|
|
1347
1359
|
*/
|
|
1348
1360
|
function getMarkdownChunk() {
|
|
1349
|
-
const
|
|
1350
|
-
for (const [regionId, content] of Array.from(state.regionContentBuffers.entries())) if (state.regionToggles.get(regionId)) fragments.push(...content);
|
|
1351
|
-
const currentContent = fragments.join("").trimStart();
|
|
1361
|
+
const currentContent = state.buffer.join("").trimStart();
|
|
1352
1362
|
const newContent = currentContent.slice(lastYieldedLength);
|
|
1353
1363
|
lastYieldedLength = currentContent.length;
|
|
1354
1364
|
return newContent;
|
|
@@ -1362,6 +1372,5 @@ function createMarkdownProcessor(options = {}) {
|
|
|
1362
1372
|
};
|
|
1363
1373
|
}
|
|
1364
1374
|
const MarkdownProcessor = createMarkdownProcessor;
|
|
1365
|
-
|
|
1366
1375
|
//#endregion
|
|
1367
|
-
export { parseHtmlStream as a, parseHtml as i, createMarkdownProcessor as n, processPluginsForEvent as r, MarkdownProcessor as t };
|
|
1376
|
+
export { parseHtmlStream as a, parseHtml as i, createMarkdownProcessor as n, processPluginsForEvent as r, MarkdownProcessor as t };
|