@mdream/js 2.0.0-beta.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +402 -126
- package/dist/_chunks/clean.mjs +526 -0
- package/dist/_chunks/const.mjs +3 -7
- package/dist/_chunks/extraction.d.mts +14 -0
- package/dist/_chunks/html.mjs +260 -0
- package/dist/_chunks/markdown-processor.mjs +1077 -828
- package/dist/_chunks/minimal.mjs +29 -0
- package/dist/_chunks/output-runner.mjs +54 -0
- package/dist/_chunks/parse.mjs +133 -1500
- package/dist/_chunks/plugin.mjs +14 -0
- package/dist/_chunks/src.mjs +291 -0
- package/dist/_chunks/tag-overrides.mjs +138 -0
- package/dist/_chunks/{plugins.mjs → tailwind.mjs} +145 -292
- package/dist/_chunks/text.mjs +583 -0
- package/dist/_chunks/types.d.mts +136 -126
- package/dist/_chunks/url.mjs +82 -0
- package/dist/_chunks/utils.mjs +659 -0
- package/dist/clean.d.mts +10 -0
- package/dist/clean.mjs +2 -0
- package/dist/cli.mjs +47 -8
- package/dist/html.d.mts +6 -0
- package/dist/html.mjs +2 -0
- package/dist/index.d.mts +5 -4
- package/dist/index.mjs +4 -58
- package/dist/parse.d.mts +15 -10
- package/dist/plugins.d.mts +13 -28
- package/dist/plugins.mjs +52 -2
- package/dist/preset/minimal.d.mts +14 -2
- package/dist/preset/minimal.mjs +1 -32
- package/dist/splitter.d.mts +12 -4
- package/dist/splitter.mjs +355 -113
- package/dist/text.d.mts +6 -0
- package/dist/text.mjs +2 -0
- package/package.json +33 -7
- package/dist/_chunks/index.d.mts +0 -9
- package/dist/_chunks/minimal.d.mts +0 -6
- package/dist/_chunks/resolve-plugins.mjs +0 -44
- package/dist/_chunks/stream.mjs +0 -37
- package/dist/core.d.mts +0 -15
- package/dist/core.mjs +0 -28
|
@@ -1,262 +1,24 @@
|
|
|
1
|
-
import { DEFAULT_BLOCK_SPACING, NO_SPACING,
|
|
2
|
-
import { blockOpenPrefix,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
emptyLinks: true,
|
|
8
|
-
redundantLinks: true,
|
|
9
|
-
selfLinkHeadings: true,
|
|
10
|
-
emptyImages: true,
|
|
11
|
-
emptyLinkText: true
|
|
12
|
-
};
|
|
13
|
-
if (clean === false) return {};
|
|
14
|
-
return clean;
|
|
15
|
-
}
|
|
16
|
-
function parseLink(md, start) {
|
|
17
|
-
const len = md.length;
|
|
18
|
-
let j = start + 1;
|
|
19
|
-
let depth = 1;
|
|
20
|
-
while (j < len && depth > 0) {
|
|
21
|
-
const c = md.charCodeAt(j);
|
|
22
|
-
if (c === 91) depth++;
|
|
23
|
-
else if (c === 93) depth--;
|
|
24
|
-
j++;
|
|
25
|
-
}
|
|
26
|
-
if (depth !== 0) return null;
|
|
27
|
-
const textEnd = j - 1;
|
|
28
|
-
if (j >= len || md.charCodeAt(j) !== 40) return null;
|
|
29
|
-
j++;
|
|
30
|
-
const urlStart = j;
|
|
31
|
-
let parenDepth = 1;
|
|
32
|
-
while (j < len && parenDepth > 0) {
|
|
33
|
-
const c = md.charCodeAt(j);
|
|
34
|
-
if (c === 40) parenDepth++;
|
|
35
|
-
else if (c === 41) parenDepth--;
|
|
36
|
-
j++;
|
|
37
|
-
}
|
|
38
|
-
if (parenDepth !== 0) return null;
|
|
39
|
-
const urlEnd = j - 1;
|
|
40
|
-
return {
|
|
41
|
-
text: md.slice(start + 1, textEnd),
|
|
42
|
-
url: md.slice(urlStart, urlEnd),
|
|
43
|
-
end: j
|
|
44
|
-
};
|
|
1
|
+
import { BLOCKQUOTE_SPACING, DEFAULT_BLOCK_SPACING, LIST_ITEM_SPACING, NO_SPACING, TABLE_ROW_SPACING, isInsideRawHtmlBlock } from "./const.mjs";
|
|
2
|
+
import { blockOpenPrefix, continuationPrefix, endsAtHardBreak, figcaptionOwnsBlockSpacing, getLanguageFromClass, isCharacterReferenceTail, isDataUrl, isEmptyLinkHref, isInsideHeading, isInsideTableCell, lastOutputChar, listMarkerLineStart, markRenderedChildContent, orderedItemNumber, parseUnsignedInteger, trimOutputStart, trimTextAtLineStart } from "./utils.mjs";
|
|
3
|
+
import { resolveUrl, safeAnchorOutput } from "./url.mjs";
|
|
4
|
+
function serializeMarkdownDestination(destination) {
|
|
5
|
+
if (!/[\t\n\f\r ()\\<>]/.test(destination)) return destination;
|
|
6
|
+
return `<${/[\\<>]/.test(destination) ? destination.replace(/[\\<>]/g, "\\$&") : destination}>`;
|
|
45
7
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
return (
|
|
8
|
+
function stripsEmptyLink(state, href) {
|
|
9
|
+
const clean = state.options?.clean;
|
|
10
|
+
if (!(clean === true || typeof clean === "object" && clean.emptyLinks)) return false;
|
|
11
|
+
return isEmptyLinkHref(href);
|
|
50
12
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
let i = start + 1;
|
|
54
|
-
if (md.charCodeAt(i) === 47) i++;
|
|
55
|
-
let code = md.charCodeAt(i);
|
|
56
|
-
if (!(code >= 65 && code <= 90 || code >= 97 && code <= 122)) return -1;
|
|
57
|
-
do {
|
|
58
|
-
i++;
|
|
59
|
-
code = md.charCodeAt(i);
|
|
60
|
-
} while (code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 45);
|
|
61
|
-
if (code !== 32 && code !== 9 && code !== 10 && code !== 13 && code !== 47 && code !== 62) return -1;
|
|
62
|
-
let quote = 0;
|
|
63
|
-
while (i < md.length) {
|
|
64
|
-
code = md.charCodeAt(i);
|
|
65
|
-
if (quote) {
|
|
66
|
-
if (code === quote) quote = 0;
|
|
67
|
-
} else if (code === 34 || code === 39) quote = code;
|
|
68
|
-
else if (code === 62) return i + 1;
|
|
69
|
-
else if (code === 60) return -1;
|
|
70
|
-
i++;
|
|
71
|
-
}
|
|
72
|
-
return -1;
|
|
13
|
+
function serializeMarkdownTitle(title) {
|
|
14
|
+
return /[\\"]/.test(title) ? title.replace(/[\\"]/g, "\\$&") : title;
|
|
73
15
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
for (let i = 0; i < text.length; i++) {
|
|
78
|
-
const c = text.charCodeAt(i);
|
|
79
|
-
if (c >= 97 && c <= 122) {
|
|
80
|
-
slug += text[i];
|
|
81
|
-
lastWasDash = false;
|
|
82
|
-
} else if (c >= 65 && c <= 90) {
|
|
83
|
-
slug += String.fromCharCode(c + 32);
|
|
84
|
-
lastWasDash = false;
|
|
85
|
-
} else if (c >= 48 && c <= 57) {
|
|
86
|
-
slug += text[i];
|
|
87
|
-
lastWasDash = false;
|
|
88
|
-
} else if (c === 95) {
|
|
89
|
-
slug += "_";
|
|
90
|
-
lastWasDash = false;
|
|
91
|
-
} else if (c === 32 || c === 9 || c === 45) {
|
|
92
|
-
if (!lastWasDash && slug.length > 0) {
|
|
93
|
-
slug += "-";
|
|
94
|
-
lastWasDash = true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (lastWasDash) slug = slug.slice(0, -1);
|
|
99
|
-
return slug;
|
|
16
|
+
function serializeMarkdownResource(destination, title) {
|
|
17
|
+
if (!title) return `(${serializeMarkdownDestination(destination)})`;
|
|
18
|
+
return `(${destination ? serializeMarkdownDestination(destination) : "<>"} "${serializeMarkdownTitle(title)}")`;
|
|
100
19
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
const len = text.length;
|
|
104
|
-
const lastGt = text.lastIndexOf(">");
|
|
105
|
-
let firstTickLength = 0;
|
|
106
|
-
let firstTickLast = 0;
|
|
107
|
-
let otherTickLasts;
|
|
108
|
-
if (text.includes("`")) {
|
|
109
|
-
let scan = 0;
|
|
110
|
-
while (scan < len) {
|
|
111
|
-
let code = text.charCodeAt(scan);
|
|
112
|
-
if (code === 96) {
|
|
113
|
-
const start = scan;
|
|
114
|
-
do {
|
|
115
|
-
scan++;
|
|
116
|
-
code = text.charCodeAt(scan);
|
|
117
|
-
} while (code === 96);
|
|
118
|
-
const ticks = scan - start;
|
|
119
|
-
if (firstTickLength === 0) {
|
|
120
|
-
firstTickLength = ticks;
|
|
121
|
-
firstTickLast = start;
|
|
122
|
-
} else if (ticks === firstTickLength) firstTickLast = start;
|
|
123
|
-
else {
|
|
124
|
-
otherTickLasts ||= /* @__PURE__ */ new Map();
|
|
125
|
-
otherTickLasts.set(ticks, start);
|
|
126
|
-
}
|
|
127
|
-
} else if (code === 60) {
|
|
128
|
-
const tagEnd = htmlTagEnd(text, scan, lastGt);
|
|
129
|
-
scan = tagEnd === -1 ? scan + 1 : tagEnd;
|
|
130
|
-
} else scan++;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
let i = 0;
|
|
134
|
-
let codeTicks = 0;
|
|
135
|
-
while (i < len) {
|
|
136
|
-
const c = text.charCodeAt(i);
|
|
137
|
-
if (c === 96) {
|
|
138
|
-
let end = i + 1;
|
|
139
|
-
while (text.charCodeAt(end) === 96) end++;
|
|
140
|
-
const ticks = end - i;
|
|
141
|
-
if (codeTicks === 0) {
|
|
142
|
-
if ((ticks === firstTickLength ? firstTickLast : otherTickLasts?.get(ticks) ?? i) > i) codeTicks = ticks;
|
|
143
|
-
} else if (codeTicks === ticks) codeTicks = 0;
|
|
144
|
-
i = end;
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
if (codeTicks !== 0) {
|
|
148
|
-
result += text[i];
|
|
149
|
-
i++;
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
if (c === 92 && i + 1 < len) {
|
|
153
|
-
result += text[i + 1];
|
|
154
|
-
i += 2;
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const tagEnd = c === 60 ? htmlTagEnd(text, i, lastGt) : -1;
|
|
158
|
-
if (tagEnd !== -1) {
|
|
159
|
-
i = tagEnd;
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
if (c === 91) {
|
|
163
|
-
const link = parseLink(text, i);
|
|
164
|
-
if (link) {
|
|
165
|
-
result += link.text;
|
|
166
|
-
i = link.end;
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (c === 42 || c === 95 || c === 126) {
|
|
171
|
-
i++;
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
result += text[i];
|
|
175
|
-
i++;
|
|
176
|
-
}
|
|
177
|
-
return result.trim();
|
|
178
|
-
}
|
|
179
|
-
function collectHeadingSlugs(md) {
|
|
180
|
-
const slugs = /* @__PURE__ */ new Set();
|
|
181
|
-
const len = md.length;
|
|
182
|
-
let i = 0;
|
|
183
|
-
while (i < len) {
|
|
184
|
-
if (i === 0 || md.charCodeAt(i - 1) === 10) {
|
|
185
|
-
let hashes = 0;
|
|
186
|
-
let j = i;
|
|
187
|
-
while (j < len && md.charCodeAt(j) === 35) {
|
|
188
|
-
hashes++;
|
|
189
|
-
j++;
|
|
190
|
-
}
|
|
191
|
-
if (hashes >= 1 && hashes <= 6 && j < len && md.charCodeAt(j) === 32) {
|
|
192
|
-
j++;
|
|
193
|
-
const lineEnd = md.indexOf("\n", j);
|
|
194
|
-
const cleaned = stripHeadingFormatting(lineEnd === -1 ? md.slice(j) : md.slice(j, lineEnd));
|
|
195
|
-
if (cleaned) slugs.add(slugify(cleaned));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
const nl = md.indexOf("\n", i);
|
|
199
|
-
if (nl === -1) break;
|
|
200
|
-
i = nl + 1;
|
|
201
|
-
}
|
|
202
|
-
return slugs;
|
|
203
|
-
}
|
|
204
|
-
function cleanFragments(md) {
|
|
205
|
-
const slugs = collectHeadingSlugs(md);
|
|
206
|
-
const len = md.length;
|
|
207
|
-
const lastGt = md.lastIndexOf(">");
|
|
208
|
-
let result = "";
|
|
209
|
-
let i = 0;
|
|
210
|
-
while (i < len) {
|
|
211
|
-
const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
|
|
212
|
-
if (tagEnd !== -1) {
|
|
213
|
-
result += md.slice(i, tagEnd);
|
|
214
|
-
i = tagEnd;
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (md.charCodeAt(i) === 91) {
|
|
218
|
-
const link = parseLink(md, i);
|
|
219
|
-
if (link && link.url.charCodeAt(0) === 35 && link.url.length > 1) {
|
|
220
|
-
const fragment = link.url.slice(1).split(" ")[0];
|
|
221
|
-
if (slugs.size > 0 ? !slugs.has(fragment) : true) {
|
|
222
|
-
result += link.text;
|
|
223
|
-
i = link.end;
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
result += md[i];
|
|
229
|
-
i++;
|
|
230
|
-
}
|
|
231
|
-
return result;
|
|
232
|
-
}
|
|
233
|
-
function cleanEmptyLinks(md) {
|
|
234
|
-
const len = md.length;
|
|
235
|
-
const lastGt = md.lastIndexOf(">");
|
|
236
|
-
let result = "";
|
|
237
|
-
let i = 0;
|
|
238
|
-
while (i < len) {
|
|
239
|
-
const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
|
|
240
|
-
if (tagEnd !== -1) {
|
|
241
|
-
result += md.slice(i, tagEnd);
|
|
242
|
-
i = tagEnd;
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
if (md.charCodeAt(i) === 91) {
|
|
246
|
-
const link = parseLink(md, i);
|
|
247
|
-
if (link) {
|
|
248
|
-
const url = link.url;
|
|
249
|
-
if (isEmptyLinkHref(url)) {
|
|
250
|
-
result += link.text;
|
|
251
|
-
i = link.end;
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
result += md[i];
|
|
257
|
-
i++;
|
|
258
|
-
}
|
|
259
|
-
return result;
|
|
20
|
+
function serializeImageDescription(alt) {
|
|
21
|
+
return /[\\[\]*_`~<&]/.test(alt) ? alt.replace(/[\\[\]*_`~<&]/g, "\\$&") : alt;
|
|
260
22
|
}
|
|
261
23
|
function isAutolinkUri(s) {
|
|
262
24
|
if (!(s.startsWith("http://") || s.startsWith("https://") || s.startsWith("ftp://") || s.startsWith("mailto:"))) return false;
|
|
@@ -266,329 +28,739 @@ function isAutolinkUri(s) {
|
|
|
266
28
|
}
|
|
267
29
|
return true;
|
|
268
30
|
}
|
|
269
|
-
function
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
let
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (i === 0 || md.charCodeAt(i - 1) === 10) {
|
|
318
|
-
let hashes = 0;
|
|
319
|
-
let j = i;
|
|
320
|
-
while (j < len && md.charCodeAt(j) === 35) {
|
|
321
|
-
hashes++;
|
|
322
|
-
j++;
|
|
323
|
-
}
|
|
324
|
-
if (hashes >= 1 && hashes <= 6 && j < len && md.charCodeAt(j) === 32) {
|
|
325
|
-
j++;
|
|
326
|
-
if (j < len && md.charCodeAt(j) === 91) {
|
|
327
|
-
const link = parseLink(md, j);
|
|
328
|
-
if (link && link.url.charCodeAt(0) === 35) {
|
|
329
|
-
result += md.slice(i, j);
|
|
330
|
-
result += link.text;
|
|
331
|
-
i = link.end;
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
result += md[i];
|
|
338
|
-
i++;
|
|
339
|
-
}
|
|
340
|
-
return result;
|
|
341
|
-
}
|
|
342
|
-
function cleanEmptyImages(md) {
|
|
343
|
-
const len = md.length;
|
|
344
|
-
const lastGt = md.lastIndexOf(">");
|
|
345
|
-
let result = "";
|
|
346
|
-
let i = 0;
|
|
347
|
-
while (i < len) {
|
|
348
|
-
const tagEnd = md.charCodeAt(i) === 60 ? htmlTagEnd(md, i, lastGt) : -1;
|
|
349
|
-
if (tagEnd !== -1) {
|
|
350
|
-
result += md.slice(i, tagEnd);
|
|
351
|
-
i = tagEnd;
|
|
31
|
+
function renderBreak(node, state) {
|
|
32
|
+
const depthMap = state.depthMap;
|
|
33
|
+
if (isInsideTableCell(state) || isInsideRawHtmlBlock(depthMap) || isInsideHeading(depthMap)) return "<br>";
|
|
34
|
+
if (depthMap[34] || depthMap[23]) return "\n";
|
|
35
|
+
return ` \n${continuationPrefix(node, state.listIndentWidths || [], !state.bufferedBlockquoteDepth)}`;
|
|
36
|
+
}
|
|
37
|
+
const breakHandler = {
|
|
38
|
+
enter: ({ node, state }) => renderBreak(node, state),
|
|
39
|
+
isSelfClosing: true,
|
|
40
|
+
spacing: NO_SPACING,
|
|
41
|
+
collapsesInnerWhiteSpace: true,
|
|
42
|
+
isInline: true
|
|
43
|
+
};
|
|
44
|
+
function escapeTrailingHeadingHashes(buffer, positions) {
|
|
45
|
+
let index = buffer.length - 1;
|
|
46
|
+
while (index >= 0 && buffer[index] === "") index--;
|
|
47
|
+
if (index < 0) return;
|
|
48
|
+
const entry = buffer[index];
|
|
49
|
+
let end = entry.length;
|
|
50
|
+
while (end > 0 && (entry[end - 1] === " " || entry[end - 1] === " ")) end--;
|
|
51
|
+
let run = end;
|
|
52
|
+
while (run > 0 && entry[run - 1] === "#") run--;
|
|
53
|
+
if (run === end) return;
|
|
54
|
+
const previous = buffer[index - 1];
|
|
55
|
+
const before = run > 0 ? entry[run - 1] : previous?.charAt(previous.length - 1);
|
|
56
|
+
if (before !== " " && before !== " ") return;
|
|
57
|
+
const replacement = `${entry.slice(0, run)}\\${entry.slice(run)}`;
|
|
58
|
+
positions?.replace(index, index + 1, [replacement], (offset) => offset > run ? offset + 1 : offset);
|
|
59
|
+
buffer[index] = replacement;
|
|
60
|
+
}
|
|
61
|
+
const LINE_FRESH = -1;
|
|
62
|
+
const LINE_OPEN = 0;
|
|
63
|
+
const LINE_ROW = 1;
|
|
64
|
+
const LINE_CONTENT = 2;
|
|
65
|
+
function lineStateBeforeRow(buffer) {
|
|
66
|
+
let fragment = buffer.length - 1;
|
|
67
|
+
while (fragment >= 0 && buffer[fragment].length === 0) fragment--;
|
|
68
|
+
if (fragment < 0) return LINE_OPEN;
|
|
69
|
+
const tail = buffer[fragment];
|
|
70
|
+
if (tail.charCodeAt(tail.length - 1) === 10) return LINE_FRESH;
|
|
71
|
+
let firstNonSpace = -1;
|
|
72
|
+
let markerFragment = -1;
|
|
73
|
+
let markerIndex = -1;
|
|
74
|
+
let cursor = tail.length;
|
|
75
|
+
for (;;) {
|
|
76
|
+
if (cursor === 0) {
|
|
77
|
+
if (--fragment < 0) break;
|
|
78
|
+
cursor = buffer[fragment].length;
|
|
352
79
|
continue;
|
|
353
80
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (j < len && md.charCodeAt(j) === 40) {
|
|
362
|
-
let parenDepth = 1;
|
|
363
|
-
j++;
|
|
364
|
-
while (j < len && parenDepth > 0) {
|
|
365
|
-
if (md.charCodeAt(j) === 40) parenDepth++;
|
|
366
|
-
else if (md.charCodeAt(j) === 41) parenDepth--;
|
|
367
|
-
j++;
|
|
368
|
-
}
|
|
369
|
-
i = j;
|
|
370
|
-
continue;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
81
|
+
const code = buffer[fragment].charCodeAt(--cursor);
|
|
82
|
+
if (code === 10) break;
|
|
83
|
+
if (code !== 32 && code !== 9) {
|
|
84
|
+
firstNonSpace = code;
|
|
85
|
+
if (markerFragment < 0) {
|
|
86
|
+
markerFragment = fragment;
|
|
87
|
+
markerIndex = cursor;
|
|
373
88
|
}
|
|
374
89
|
}
|
|
375
|
-
result += md[i];
|
|
376
|
-
i++;
|
|
377
90
|
}
|
|
378
|
-
return
|
|
91
|
+
if (firstNonSpace === -1) return LINE_OPEN;
|
|
92
|
+
if (firstNonSpace === 124) return LINE_ROW;
|
|
93
|
+
return listMarkerLineStart(buffer, markerFragment, markerIndex) ? LINE_OPEN : LINE_CONTENT;
|
|
379
94
|
}
|
|
380
|
-
function
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
i = tagEnd;
|
|
390
|
-
continue;
|
|
391
|
-
}
|
|
392
|
-
if (md.charCodeAt(i) === 91) {
|
|
393
|
-
const link = parseLink(md, i);
|
|
394
|
-
if (link && link.text.trim().length === 0) {
|
|
395
|
-
i = link.end;
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
result += md[i];
|
|
400
|
-
i++;
|
|
95
|
+
function rowMarker(state) {
|
|
96
|
+
const indent = state.listIndent;
|
|
97
|
+
const lineState = lineStateBeforeRow(state.buffer);
|
|
98
|
+
if (!indent) return lineState === LINE_ROW ? "\n| " : lineState === LINE_CONTENT ? "\n\n| " : "| ";
|
|
99
|
+
switch (lineState) {
|
|
100
|
+
case LINE_ROW: return `\n${indent}| `;
|
|
101
|
+
case LINE_CONTENT: return `\n\n${indent}| `;
|
|
102
|
+
case LINE_FRESH: return `${indent}| `;
|
|
103
|
+
default: return "| ";
|
|
401
104
|
}
|
|
402
|
-
return result;
|
|
403
|
-
}
|
|
404
|
-
function applyClean(md, opts) {
|
|
405
|
-
if (opts.emptyImages) md = cleanEmptyImages(md);
|
|
406
|
-
if (opts.emptyLinks) md = cleanEmptyLinks(md);
|
|
407
|
-
if (opts.emptyLinkText) md = cleanEmptyLinkText(md);
|
|
408
|
-
if (opts.redundantLinks) md = cleanRedundantLinks(md);
|
|
409
|
-
if (opts.selfLinkHeadings) md = cleanSelfLinkHeadings(md);
|
|
410
|
-
if (opts.fragments) md = cleanFragments(md);
|
|
411
|
-
return md;
|
|
412
105
|
}
|
|
413
|
-
|
|
414
|
-
|
|
106
|
+
const MAX_CELL_SPAN = 64;
|
|
107
|
+
function cellEnter(node, state) {
|
|
108
|
+
if (state.tableRowOpenerPending) return "";
|
|
109
|
+
if (node.index === 0) return "";
|
|
110
|
+
const header = state.tableHeaderCells || 0;
|
|
111
|
+
return header > 0 && (state.tableCurrentRowCells || 0) >= header ? " " : " | ";
|
|
415
112
|
}
|
|
416
|
-
function
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
case 14:
|
|
422
|
-
case 15: return "strong";
|
|
423
|
-
case 16:
|
|
424
|
-
case 17: return "em";
|
|
425
|
-
case 18:
|
|
426
|
-
case 110:
|
|
427
|
-
case 111: return "del";
|
|
428
|
-
}
|
|
429
|
-
if (!(tagId === 2 || tagId === 3 || tagId >= 14 && tagId <= 26 || tagId >= 28 && tagId <= 33 || tagId >= 35 && tagId <= 39 || tagId === 41 || tagId >= 46 && tagId <= 47 || tagId >= 50 && tagId <= 51 || tagId >= 79 && tagId <= 83 || tagId >= 88 && tagId <= 93 || tagId >= 95 && tagId <= 102 || tagId >= 104 && tagId <= 107)) return;
|
|
430
|
-
if (node.tagHandler?.aliasTagId === void 0) return node.name;
|
|
431
|
-
for (const name in TagIdMap) if (TagIdMap[name] === tagId) return name;
|
|
113
|
+
function cellExit(node, state) {
|
|
114
|
+
const parsedSpan = parseUnsignedInteger(node.attributes?.colspan);
|
|
115
|
+
const span = parsedSpan && parsedSpan < 256 ? Math.min(parsedSpan, MAX_CELL_SPAN) : 1;
|
|
116
|
+
state.tableCurrentRowCells += span;
|
|
117
|
+
return span > 1 ? " |".repeat(span - 1) : void 0;
|
|
432
118
|
}
|
|
433
|
-
function
|
|
434
|
-
return
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
return start === void 0 ? "" : ` start="${start}"`;
|
|
446
|
-
}
|
|
447
|
-
if (tagId === 23) {
|
|
448
|
-
const language = getLanguageFromClass(attributes.class);
|
|
449
|
-
return language ? ` class="language-${escapeHtml(language, true)}"` : "";
|
|
450
|
-
}
|
|
451
|
-
if (tagId === 31 || tagId === 32) {
|
|
452
|
-
let output = "";
|
|
453
|
-
const colspan = parseUnsignedInteger(attributes.colspan);
|
|
454
|
-
if (colspan !== void 0 && colspan > 0) output += ` colspan="${colspan}"`;
|
|
455
|
-
if (tagId === 31) {
|
|
456
|
-
const align = attributes.align?.toLowerCase();
|
|
457
|
-
if (align === "left" || align === "center" || align === "right") output += ` align="${align}"`;
|
|
458
|
-
}
|
|
459
|
-
return output;
|
|
460
|
-
}
|
|
461
|
-
return "";
|
|
462
|
-
}
|
|
463
|
-
function append(state, output, value) {
|
|
464
|
-
const frame = state.frames.at(-1);
|
|
465
|
-
if (frame) frame.output += value;
|
|
466
|
-
else output.push(value);
|
|
467
|
-
}
|
|
468
|
-
function processText(node, state, output) {
|
|
469
|
-
if (node.excludedFromMarkdown || !node.value) return;
|
|
470
|
-
for (let index = state.frames.length - 1; index >= 0; index--) {
|
|
471
|
-
const frame = state.frames[index];
|
|
472
|
-
if (frame._tag === 0) {
|
|
473
|
-
frame.text += node.value;
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
append(state, output, escapeHtml(node.value));
|
|
478
|
-
}
|
|
479
|
-
function closeFrame(state, output, frame) {
|
|
480
|
-
state.frames.pop();
|
|
481
|
-
if (frame._tag === 0) {
|
|
482
|
-
const slug = slugifyHeading(frame.text);
|
|
483
|
-
const id = slug ? ` id="${slug}"` : "";
|
|
484
|
-
append(state, output, `<h${frame.level}${id}>${frame.output}</h${frame.level}>`);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
append(state, output, `<pre tabindex="0"><code${frame.language ? ` class="language-${escapeHtml(frame.language, true)}"` : ""}>${frame.output}</code></pre>`);
|
|
119
|
+
function handleHeading(depth) {
|
|
120
|
+
return {
|
|
121
|
+
enter: ({ state }) => {
|
|
122
|
+
if ((state.depthMap?.[26] || 0) > 0 || isInsideTableCell(state)) return `<h${depth}>`;
|
|
123
|
+
return `${"#".repeat(depth)} `;
|
|
124
|
+
},
|
|
125
|
+
exit: ({ state }) => {
|
|
126
|
+
if ((state.depthMap?.[26] || 0) > 0 || isInsideTableCell(state)) return `</h${depth}>`;
|
|
127
|
+
escapeTrailingHeadingHashes(state.buffer, state.outputPositions);
|
|
128
|
+
},
|
|
129
|
+
collapsesInnerWhiteSpace: true
|
|
130
|
+
};
|
|
488
131
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
132
|
+
const Strong = {
|
|
133
|
+
enter: ({ state }) => {
|
|
134
|
+
if ((state.depthMap?.[15] || 0) > 1) return "";
|
|
135
|
+
return "**";
|
|
136
|
+
},
|
|
137
|
+
exit: ({ node, state }) => {
|
|
138
|
+
if ((state.depthMap?.[15] || 0) + (node.tagId === 15 ? 1 : 0) > 1) return "";
|
|
139
|
+
return "**";
|
|
140
|
+
},
|
|
141
|
+
collapsesInnerWhiteSpace: true,
|
|
142
|
+
spacing: NO_SPACING,
|
|
143
|
+
isInline: true
|
|
144
|
+
};
|
|
145
|
+
const Emphasis = {
|
|
146
|
+
enter: ({ state }) => {
|
|
147
|
+
if ((state.depthMap?.[17] || 0) > 1) return "";
|
|
148
|
+
return "*";
|
|
149
|
+
},
|
|
150
|
+
exit: ({ node, state }) => {
|
|
151
|
+
if ((state.depthMap?.[17] || 0) + (node.tagId === 17 ? 1 : 0) > 1) return "";
|
|
152
|
+
return "*";
|
|
153
|
+
},
|
|
154
|
+
collapsesInnerWhiteSpace: true,
|
|
155
|
+
spacing: NO_SPACING,
|
|
156
|
+
isInline: true
|
|
157
|
+
};
|
|
158
|
+
const Strikethrough = {
|
|
159
|
+
enter: () => "~~",
|
|
160
|
+
exit: () => "~~",
|
|
161
|
+
collapsesInnerWhiteSpace: true,
|
|
162
|
+
spacing: NO_SPACING,
|
|
163
|
+
isInline: true
|
|
164
|
+
};
|
|
165
|
+
const INERT_RAWTEXT = {
|
|
166
|
+
isNonNesting: true,
|
|
167
|
+
excludesTextNodes: true,
|
|
168
|
+
spacing: NO_SPACING
|
|
169
|
+
};
|
|
170
|
+
const tagHandlers = {
|
|
171
|
+
[1]: {
|
|
172
|
+
spacing: NO_SPACING,
|
|
173
|
+
collapsesInnerWhiteSpace: true
|
|
174
|
+
},
|
|
175
|
+
[2]: {
|
|
176
|
+
enter: () => "<details>",
|
|
177
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</details>" : "</details>\n\n"
|
|
178
|
+
},
|
|
179
|
+
[3]: {
|
|
180
|
+
enter: () => "<summary>",
|
|
181
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</summary>" : "</summary>\n\n"
|
|
182
|
+
},
|
|
183
|
+
[4]: {
|
|
184
|
+
excludesTextNodes: true,
|
|
185
|
+
collapsesInnerWhiteSpace: true,
|
|
186
|
+
isNonNesting: true,
|
|
187
|
+
spacing: NO_SPACING
|
|
188
|
+
},
|
|
189
|
+
[52]: {
|
|
190
|
+
excludesTextNodes: true,
|
|
191
|
+
isNonNesting: true
|
|
192
|
+
},
|
|
193
|
+
[53]: {
|
|
194
|
+
isNonNesting: true,
|
|
195
|
+
excludesTextNodes: true
|
|
196
|
+
},
|
|
197
|
+
[5]: {
|
|
198
|
+
collapsesInnerWhiteSpace: true,
|
|
199
|
+
isSelfClosing: true,
|
|
200
|
+
spacing: NO_SPACING
|
|
201
|
+
},
|
|
202
|
+
[6]: breakHandler,
|
|
203
|
+
[7]: handleHeading(1),
|
|
204
|
+
[8]: handleHeading(2),
|
|
205
|
+
[9]: handleHeading(3),
|
|
206
|
+
[10]: handleHeading(4),
|
|
207
|
+
[11]: handleHeading(5),
|
|
208
|
+
[12]: handleHeading(6),
|
|
209
|
+
[13]: {
|
|
210
|
+
enter: ({ node, state }) => {
|
|
211
|
+
if (isInsideTableCell(state)) return "<hr>";
|
|
212
|
+
if (!(state.depthMap?.[25] || state.bufferedBlockquoteDepth)) return "---";
|
|
213
|
+
const prefix = continuationPrefix(node, state.listIndentWidths || [], !state.bufferedBlockquoteDepth);
|
|
214
|
+
if (!prefix) return "---";
|
|
215
|
+
if (state.depthMap?.[25]) state.listRulePending = prefix;
|
|
216
|
+
const open = blockOpenPrefix(state.buffer, prefix);
|
|
217
|
+
return open === void 0 ? "***" : `${open}---`;
|
|
218
|
+
},
|
|
219
|
+
isSelfClosing: true
|
|
220
|
+
},
|
|
221
|
+
[14]: Strong,
|
|
222
|
+
[15]: Strong,
|
|
223
|
+
[16]: Emphasis,
|
|
224
|
+
[17]: Emphasis,
|
|
225
|
+
[18]: Strikethrough,
|
|
226
|
+
[110]: Strikethrough,
|
|
227
|
+
[111]: Strikethrough,
|
|
228
|
+
[19]: {
|
|
229
|
+
enter: () => "<sub>",
|
|
230
|
+
exit: () => "</sub>",
|
|
231
|
+
collapsesInnerWhiteSpace: true,
|
|
232
|
+
spacing: NO_SPACING,
|
|
233
|
+
isInline: true
|
|
234
|
+
},
|
|
235
|
+
[20]: {
|
|
236
|
+
enter: () => "<sup>",
|
|
237
|
+
exit: () => "</sup>",
|
|
238
|
+
collapsesInnerWhiteSpace: true,
|
|
239
|
+
spacing: NO_SPACING,
|
|
240
|
+
isInline: true
|
|
241
|
+
},
|
|
242
|
+
[21]: {
|
|
243
|
+
enter: () => "<ins>",
|
|
244
|
+
exit: () => "</ins>",
|
|
245
|
+
collapsesInnerWhiteSpace: true,
|
|
246
|
+
spacing: NO_SPACING,
|
|
247
|
+
isInline: true
|
|
248
|
+
},
|
|
249
|
+
[22]: {
|
|
250
|
+
enter: ({ state }) => {
|
|
251
|
+
return {
|
|
252
|
+
_tag: "BlockquoteEnter",
|
|
253
|
+
output: (state.depthMap?.[25] || 0) > 0 ? "\n" : void 0
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
exit: () => ({ _tag: "BlockquoteExit" }),
|
|
257
|
+
spacing: BLOCKQUOTE_SPACING
|
|
258
|
+
},
|
|
259
|
+
[34]: {
|
|
260
|
+
enter: ({ node, state }) => {
|
|
261
|
+
if (isInsideTableCell(state)) return "<pre>";
|
|
262
|
+
return {
|
|
263
|
+
_tag: "PreEnter",
|
|
264
|
+
language: getLanguageFromClass(node.attributes?.class)
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
exit: ({ state }) => {
|
|
268
|
+
if (isInsideTableCell(state)) return "</pre>";
|
|
269
|
+
return { _tag: "PreExit" };
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
[23]: {
|
|
273
|
+
enter: ({ node, state }) => {
|
|
274
|
+
if ((state.depthMap?.[34] || 0) > 0) {
|
|
275
|
+
if (isInsideTableCell(state)) return "<code>";
|
|
276
|
+
if (state.preFenceOwnerDepth) return;
|
|
277
|
+
const language = getLanguageFromClass(node.attributes?.class);
|
|
278
|
+
if ((state.depthMap?.[25] || 0) > 0) {
|
|
279
|
+
const indent = state.listIndent;
|
|
280
|
+
return {
|
|
281
|
+
_tag: "CodeFenceEnter",
|
|
282
|
+
language,
|
|
283
|
+
output: `${blockOpenPrefix(state.buffer, indent) ?? ""}\`\`\`${language}\n`
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
_tag: "CodeFenceEnter",
|
|
288
|
+
language,
|
|
289
|
+
output: `\`\`\`${language}\n`
|
|
290
|
+
};
|
|
541
291
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
const element = event.node;
|
|
561
|
-
for (const plugin of plugins) if (plugin.processAttributes) plugin.processAttributes(element, state);
|
|
562
|
-
}
|
|
563
|
-
let shouldSkip = false;
|
|
564
|
-
for (const plugin of plugins) {
|
|
565
|
-
const res = plugin.beforeNodeProcess?.(event, state);
|
|
566
|
-
if (typeof res === "object") shouldSkip = res.skip;
|
|
567
|
-
}
|
|
568
|
-
if (shouldSkip) return true;
|
|
569
|
-
if (event.node.type === 1) {
|
|
570
|
-
const element = event.node;
|
|
571
|
-
const fn = event.type === 0 ? "onNodeEnter" : "onNodeExit";
|
|
572
|
-
const pluginOutputs = [];
|
|
573
|
-
for (const plugin of plugins) if (plugin[fn]) {
|
|
574
|
-
const result = plugin[fn](element, state);
|
|
575
|
-
if (result) pluginOutputs.push(result);
|
|
292
|
+
if (isInsideRawHtmlBlock(state.depthMap)) return "<code>";
|
|
293
|
+
if ((state.depthMap?.[25] || 0) > 0) {
|
|
294
|
+
const lastEntry = state.buffer.at(-1);
|
|
295
|
+
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
296
|
+
if (lastChar && lastChar !== " " && lastChar !== "\n" && lastChar !== " " && lastChar !== "*" && lastChar !== "_" && lastChar !== "~" && lastChar !== "[" && lastChar !== ">") return {
|
|
297
|
+
_tag: "CodeSpanEnter",
|
|
298
|
+
output: ` \``
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
_tag: "CodeSpanEnter",
|
|
303
|
+
output: "`"
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
exit: ({ state }) => {
|
|
307
|
+
if ((state.depthMap?.[34] || 0) > 0) {
|
|
308
|
+
if (isInsideTableCell(state)) return "</code>";
|
|
309
|
+
return;
|
|
576
310
|
}
|
|
577
|
-
if (
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
311
|
+
if (isInsideRawHtmlBlock(state.depthMap)) return "</code>";
|
|
312
|
+
return { _tag: "CodeSpanExit" };
|
|
313
|
+
},
|
|
314
|
+
collapsesInnerWhiteSpace: true,
|
|
315
|
+
spacing: NO_SPACING,
|
|
316
|
+
isInline: true
|
|
317
|
+
},
|
|
318
|
+
[24]: {
|
|
319
|
+
enter: ({ state }) => isInsideTableCell(state) ? "<ul>" : void 0,
|
|
320
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</ul>" : void 0
|
|
321
|
+
},
|
|
322
|
+
[33]: {
|
|
323
|
+
enter: ({ state }) => isInsideTableCell(state) ? "<ol>" : void 0,
|
|
324
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</ol>" : void 0
|
|
325
|
+
},
|
|
326
|
+
[25]: {
|
|
327
|
+
enter: ({ node, state }) => {
|
|
328
|
+
if (isInsideTableCell(state)) return "<li>";
|
|
329
|
+
const marker = node.parent?.tagId === 33 ? `${orderedItemNumber(node.parent, node.index)}. ` : "- ";
|
|
330
|
+
return `${state.listIndent}${marker}`;
|
|
331
|
+
},
|
|
332
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</li>" : void 0,
|
|
333
|
+
spacing: LIST_ITEM_SPACING
|
|
334
|
+
},
|
|
335
|
+
[26]: {
|
|
336
|
+
enter: ({ node, state }) => {
|
|
337
|
+
if (node.attributes?.href !== void 0) {
|
|
338
|
+
if (stripsEmptyLink(state, node.attributes.href)) return;
|
|
339
|
+
if (isInsideRawHtmlBlock(state.depthMap)) return safeAnchorOutput(node, state.options, true, true);
|
|
340
|
+
return "[";
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
exit: ({ node, state }) => {
|
|
344
|
+
if (node.attributes?.href === void 0) return "";
|
|
345
|
+
if (stripsEmptyLink(state, node.attributes.href)) return "";
|
|
346
|
+
if (isInsideRawHtmlBlock(state.depthMap) && !node.tagHandler?.literalEnter) return safeAnchorOutput(node, state.options, false, true);
|
|
347
|
+
const href = resolveUrl(node.attributes.href, state.options?.origin, state.options?.clean);
|
|
348
|
+
let title = node.attributes?.title;
|
|
349
|
+
if (state.lastContentCache === title) title = "";
|
|
350
|
+
if (!title && isAutolinkUri(href)) {
|
|
351
|
+
const buf = state.buffer;
|
|
352
|
+
let i = buf.length - 1;
|
|
353
|
+
let textLen = 0;
|
|
354
|
+
let captionBracket = -1;
|
|
355
|
+
let captionTextLen = 0;
|
|
356
|
+
while (i >= 0) {
|
|
357
|
+
const entry = buf[i];
|
|
358
|
+
if (entry === "[") break;
|
|
359
|
+
if (captionBracket < 0 && state.depthMap?.[106] && entry.endsWith("*[")) {
|
|
360
|
+
captionBracket = i;
|
|
361
|
+
captionTextLen = textLen;
|
|
362
|
+
}
|
|
363
|
+
textLen += entry.length;
|
|
364
|
+
i--;
|
|
365
|
+
}
|
|
366
|
+
const captionLink = i < 0 && captionBracket >= 0;
|
|
367
|
+
if (captionLink) {
|
|
368
|
+
i = captionBracket;
|
|
369
|
+
textLen = captionTextLen;
|
|
370
|
+
}
|
|
371
|
+
if (i >= 0 && textLen === href.length && buf.slice(i + 1).join("") === href) {
|
|
372
|
+
if (captionLink) buf[i] = buf[i].slice(0, -1);
|
|
373
|
+
buf.length = i + (captionLink ? 1 : 0);
|
|
374
|
+
const auto = `<${href}>`;
|
|
375
|
+
buf.push(auto);
|
|
376
|
+
state.lastContentCache = auto;
|
|
377
|
+
return "";
|
|
585
378
|
}
|
|
586
379
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
380
|
+
return `]${serializeMarkdownResource(href, title)}`;
|
|
381
|
+
},
|
|
382
|
+
collapsesInnerWhiteSpace: true,
|
|
383
|
+
spacing: NO_SPACING,
|
|
384
|
+
isInline: true
|
|
385
|
+
},
|
|
386
|
+
[27]: {
|
|
387
|
+
enter: ({ node, state }) => {
|
|
388
|
+
const alt = node.attributes?.alt || "";
|
|
389
|
+
const rawSrc = node.attributes?.src || "";
|
|
390
|
+
const src = isDataUrl(rawSrc) ? "" : resolveUrl(rawSrc, state.options?.origin, state.options?.clean);
|
|
391
|
+
const clean = state.options?.clean;
|
|
392
|
+
if ((clean === true || clean !== void 0 && clean !== false && clean.emptyImages === true) && !alt.trim()) return void 0;
|
|
393
|
+
markRenderedChildContent(node);
|
|
394
|
+
return `![${serializeImageDescription(alt)}]${serializeMarkdownResource(src, node.attributes?.title)}`;
|
|
395
|
+
},
|
|
396
|
+
collapsesInnerWhiteSpace: true,
|
|
397
|
+
isSelfClosing: true,
|
|
398
|
+
spacing: NO_SPACING,
|
|
399
|
+
isInline: true
|
|
400
|
+
},
|
|
401
|
+
[28]: {
|
|
402
|
+
enter: ({ state }) => {
|
|
403
|
+
if (isInsideTableCell(state)) return "<table>";
|
|
404
|
+
if ((state.depthMap?.[28] || 0) <= 1) state.tableRenderedTable = false;
|
|
405
|
+
state.tableColumnAlignments = [];
|
|
406
|
+
state.tableHeaderCells = 0;
|
|
407
|
+
},
|
|
408
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</table>" : void 0
|
|
409
|
+
},
|
|
410
|
+
[107]: { enter: ({ state }) => {
|
|
411
|
+
if ((state.depthMap?.[25] || 0) === 0 || isInsideTableCell(state)) return void 0;
|
|
412
|
+
return blockOpenPrefix(state.buffer, state.listIndent);
|
|
413
|
+
} },
|
|
414
|
+
[29]: {
|
|
415
|
+
enter: ({ state }) => {
|
|
416
|
+
if (isInsideTableCell(state)) return "<thead>";
|
|
417
|
+
},
|
|
418
|
+
exit: ({ state }) => isInsideTableCell(state) ? "</thead>" : void 0,
|
|
419
|
+
spacing: TABLE_ROW_SPACING,
|
|
420
|
+
excludesTextNodes: true
|
|
421
|
+
},
|
|
422
|
+
[30]: {
|
|
423
|
+
enter: ({ node, state }) => {
|
|
424
|
+
if (isInsideTableCell(state)) return "<tr>";
|
|
425
|
+
state.tableCurrentRowCells = 0;
|
|
426
|
+
state.tableRowOpenerPending = !state.tableRenderedTable && !node.tagHandler?.literalEnter && !node.tagHandler?.literalExit;
|
|
427
|
+
if (state.tableRowOpenerPending) return void 0;
|
|
428
|
+
return rowMarker(state);
|
|
429
|
+
},
|
|
430
|
+
exit: ({ state }) => {
|
|
431
|
+
if (isInsideTableCell(state) || (state.depthMap?.[28] || 0) > 1) return "</tr>";
|
|
432
|
+
if (state.tableRowOpenerPending) {
|
|
433
|
+
state.tableRowOpenerPending = false;
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (!state.tableRenderedTable) {
|
|
437
|
+
state.tableRenderedTable = true;
|
|
438
|
+
const alignments = state.tableColumnAlignments;
|
|
439
|
+
while (alignments.length < state.tableCurrentRowCells) alignments.push("");
|
|
440
|
+
const alignmentMarkers = alignments.map((align) => {
|
|
441
|
+
switch (align) {
|
|
442
|
+
case "left": return ":---";
|
|
443
|
+
case "center": return ":---:";
|
|
444
|
+
case "right": return "---:";
|
|
445
|
+
default: return "---";
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
state.tableHeaderCells = alignments.length;
|
|
449
|
+
return ` |\n${(state.depthMap?.[25] || 0) > 0 ? state.listIndent : ""}| ${alignmentMarkers.join(" | ")} |`;
|
|
450
|
+
}
|
|
451
|
+
return " |";
|
|
452
|
+
},
|
|
453
|
+
excludesTextNodes: true,
|
|
454
|
+
spacing: TABLE_ROW_SPACING
|
|
455
|
+
},
|
|
456
|
+
[31]: {
|
|
457
|
+
enter: ({ node, state }) => {
|
|
458
|
+
if ((state.depthMap?.[28] || 0) > 1) return "<th>";
|
|
459
|
+
const align = node.attributes?.align?.toLowerCase();
|
|
460
|
+
if (align) state.tableColumnAlignments.push(align);
|
|
461
|
+
else if (state.tableColumnAlignments.length <= state.tableCurrentRowCells) state.tableColumnAlignments.push("");
|
|
462
|
+
return cellEnter(node, state);
|
|
463
|
+
},
|
|
464
|
+
exit: ({ node, state }) => {
|
|
465
|
+
if ((state.depthMap?.[28] || 0) > 1) return "</th>";
|
|
466
|
+
return cellExit(node, state);
|
|
467
|
+
},
|
|
468
|
+
collapsesInnerWhiteSpace: true,
|
|
469
|
+
spacing: NO_SPACING
|
|
470
|
+
},
|
|
471
|
+
[32]: {
|
|
472
|
+
enter: ({ node, state }) => {
|
|
473
|
+
if ((state.depthMap?.[28] || 0) > 1) return "<td>";
|
|
474
|
+
return cellEnter(node, state);
|
|
475
|
+
},
|
|
476
|
+
exit: ({ node, state }) => {
|
|
477
|
+
if ((state.depthMap?.[28] || 0) > 1) return "</td>";
|
|
478
|
+
return cellExit(node, state);
|
|
479
|
+
},
|
|
480
|
+
collapsesInnerWhiteSpace: true,
|
|
481
|
+
spacing: NO_SPACING
|
|
482
|
+
},
|
|
483
|
+
[35]: { enter: ({ state }) => {
|
|
484
|
+
if ((state.depthMap?.[25] || 0) > 0 && !isInsideTableCell(state)) {
|
|
485
|
+
const lastEntry = state.buffer.at(-1);
|
|
486
|
+
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
487
|
+
if (lastChar && lastChar !== " " && lastChar !== "\n") return `\n\n${state.listIndent}`;
|
|
488
|
+
}
|
|
489
|
+
} },
|
|
490
|
+
[36]: {},
|
|
491
|
+
[37]: {
|
|
492
|
+
collapsesInnerWhiteSpace: true,
|
|
493
|
+
spacing: NO_SPACING,
|
|
494
|
+
isInline: true
|
|
495
|
+
},
|
|
496
|
+
[41]: {},
|
|
497
|
+
[42]: {
|
|
498
|
+
collapsesInnerWhiteSpace: true,
|
|
499
|
+
spacing: NO_SPACING,
|
|
500
|
+
isInline: true
|
|
501
|
+
},
|
|
502
|
+
[43]: {
|
|
503
|
+
collapsesInnerWhiteSpace: true,
|
|
504
|
+
spacing: NO_SPACING,
|
|
505
|
+
isInline: true
|
|
506
|
+
},
|
|
507
|
+
[44]: { spacing: NO_SPACING },
|
|
508
|
+
[45]: {
|
|
509
|
+
enter: ({ state }) => {
|
|
510
|
+
if ((state.depthMap?.[28] || 0) > 1) return "<center>";
|
|
511
|
+
},
|
|
512
|
+
exit: ({ state }) => {
|
|
513
|
+
if ((state.depthMap?.[28] || 0) > 1) return "</center>";
|
|
514
|
+
},
|
|
515
|
+
spacing: NO_SPACING
|
|
516
|
+
},
|
|
517
|
+
[38]: {
|
|
518
|
+
spacing: NO_SPACING,
|
|
519
|
+
excludesTextNodes: true
|
|
520
|
+
},
|
|
521
|
+
[39]: {
|
|
522
|
+
spacing: TABLE_ROW_SPACING,
|
|
523
|
+
excludesTextNodes: true
|
|
524
|
+
},
|
|
525
|
+
[46]: {
|
|
526
|
+
enter: () => "`",
|
|
527
|
+
exit: () => "`",
|
|
528
|
+
collapsesInnerWhiteSpace: true,
|
|
529
|
+
spacing: NO_SPACING,
|
|
530
|
+
isInline: true
|
|
531
|
+
},
|
|
532
|
+
[47]: { spacing: NO_SPACING },
|
|
533
|
+
[40]: { spacing: NO_SPACING },
|
|
534
|
+
[54]: {
|
|
535
|
+
isSelfClosing: true,
|
|
536
|
+
spacing: NO_SPACING,
|
|
537
|
+
collapsesInnerWhiteSpace: true,
|
|
538
|
+
isInline: true
|
|
539
|
+
},
|
|
540
|
+
[55]: {
|
|
541
|
+
isSelfClosing: true,
|
|
542
|
+
spacing: NO_SPACING,
|
|
543
|
+
isInline: true,
|
|
544
|
+
collapsesInnerWhiteSpace: true
|
|
545
|
+
},
|
|
546
|
+
[56]: {
|
|
547
|
+
isSelfClosing: true,
|
|
548
|
+
spacing: NO_SPACING,
|
|
549
|
+
isInline: true,
|
|
550
|
+
collapsesInnerWhiteSpace: true
|
|
551
|
+
},
|
|
552
|
+
[57]: {
|
|
553
|
+
isSelfClosing: true,
|
|
554
|
+
spacing: NO_SPACING
|
|
555
|
+
},
|
|
556
|
+
[58]: {
|
|
557
|
+
isSelfClosing: true,
|
|
558
|
+
spacing: NO_SPACING
|
|
559
|
+
},
|
|
560
|
+
[59]: {
|
|
561
|
+
isSelfClosing: true,
|
|
562
|
+
spacing: NO_SPACING,
|
|
563
|
+
isInline: true,
|
|
564
|
+
collapsesInnerWhiteSpace: true
|
|
565
|
+
},
|
|
566
|
+
[60]: {
|
|
567
|
+
isSelfClosing: true,
|
|
568
|
+
spacing: NO_SPACING,
|
|
569
|
+
isInline: true,
|
|
570
|
+
collapsesInnerWhiteSpace: true
|
|
571
|
+
},
|
|
572
|
+
[61]: {
|
|
573
|
+
isSelfClosing: true,
|
|
574
|
+
spacing: NO_SPACING
|
|
575
|
+
},
|
|
576
|
+
[62]: {
|
|
577
|
+
isSelfClosing: true,
|
|
578
|
+
spacing: NO_SPACING
|
|
579
|
+
},
|
|
580
|
+
[63]: {
|
|
581
|
+
isSelfClosing: true,
|
|
582
|
+
spacing: NO_SPACING
|
|
583
|
+
},
|
|
584
|
+
[64]: {
|
|
585
|
+
isSelfClosing: true,
|
|
586
|
+
spacing: NO_SPACING,
|
|
587
|
+
isInline: true,
|
|
588
|
+
collapsesInnerWhiteSpace: true
|
|
589
|
+
},
|
|
590
|
+
[49]: { spacing: NO_SPACING },
|
|
591
|
+
[65]: { spacing: NO_SPACING },
|
|
592
|
+
[66]: {
|
|
593
|
+
isNonNesting: true,
|
|
594
|
+
spacing: NO_SPACING
|
|
595
|
+
},
|
|
596
|
+
[67]: { spacing: NO_SPACING },
|
|
597
|
+
[109]: { spacing: NO_SPACING },
|
|
598
|
+
[68]: { spacing: NO_SPACING },
|
|
599
|
+
[69]: { spacing: NO_SPACING },
|
|
600
|
+
[70]: { spacing: NO_SPACING },
|
|
601
|
+
[71]: { spacing: NO_SPACING },
|
|
602
|
+
[72]: { spacing: NO_SPACING },
|
|
603
|
+
[73]: { ...INERT_RAWTEXT },
|
|
604
|
+
[74]: { spacing: NO_SPACING },
|
|
605
|
+
[75]: { spacing: NO_SPACING },
|
|
606
|
+
[76]: { spacing: NO_SPACING },
|
|
607
|
+
[77]: { spacing: NO_SPACING },
|
|
608
|
+
[78]: {
|
|
609
|
+
excludesTextNodes: true,
|
|
610
|
+
spacing: NO_SPACING
|
|
611
|
+
},
|
|
612
|
+
[79]: {
|
|
613
|
+
enter: () => "",
|
|
614
|
+
exit: () => "",
|
|
615
|
+
collapsesInnerWhiteSpace: true,
|
|
616
|
+
spacing: NO_SPACING,
|
|
617
|
+
isInline: true
|
|
618
|
+
},
|
|
619
|
+
[80]: {
|
|
620
|
+
enter: () => "<mark>",
|
|
621
|
+
exit: () => "</mark>",
|
|
622
|
+
collapsesInnerWhiteSpace: true,
|
|
623
|
+
spacing: NO_SPACING,
|
|
624
|
+
isInline: true
|
|
625
|
+
},
|
|
626
|
+
[81]: {
|
|
627
|
+
enter: () => "\"",
|
|
628
|
+
exit: () => "\"",
|
|
629
|
+
collapsesInnerWhiteSpace: true,
|
|
630
|
+
spacing: NO_SPACING,
|
|
631
|
+
isInline: true
|
|
632
|
+
},
|
|
633
|
+
[82]: {
|
|
634
|
+
enter: () => "`",
|
|
635
|
+
exit: () => "`",
|
|
636
|
+
collapsesInnerWhiteSpace: true,
|
|
637
|
+
spacing: NO_SPACING,
|
|
638
|
+
isInline: true
|
|
639
|
+
},
|
|
640
|
+
[83]: {
|
|
641
|
+
enter: () => "",
|
|
642
|
+
exit: () => "",
|
|
643
|
+
collapsesInnerWhiteSpace: true,
|
|
644
|
+
spacing: NO_SPACING,
|
|
645
|
+
isInline: true
|
|
646
|
+
},
|
|
647
|
+
[84]: { ...INERT_RAWTEXT },
|
|
648
|
+
[112]: { ...INERT_RAWTEXT },
|
|
649
|
+
[108]: {
|
|
650
|
+
isNonNesting: true,
|
|
651
|
+
excludesTextNodes: true,
|
|
652
|
+
spacing: NO_SPACING
|
|
653
|
+
},
|
|
654
|
+
[85]: { ...INERT_RAWTEXT },
|
|
655
|
+
[86]: {
|
|
656
|
+
isNonNesting: true,
|
|
657
|
+
spacing: NO_SPACING
|
|
658
|
+
},
|
|
659
|
+
[87]: {
|
|
660
|
+
isNonNesting: true,
|
|
661
|
+
spacing: NO_SPACING
|
|
662
|
+
},
|
|
663
|
+
[88]: { spacing: NO_SPACING },
|
|
664
|
+
[89]: {
|
|
665
|
+
enter: () => {
|
|
666
|
+
return "<u>";
|
|
667
|
+
},
|
|
668
|
+
exit: () => {
|
|
669
|
+
return "</u>";
|
|
670
|
+
},
|
|
671
|
+
collapsesInnerWhiteSpace: true,
|
|
672
|
+
spacing: NO_SPACING,
|
|
673
|
+
isInline: true
|
|
674
|
+
},
|
|
675
|
+
[90]: {
|
|
676
|
+
enter: () => "*",
|
|
677
|
+
exit: () => "*",
|
|
678
|
+
collapsesInnerWhiteSpace: true,
|
|
679
|
+
spacing: NO_SPACING,
|
|
680
|
+
isInline: true
|
|
681
|
+
},
|
|
682
|
+
[91]: {
|
|
683
|
+
enter: () => "**",
|
|
684
|
+
exit: () => "**",
|
|
685
|
+
collapsesInnerWhiteSpace: true,
|
|
686
|
+
spacing: NO_SPACING,
|
|
687
|
+
isInline: true
|
|
688
|
+
},
|
|
689
|
+
[92]: {
|
|
690
|
+
enter: () => "`",
|
|
691
|
+
exit: () => "`",
|
|
692
|
+
collapsesInnerWhiteSpace: true,
|
|
693
|
+
spacing: NO_SPACING,
|
|
694
|
+
isInline: true
|
|
695
|
+
},
|
|
696
|
+
[93]: {
|
|
697
|
+
enter: () => "",
|
|
698
|
+
exit: () => "",
|
|
699
|
+
collapsesInnerWhiteSpace: true,
|
|
700
|
+
spacing: NO_SPACING,
|
|
701
|
+
isInline: true
|
|
702
|
+
},
|
|
703
|
+
[94]: {
|
|
704
|
+
enter: () => "",
|
|
705
|
+
exit: () => "",
|
|
706
|
+
collapsesInnerWhiteSpace: true,
|
|
707
|
+
spacing: NO_SPACING,
|
|
708
|
+
isInline: true
|
|
709
|
+
},
|
|
710
|
+
[95]: {
|
|
711
|
+
enter: () => "",
|
|
712
|
+
exit: () => "",
|
|
713
|
+
collapsesInnerWhiteSpace: true,
|
|
714
|
+
spacing: NO_SPACING,
|
|
715
|
+
isInline: true
|
|
716
|
+
},
|
|
717
|
+
[96]: {
|
|
718
|
+
enter: () => "",
|
|
719
|
+
exit: () => "",
|
|
720
|
+
collapsesInnerWhiteSpace: true,
|
|
721
|
+
spacing: NO_SPACING,
|
|
722
|
+
isInline: true
|
|
723
|
+
},
|
|
724
|
+
[97]: {
|
|
725
|
+
enter: () => "",
|
|
726
|
+
exit: () => "",
|
|
727
|
+
collapsesInnerWhiteSpace: true,
|
|
728
|
+
spacing: NO_SPACING,
|
|
729
|
+
isInline: true
|
|
730
|
+
},
|
|
731
|
+
[100]: {
|
|
732
|
+
enter: () => "<address>",
|
|
733
|
+
exit: () => "</address>",
|
|
734
|
+
spacing: NO_SPACING,
|
|
735
|
+
collapsesInnerWhiteSpace: true
|
|
736
|
+
},
|
|
737
|
+
[101]: {
|
|
738
|
+
spacing: NO_SPACING,
|
|
739
|
+
enter: () => "<dl>",
|
|
740
|
+
exit: () => "</dl>"
|
|
741
|
+
},
|
|
742
|
+
[99]: {
|
|
743
|
+
enter: () => "<dt>",
|
|
744
|
+
exit: () => "</dt>",
|
|
745
|
+
collapsesInnerWhiteSpace: true,
|
|
746
|
+
spacing: [0, 1]
|
|
747
|
+
},
|
|
748
|
+
[98]: {
|
|
749
|
+
enter: () => "<dd>",
|
|
750
|
+
exit: () => "</dd>",
|
|
751
|
+
spacing: [0, 1]
|
|
752
|
+
},
|
|
753
|
+
[50]: {},
|
|
754
|
+
[51]: {},
|
|
755
|
+
[105]: {},
|
|
756
|
+
[104]: {},
|
|
757
|
+
[102]: {},
|
|
758
|
+
[106]: {
|
|
759
|
+
exit: () => "*",
|
|
760
|
+
collapsesInnerWhiteSpace: true,
|
|
761
|
+
isInline: true
|
|
762
|
+
}
|
|
763
|
+
};
|
|
592
764
|
const INLINE_MARKER_TYPE = /* @__PURE__ */ new Uint8Array(113);
|
|
593
765
|
const MARKER_TYPE_MASK = 7;
|
|
594
766
|
const CAPTION_FRAME_SIZE = 4;
|
|
@@ -667,6 +839,7 @@ function resolveItemMarker(state, atExit, unresolvedCaptionFragment = -1) {
|
|
|
667
839
|
}
|
|
668
840
|
}
|
|
669
841
|
if (first === -1 && !atExit) return;
|
|
842
|
+
if (first === 10 && !atExit) return;
|
|
670
843
|
if (!atExit && unresolvedCaptionFragment !== -1) {
|
|
671
844
|
let captionOpensItem = true;
|
|
672
845
|
for (let index = fragment + 1; index < unresolvedCaptionFragment; index++) if (hasNonWhitespace(buffer[index])) {
|
|
@@ -677,14 +850,15 @@ function resolveItemMarker(state, atExit, unresolvedCaptionFragment = -1) {
|
|
|
677
850
|
}
|
|
678
851
|
state.emptyItemFragment = void 0;
|
|
679
852
|
if (first !== -1 && first !== 10) return;
|
|
680
|
-
|
|
853
|
+
const replacement = `\n${buffer[fragment]}`;
|
|
854
|
+
state.outputPositions?.replace(fragment, fragment + 1, [replacement], (offset) => offset + 1);
|
|
855
|
+
buffer[fragment] = replacement;
|
|
681
856
|
}
|
|
682
857
|
function updateListIndent(state, element, eventType) {
|
|
683
858
|
if (element.tagId !== 25) return;
|
|
684
859
|
if (isInsideTableCell(state)) return;
|
|
685
860
|
if (eventType === 0) {
|
|
686
|
-
const
|
|
687
|
-
const width = state.plainText ? 0 : isOrdered ? String(orderedItemNumber(element.parent, element.index)).length + 2 : 2;
|
|
861
|
+
const width = element.parent?.tagId === 33 ? String(orderedItemNumber(element.parent, element.index)).length + 2 : 2;
|
|
688
862
|
state.listIndentWidths.push(width);
|
|
689
863
|
state.listIndent += " ".repeat(width);
|
|
690
864
|
} else if (eventType === 1) {
|
|
@@ -699,7 +873,7 @@ function needsSpacing(lastChar, firstChar, state) {
|
|
|
699
873
|
}
|
|
700
874
|
function shouldAddSpacingBeforeText(lastChar, lastNode, textNode) {
|
|
701
875
|
if (!lastChar || "\n [>".includes(lastChar)) return false;
|
|
702
|
-
if (lastNode
|
|
876
|
+
if (textNode.joinsPrevious || lastNode && (lastNode.tagHandler ? lastNode.tagHandler.isInline : lastNode.tagId === -1)) return false;
|
|
703
877
|
const firstChar = textNode.value[0];
|
|
704
878
|
if (firstChar === " ") return false;
|
|
705
879
|
if (firstChar && ".,!?:;_*`)]".includes(firstChar)) return false;
|
|
@@ -761,12 +935,6 @@ function escapeRawHtmlText(value, depthMap, protectLinkText) {
|
|
|
761
935
|
}
|
|
762
936
|
return copiedUntil === 0 ? value : escaped + value.slice(copiedUntil);
|
|
763
937
|
}
|
|
764
|
-
function resetBufferScanCursors(scan) {
|
|
765
|
-
scan[1] = 0;
|
|
766
|
-
scan[2] = 0;
|
|
767
|
-
scan[3] = 0;
|
|
768
|
-
scan[4] = 0;
|
|
769
|
-
}
|
|
770
938
|
function trackRawHtmlMarkdownContext(buffer, scan) {
|
|
771
939
|
if (scan[0]) return true;
|
|
772
940
|
let index = scan[1];
|
|
@@ -790,16 +958,21 @@ function lineOpensRawHtmlBlock(buffer, scan) {
|
|
|
790
958
|
scanned = 0;
|
|
791
959
|
scan[3] = 0;
|
|
792
960
|
scan[4] = 0;
|
|
961
|
+
scan[5] = void 0;
|
|
962
|
+
scan[6] = 0;
|
|
793
963
|
}
|
|
794
964
|
for (let index = scanned; index < buffer.length; index++) {
|
|
795
965
|
const newline = buffer[index].lastIndexOf("\n");
|
|
796
966
|
if (newline !== -1) {
|
|
797
967
|
scan[3] = index;
|
|
798
968
|
scan[4] = newline + 1;
|
|
969
|
+
scan[5] = void 0;
|
|
970
|
+
scan[6] = 0;
|
|
799
971
|
}
|
|
800
972
|
}
|
|
801
973
|
scan[2] = buffer.length;
|
|
802
|
-
|
|
974
|
+
if (scan[5] !== void 0) return scan[5];
|
|
975
|
+
let spaces = scan[6];
|
|
803
976
|
let offset = scan[4];
|
|
804
977
|
for (let index = scan[3]; index < buffer.length; index++) {
|
|
805
978
|
const fragment = buffer[index];
|
|
@@ -811,7 +984,9 @@ function lineOpensRawHtmlBlock(buffer, scan) {
|
|
|
811
984
|
}
|
|
812
985
|
offset = 0;
|
|
813
986
|
}
|
|
814
|
-
|
|
987
|
+
scan[6] = spaces;
|
|
988
|
+
scan[3] = buffer.length;
|
|
989
|
+
scan[4] = 0;
|
|
815
990
|
}
|
|
816
991
|
function markdownLineIndent(buffer) {
|
|
817
992
|
let spaces = 0;
|
|
@@ -918,11 +1093,19 @@ function currentColumn(buffer) {
|
|
|
918
1093
|
for (let i = buffer.length - 1; i >= 0; i--) {
|
|
919
1094
|
const s = buffer[i];
|
|
920
1095
|
const nl = s.lastIndexOf("\n");
|
|
921
|
-
if (nl >= 0) return col +
|
|
922
|
-
col +=
|
|
1096
|
+
if (nl >= 0) return col + columnWidth(s, nl + 1);
|
|
1097
|
+
col += columnWidth(s, 0);
|
|
923
1098
|
}
|
|
924
1099
|
return col;
|
|
925
1100
|
}
|
|
1101
|
+
function columnWidth(value, start) {
|
|
1102
|
+
let width = 0;
|
|
1103
|
+
for (let i = start; i < value.length; i++) {
|
|
1104
|
+
const code = value.charCodeAt(i);
|
|
1105
|
+
if ((code & 64512) !== 56320 && code !== 64976 && code !== 64977) width++;
|
|
1106
|
+
}
|
|
1107
|
+
return width;
|
|
1108
|
+
}
|
|
926
1109
|
function wrapText(value, col, width, prefix) {
|
|
927
1110
|
const leading = value.charCodeAt(0) === 32;
|
|
928
1111
|
const trailing = value.charCodeAt(value.length - 1) === 32;
|
|
@@ -955,13 +1138,10 @@ function wrapText(value, col, width, prefix) {
|
|
|
955
1138
|
if (out === "" && (leading || trailing)) out = " ";
|
|
956
1139
|
return out;
|
|
957
1140
|
}
|
|
958
|
-
function calculateNewLineConfig(node,
|
|
1141
|
+
function calculateNewLineConfig(node, state, eventType) {
|
|
1142
|
+
const depthMap = state.depthMap;
|
|
959
1143
|
const tagId = node.tagId;
|
|
960
|
-
if (
|
|
961
|
-
if (tagId !== 25 && (depthMap[25] || 0) > 0 || plainText && tagId !== 22 && (depthMap[22] || 0) > 0) {
|
|
962
|
-
if (plainText && tagId === 34) return [1, 1];
|
|
963
|
-
return NO_SPACING;
|
|
964
|
-
}
|
|
1144
|
+
if (tagId !== 25 && (depthMap[25] || 0) > 0) return NO_SPACING;
|
|
965
1145
|
const isBlockElement = tagId !== void 0 && (tagId >= 7 && tagId <= 12 || tagId === 35 || tagId === 36 || tagId === 25 || tagId === 106);
|
|
966
1146
|
let currParent = node.parent;
|
|
967
1147
|
while (currParent) {
|
|
@@ -970,6 +1150,10 @@ function calculateNewLineConfig(node, depthMap, plainText) {
|
|
|
970
1150
|
currParent = currParent.parent;
|
|
971
1151
|
continue;
|
|
972
1152
|
}
|
|
1153
|
+
if (eventType === 1 && tagId !== void 0 && tagId >= 7 && tagId <= 12 && !isInsideTableCell(state) && !wrapperEmitsInlineMarkdown(currParent, state)) {
|
|
1154
|
+
currParent = currParent.parent;
|
|
1155
|
+
continue;
|
|
1156
|
+
}
|
|
973
1157
|
return NO_SPACING;
|
|
974
1158
|
}
|
|
975
1159
|
currParent = currParent.parent;
|
|
@@ -978,6 +1162,12 @@ function calculateNewLineConfig(node, depthMap, plainText) {
|
|
|
978
1162
|
if (tagId === -1) return NO_SPACING;
|
|
979
1163
|
return DEFAULT_BLOCK_SPACING;
|
|
980
1164
|
}
|
|
1165
|
+
function wrapperEmitsInlineMarkdown(node, state) {
|
|
1166
|
+
const handler = node.tagHandler;
|
|
1167
|
+
if (node.hasEnterOutput || handler?.literalExit && handler.literalExitHasOutput !== false) return true;
|
|
1168
|
+
const tagId = node.tagId;
|
|
1169
|
+
return INLINE_MARKER_TYPE[tagId] !== void 0 && INLINE_MARKER_TYPE[tagId] !== 0 || tagId === 26 && (node.attributes?.href !== void 0 || isInsideRawHtmlBlock(state.depthMap)) || tagId === 19 || tagId === 20 || tagId === 21 || tagId === 89 || tagId === 80;
|
|
1170
|
+
}
|
|
981
1171
|
function hasNonWhitespace(value) {
|
|
982
1172
|
for (let i = 0; i < value.length; i++) {
|
|
983
1173
|
const c = value.charCodeAt(i);
|
|
@@ -993,23 +1183,9 @@ function trimAsciiWhitespaceEnd(value) {
|
|
|
993
1183
|
while (end > 0 && isAsciiWhitespace(value.charCodeAt(end - 1))) end--;
|
|
994
1184
|
return end === value.length ? value : value.slice(0, end);
|
|
995
1185
|
}
|
|
996
|
-
function
|
|
997
|
-
let position = 0;
|
|
998
|
-
for (let index = 0; index < fragment; index++) position += buffer[index].length;
|
|
999
|
-
return position;
|
|
1000
|
-
}
|
|
1001
|
-
function trimBufferedWhitespacePosition(content, position) {
|
|
1002
|
-
let end = Math.max(0, position);
|
|
1003
|
-
while (end > 0) {
|
|
1004
|
-
const code = content.charCodeAt(end - 1);
|
|
1005
|
-
if (code !== 32 && code !== 10) break;
|
|
1006
|
-
end--;
|
|
1007
|
-
}
|
|
1008
|
-
return end;
|
|
1009
|
-
}
|
|
1010
|
-
function dropEmptyMarker(buffer, packed, markerType) {
|
|
1186
|
+
function dropEmptyMarker(buffer, packed, markerType, positions) {
|
|
1011
1187
|
const idx = packed >> 3;
|
|
1012
|
-
if ((packed & MARKER_TYPE_MASK) === markerType && idx < buffer.length) return dropEmptyLinkText(buffer, idx) ? idx : -1;
|
|
1188
|
+
if ((packed & MARKER_TYPE_MASK) === markerType && idx < buffer.length) return dropEmptyLinkText(buffer, idx, positions) ? idx : -1;
|
|
1013
1189
|
return -1;
|
|
1014
1190
|
}
|
|
1015
1191
|
function resetRetractedCaptionFrames(frames, count, fragment) {
|
|
@@ -1022,8 +1198,9 @@ function resetRetractedCaptionFrames(frames, count, fragment) {
|
|
|
1022
1198
|
}
|
|
1023
1199
|
}
|
|
1024
1200
|
}
|
|
1025
|
-
function dropEmptyLinkText(buffer, openFragment) {
|
|
1201
|
+
function dropEmptyLinkText(buffer, openFragment, positions) {
|
|
1026
1202
|
for (let index = openFragment + 1; index < buffer.length; index++) if (hasNonWhitespace(buffer[index])) return false;
|
|
1203
|
+
positions?.replace(openFragment, buffer.length, []);
|
|
1027
1204
|
buffer.length = openFragment;
|
|
1028
1205
|
return true;
|
|
1029
1206
|
}
|
|
@@ -1067,13 +1244,21 @@ function maxLineLeadingRun(value, marker, indent) {
|
|
|
1067
1244
|
function finalizeCodeSpan(state, span) {
|
|
1068
1245
|
let content = state.buffer.slice(span.fragment + 1).join("");
|
|
1069
1246
|
if ((state.depthMap[28] || 0) > 0 && content.includes("|")) {
|
|
1247
|
+
const original = content;
|
|
1070
1248
|
content = content.replaceAll("|", "\\|");
|
|
1249
|
+
state.outputPositions?.replace(span.fragment + 1, state.buffer.length, [content], (offset) => {
|
|
1250
|
+
let added = 0;
|
|
1251
|
+
for (let index = 0; index < offset; index++) if (original.charCodeAt(index) === 124) added++;
|
|
1252
|
+
return offset + added;
|
|
1253
|
+
});
|
|
1071
1254
|
state.buffer.length = span.fragment + 1;
|
|
1072
1255
|
state.buffer.push(content);
|
|
1073
1256
|
}
|
|
1074
1257
|
const delimiter = "`".repeat(Math.max(1, maxBacktickRun(content) + 1));
|
|
1075
1258
|
const padded = content.startsWith("`") || content.endsWith("`");
|
|
1076
|
-
|
|
1259
|
+
const opening = `${span.prefix}${delimiter}${padded ? " " : ""}`;
|
|
1260
|
+
if (state.outputPositions && opening !== state.buffer[span.fragment]) state.outputPositions?.replace(span.fragment, span.fragment + 1, [opening]);
|
|
1261
|
+
state.buffer[span.fragment] = opening;
|
|
1077
1262
|
return `${padded ? " " : ""}${delimiter}`;
|
|
1078
1263
|
}
|
|
1079
1264
|
function startCodeFence(state, fragment, language, indent) {
|
|
@@ -1094,49 +1279,110 @@ function finalizeCodeFence(state) {
|
|
|
1094
1279
|
const content = state.buffer.slice(fence.fragment + 1).join("");
|
|
1095
1280
|
const delimiter = marker.repeat(Math.max(3, maxLineLeadingRun(content, markerCode, fence.indent) + 1));
|
|
1096
1281
|
const opening = state.buffer[fence.fragment];
|
|
1097
|
-
|
|
1282
|
+
const replacement = `${opening.slice(0, fence.markerOffset)}${delimiter}${opening.slice(fence.markerOffset + 3)}`;
|
|
1283
|
+
if (state.outputPositions && replacement !== opening) state.outputPositions?.replace(fence.fragment, fence.fragment + 1, [replacement], (offset) => offset <= fence.markerOffset ? offset : offset + delimiter.length - 3);
|
|
1284
|
+
state.buffer[fence.fragment] = replacement;
|
|
1098
1285
|
return delimiter;
|
|
1099
1286
|
}
|
|
1100
1287
|
function stripBlockquoteListIndent(line, listIndent) {
|
|
1101
1288
|
return listIndent && line.startsWith(listIndent) ? line.slice(listIndent.length) : line;
|
|
1102
1289
|
}
|
|
1290
|
+
function quotedOffset(content, listIndent, offset) {
|
|
1291
|
+
if (offset > content.length) return -1;
|
|
1292
|
+
let sourceStart = 0;
|
|
1293
|
+
let outputStart = 0;
|
|
1294
|
+
while (true) {
|
|
1295
|
+
const newline = content.indexOf("\n", sourceStart);
|
|
1296
|
+
const lineEnd = newline === -1 ? content.length : newline;
|
|
1297
|
+
const removed = listIndent && content.startsWith(listIndent, sourceStart) ? listIndent.length : 0;
|
|
1298
|
+
const unindentedLength = Math.max(0, lineEnd - sourceStart - removed);
|
|
1299
|
+
const prefixLength = listIndent.length + 1 + (unindentedLength > 0 ? 1 : 0);
|
|
1300
|
+
if (offset <= lineEnd) return outputStart + prefixLength + Math.max(0, offset - sourceStart - removed);
|
|
1301
|
+
outputStart += prefixLength + unindentedLength + 1;
|
|
1302
|
+
sourceStart = lineEnd + 1;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1103
1305
|
function finalizeBlockquote(state) {
|
|
1104
1306
|
const frame = state.blockquotes.pop();
|
|
1105
1307
|
if (!frame) return;
|
|
1106
1308
|
state.bufferedBlockquoteDepth = state.blockquotes.length;
|
|
1107
|
-
const
|
|
1309
|
+
const buffer = state.buffer;
|
|
1310
|
+
const content = trimAsciiWhitespaceEnd(buffer.slice(frame.fragment).join(""));
|
|
1311
|
+
if (!content && frame.followsWhitespace) return;
|
|
1108
1312
|
const prefix = `${frame.listIndent}>`;
|
|
1109
1313
|
const quoted = content.split("\n").map((line) => {
|
|
1110
1314
|
const unindented = stripBlockquoteListIndent(line, frame.listIndent);
|
|
1111
1315
|
return unindented ? `${prefix} ${unindented}` : prefix;
|
|
1112
1316
|
}).join("\n");
|
|
1113
|
-
|
|
1317
|
+
let sourceStart = 0;
|
|
1318
|
+
let quotedStart = 0;
|
|
1319
|
+
const mapPosition = state.outputPositions ? (position, kind) => {
|
|
1320
|
+
const offset = Math.min(position, content.length);
|
|
1321
|
+
while (true) {
|
|
1322
|
+
const newline = content.indexOf("\n", sourceStart);
|
|
1323
|
+
const lineEnd = newline === -1 ? content.length : newline;
|
|
1324
|
+
const removed = frame.listIndent && content.startsWith(frame.listIndent, sourceStart) ? frame.listIndent.length : 0;
|
|
1325
|
+
const lineLength = Math.max(0, lineEnd - sourceStart - removed);
|
|
1326
|
+
const prefixLength = frame.listIndent.length + 1 + (lineLength > 0 ? 1 : 0);
|
|
1327
|
+
if (offset <= lineEnd) return kind === "boundary" && offset === sourceStart ? quotedStart : quotedStart + prefixLength + Math.max(0, offset - sourceStart - removed);
|
|
1328
|
+
quotedStart += prefixLength + lineLength + 1;
|
|
1329
|
+
sourceStart = lineEnd + 1;
|
|
1330
|
+
}
|
|
1331
|
+
} : void 0;
|
|
1332
|
+
const fence = state.codeFence;
|
|
1333
|
+
if (fence && fence.fragment >= frame.fragment) {
|
|
1334
|
+
let openerStart = 0;
|
|
1335
|
+
for (let index = frame.fragment; index < fence.fragment; index++) openerStart += buffer[index].length;
|
|
1336
|
+
const openerEnd = openerStart + buffer[fence.fragment].length;
|
|
1337
|
+
const remap = (offset) => {
|
|
1338
|
+
const mapped = quotedOffset(content, frame.listIndent, offset);
|
|
1339
|
+
return mapped === -1 ? quoted.length : mapped;
|
|
1340
|
+
};
|
|
1341
|
+
const start = remap(openerStart);
|
|
1342
|
+
const end = remap(openerEnd);
|
|
1343
|
+
fence.markerOffset = remap(openerStart + fence.markerOffset) - start;
|
|
1344
|
+
if (state.outputPositions) {
|
|
1345
|
+
const replacement = [quoted.slice(start, end)];
|
|
1346
|
+
if (start > 0) replacement.unshift(quoted.slice(0, start));
|
|
1347
|
+
if (end < quoted.length) replacement.push(quoted.slice(end));
|
|
1348
|
+
state.outputPositions.replace(frame.fragment, buffer.length, replacement, mapPosition);
|
|
1349
|
+
}
|
|
1350
|
+
buffer.length = frame.fragment;
|
|
1351
|
+
if (start > 0) buffer.push(quoted.slice(0, start));
|
|
1352
|
+
fence.fragment = buffer.length;
|
|
1353
|
+
buffer.push(quoted.slice(start, end));
|
|
1354
|
+
if (end < quoted.length) buffer.push(quoted.slice(end));
|
|
1355
|
+
state.lastContentCache = buffer.at(-1);
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1358
|
+
state.outputPositions?.replace(frame.fragment, buffer.length, [quoted], mapPosition);
|
|
1359
|
+
buffer.splice(frame.fragment, buffer.length - frame.fragment, quoted);
|
|
1114
1360
|
state.lastContentCache = quoted;
|
|
1115
1361
|
}
|
|
1116
|
-
function collapseNestedBlockquoteSeparator(buffer) {
|
|
1362
|
+
function collapseNestedBlockquoteSeparator(buffer, positions) {
|
|
1117
1363
|
if (newlineRunBefore(buffer, buffer.length) < 2) return;
|
|
1118
1364
|
const last = buffer.at(-1);
|
|
1365
|
+
positions?.replace(buffer.length - 1, buffer.length, last.length === 1 ? [] : [last.slice(0, -1)]);
|
|
1119
1366
|
if (last.length === 1) buffer.pop();
|
|
1120
1367
|
else buffer[buffer.length - 1] = last.slice(0, -1);
|
|
1121
1368
|
}
|
|
1122
1369
|
function flushPreFence(state) {
|
|
1123
|
-
if (state.plainText) {
|
|
1124
|
-
state.preFencePending = false;
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
1370
|
state.preFencePending = false;
|
|
1128
|
-
state.
|
|
1371
|
+
state.preFenceOwnerDepth = state.preFencePendingDepth;
|
|
1129
1372
|
const lang = state.preFenceLang || "";
|
|
1130
1373
|
const fence = (state.depthMap[25] || 0) > 0 ? `${blockOpenPrefix(state.buffer, state.listIndent) ?? ""}\`\`\`${lang}\n${state.listIndent}` : `\`\`\`${lang}\n`;
|
|
1131
1374
|
state.buffer.push(fence);
|
|
1132
1375
|
startCodeFence(state, state.buffer.length - 1, lang, state.listIndent);
|
|
1133
1376
|
state.lastContentCache = fence;
|
|
1134
1377
|
}
|
|
1378
|
+
function codeOwnsPendingPreFence(state, element) {
|
|
1379
|
+
return element.tagId === 23 && element.parent?.tagId === 34 && state.depthMap[34] === state.preFencePendingDepth;
|
|
1380
|
+
}
|
|
1135
1381
|
function consumePendingPreChild(state, node, eventType, beforeFlush) {
|
|
1136
1382
|
if (eventType !== 0) return false;
|
|
1137
1383
|
if (node.type === 1) {
|
|
1138
1384
|
const element = node;
|
|
1139
|
-
if (
|
|
1385
|
+
if (codeOwnsPendingPreFence(state, element)) state.preFencePending = false;
|
|
1140
1386
|
else if (element.tagId !== 34 && element.tagId !== 106 && !suppressesFormattingInPre(element.tagId)) {
|
|
1141
1387
|
beforeFlush();
|
|
1142
1388
|
flushPreFence(state);
|
|
@@ -1157,15 +1403,18 @@ function consumeGfmAction(action, state, lifecycle) {
|
|
|
1157
1403
|
finalizeBlockquote(state);
|
|
1158
1404
|
return;
|
|
1159
1405
|
case "PreEnter":
|
|
1160
|
-
state.preFencePending
|
|
1161
|
-
|
|
1162
|
-
|
|
1406
|
+
if (!state.preFenceOwnerDepth && !state.preFencePending) {
|
|
1407
|
+
state.preFencePending = true;
|
|
1408
|
+
state.preFencePendingDepth = state.depthMap[34];
|
|
1409
|
+
state.preFenceLang = action.language;
|
|
1410
|
+
}
|
|
1163
1411
|
return;
|
|
1164
1412
|
case "PreExit": {
|
|
1165
|
-
const
|
|
1166
|
-
state.preFencePending = false;
|
|
1167
|
-
state.
|
|
1168
|
-
|
|
1413
|
+
const depth = state.depthMap[34] + 1;
|
|
1414
|
+
if (state.preFencePendingDepth === depth) state.preFencePending = false;
|
|
1415
|
+
if (state.preFenceOwnerDepth !== depth) return void 0;
|
|
1416
|
+
state.preFenceOwnerDepth = 0;
|
|
1417
|
+
state.lastTextNode = void 0;
|
|
1169
1418
|
const indent = state.listIndent;
|
|
1170
1419
|
const output = (state.depthMap[25] || 0) > 0 ? `\n${indent}\`\`\`\n\n${indent}` : `\n\`\`\``;
|
|
1171
1420
|
const delimiter = finalizeCodeFence(state);
|
|
@@ -1178,22 +1427,26 @@ function consumeGfmAction(action, state, lifecycle) {
|
|
|
1178
1427
|
}
|
|
1179
1428
|
case "CodeFenceEnter":
|
|
1180
1429
|
state.preFencePending = false;
|
|
1181
|
-
state.
|
|
1430
|
+
state.preFenceOwnerDepth = state.depthMap[34];
|
|
1182
1431
|
return action.output;
|
|
1183
1432
|
}
|
|
1184
1433
|
}
|
|
1185
|
-
function commitGfmAction(action, state, lifecycle, outputStart) {
|
|
1434
|
+
function commitGfmAction(action, state, lifecycle, outputStart, owner) {
|
|
1186
1435
|
switch (action._tag) {
|
|
1187
|
-
case "BlockquoteEnter":
|
|
1188
|
-
if (state.blockquotes.length > 0) collapseNestedBlockquoteSeparator(state.buffer);
|
|
1436
|
+
case "BlockquoteEnter": {
|
|
1437
|
+
if (state.blockquotes.length > 0) collapseNestedBlockquoteSeparator(state.buffer, state.outputPositions);
|
|
1438
|
+
const before = lastOutputChar(state.buffer);
|
|
1189
1439
|
state.blockquotes.push({
|
|
1190
1440
|
fragment: state.buffer.length,
|
|
1191
|
-
listIndent: state.listIndent
|
|
1441
|
+
listIndent: state.listIndent,
|
|
1442
|
+
followsWhitespace: before === -1 ? state.lastContentCache !== void 0 && isAsciiWhitespace(state.lastContentCache.charCodeAt(state.lastContentCache.length - 1)) : isAsciiWhitespace(before)
|
|
1192
1443
|
});
|
|
1193
1444
|
state.bufferedBlockquoteDepth = state.blockquotes.length;
|
|
1194
1445
|
break;
|
|
1446
|
+
}
|
|
1195
1447
|
case "CodeSpanEnter":
|
|
1196
1448
|
lifecycle.openCodeSpans.push({
|
|
1449
|
+
owner,
|
|
1197
1450
|
fragment: outputStart,
|
|
1198
1451
|
prefix: action.output.slice(0, -1)
|
|
1199
1452
|
});
|
|
@@ -1206,56 +1459,34 @@ function commitGfmAction(action, state, lifecycle, outputStart) {
|
|
|
1206
1459
|
}
|
|
1207
1460
|
}
|
|
1208
1461
|
}
|
|
1209
|
-
function
|
|
1210
|
-
const override = state.options?.plugins?.tagOverrides?.[node.name];
|
|
1211
|
-
if (override && typeof override !== "string") {
|
|
1212
|
-
const explicitOutput = eventType === 0 ? override.enter : override.exit;
|
|
1213
|
-
if (explicitOutput !== void 0) return explicitOutput;
|
|
1214
|
-
}
|
|
1215
|
-
const tagId = node.tagId;
|
|
1216
|
-
const depthMap = state.depthMap;
|
|
1217
|
-
if (eventType === 0) {
|
|
1218
|
-
if (tagId === 6) return "\n";
|
|
1219
|
-
if (tagId === 35 && ((depthMap[22] || 0) > 0 || (depthMap[25] || 0) > 0 && !isInsideTableCell(state))) {
|
|
1220
|
-
const lastEntry = state.buffer.at(-1);
|
|
1221
|
-
const lastChar = lastEntry?.charAt(lastEntry.length - 1) || "";
|
|
1222
|
-
if (lastChar && lastChar !== " " && lastChar !== "\n") return "\n\n";
|
|
1223
|
-
}
|
|
1224
|
-
if (tagId === 32 || tagId === 31) return (depthMap[28] || 0) > 1 || node.index === 0 ? "" : " ";
|
|
1225
|
-
if (tagId === 27) {
|
|
1226
|
-
const alt = node.attributes?.alt;
|
|
1227
|
-
const clean = state.options?.clean;
|
|
1228
|
-
if ((clean === true || clean != null && clean !== false && clean.emptyImages === true) && !(alt !== void 0 && alt.trim().length > 0)) return void 0;
|
|
1229
|
-
const src = node.attributes?.src || "";
|
|
1230
|
-
const output = alt !== void 0 ? alt || void 0 : node.attributes?.title || resolveUrl(isDataUrl(src) ? "" : src, state.options?.origin, state.options?.clean) || void 0;
|
|
1231
|
-
if (output && hasNonWhitespace(output)) markRenderedChildContent(node);
|
|
1232
|
-
return output;
|
|
1233
|
-
}
|
|
1234
|
-
if (tagId === 81) return "\"";
|
|
1235
|
-
return;
|
|
1236
|
-
}
|
|
1237
|
-
if (tagId === 81) return "\"";
|
|
1238
|
-
}
|
|
1239
|
-
function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverrideHandlers) {
|
|
1240
|
-
const outputFormat = options.format === "html" || options.format === "text" ? options.format : "markdown";
|
|
1241
|
-
const plainText = outputFormat === "text";
|
|
1242
|
-
const htmlState = outputFormat === "html" ? createHtmlOutputState() : void 0;
|
|
1462
|
+
function createMarkdownProcessor(options = {}, createStream) {
|
|
1243
1463
|
const state = {
|
|
1244
1464
|
options,
|
|
1465
|
+
outputFormat: "markdown",
|
|
1245
1466
|
buffer: [],
|
|
1467
|
+
outputPositions: void 0,
|
|
1246
1468
|
depthMap: /* @__PURE__ */ new Uint16Array(113),
|
|
1469
|
+
depth: 0,
|
|
1247
1470
|
listIndent: "",
|
|
1248
1471
|
listIndentWidths: [],
|
|
1249
1472
|
blockquotes: [],
|
|
1250
1473
|
bufferedBlockquoteDepth: 0,
|
|
1251
|
-
|
|
1252
|
-
|
|
1474
|
+
emptyItemFragment: void 0,
|
|
1475
|
+
tableRenderedTable: false,
|
|
1476
|
+
tableCurrentRowCells: 0,
|
|
1477
|
+
tableColumnAlignments: [],
|
|
1478
|
+
tableHeaderCells: 0,
|
|
1479
|
+
preFencePending: false,
|
|
1480
|
+
preFencePendingDepth: 0,
|
|
1481
|
+
preFenceOwnerDepth: 0
|
|
1253
1482
|
};
|
|
1254
1483
|
const bufferScan = [
|
|
1255
1484
|
false,
|
|
1256
1485
|
0,
|
|
1257
1486
|
0,
|
|
1258
1487
|
0,
|
|
1488
|
+
0,
|
|
1489
|
+
void 0,
|
|
1259
1490
|
0
|
|
1260
1491
|
];
|
|
1261
1492
|
let inRawHtmlRegion = false;
|
|
@@ -1271,18 +1502,29 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1271
1502
|
let openLinkCaptionBreakRun = 0;
|
|
1272
1503
|
let openLinkCaptionFlags;
|
|
1273
1504
|
const clean = options.clean;
|
|
1274
|
-
const
|
|
1505
|
+
const cleanRules = typeof clean === "object" && clean !== null ? clean : void 0;
|
|
1506
|
+
const cleanEmptyLinkText = clean === true || cleanRules?.emptyLinkText === true;
|
|
1507
|
+
const cleanPass = typeof cleanRules?.apply === "function" ? cleanRules.apply(state) : void 0;
|
|
1275
1508
|
let rawHtmlLink;
|
|
1276
|
-
let lastYieldedLength = 0;
|
|
1277
1509
|
let hasYieldedContent = false;
|
|
1278
|
-
let preserveLeadingWhitespace = false;
|
|
1279
1510
|
function captionNeedsPreparation() {
|
|
1280
1511
|
return captionBoundary !== 0 || captionFrameCount !== 0 && (captionFrames[(captionFrameCount - 1) * CAPTION_FRAME_SIZE + 2] & CAPTION_OPEN) === 0;
|
|
1281
1512
|
}
|
|
1513
|
+
function openLink(fragment) {
|
|
1514
|
+
if (!cleanEmptyLinkText) {
|
|
1515
|
+
openLinkFragment = -fragment - 2;
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
openLinkFragment = fragment;
|
|
1519
|
+
openLinkCaptionBreakRun = captionBreakRun;
|
|
1520
|
+
const snapshot = openLinkCaptionFlags?.length === captionFrameCount ? openLinkCaptionFlags : new Uint8Array(captionFrameCount);
|
|
1521
|
+
for (let index = 0; index < captionFrameCount; index++) snapshot[index] = captionFrames[index * CAPTION_FRAME_SIZE + 2] & CAPTION_INTERNAL_BREAK;
|
|
1522
|
+
openLinkCaptionFlags = snapshot;
|
|
1523
|
+
}
|
|
1282
1524
|
function pushCaptionFrame(element, handler) {
|
|
1283
1525
|
let enterSpacing = 0;
|
|
1284
1526
|
let exitSpacing = 0;
|
|
1285
|
-
if (!state.depthMap[34] && figcaptionOwnsBlockSpacing(element,
|
|
1527
|
+
if (!state.depthMap[34] && figcaptionOwnsBlockSpacing(element, false)) {
|
|
1286
1528
|
const spacing = handler?.spacing;
|
|
1287
1529
|
if (spacing) {
|
|
1288
1530
|
enterSpacing = spacing[0];
|
|
@@ -1314,6 +1556,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1314
1556
|
const last = state.buffer[lastIndex];
|
|
1315
1557
|
if (prefix.charCodeAt(0) === 10 && last?.endsWith(" ")) {
|
|
1316
1558
|
const trimmed = last.slice(0, -1);
|
|
1559
|
+
state.outputPositions?.replace(lastIndex, lastIndex + 1, [trimmed]);
|
|
1317
1560
|
state.buffer[lastIndex] = trimmed;
|
|
1318
1561
|
if (state.lastContentCache === last) state.lastContentCache = trimmed;
|
|
1319
1562
|
state.lastTextNode = void 0;
|
|
@@ -1340,7 +1583,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1340
1583
|
const beforeFragment = anchor === CAPTION_NO_ANCHOR ? state.buffer.length : anchor;
|
|
1341
1584
|
let opening = flags & CAPTION_INTERNAL_BREAK ? "" : captionSpacingPrefix(frames[offset], true, beforeFragment);
|
|
1342
1585
|
flags |= CAPTION_OPEN;
|
|
1343
|
-
if (!
|
|
1586
|
+
if (!explicitTop || index !== captionFrameCount - 1) opening += "*";
|
|
1344
1587
|
if (opening) {
|
|
1345
1588
|
if (beforeFragment === state.buffer.length) {
|
|
1346
1589
|
state.buffer.push(opening);
|
|
@@ -1348,6 +1591,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1348
1591
|
} else {
|
|
1349
1592
|
const anchored = state.buffer[beforeFragment];
|
|
1350
1593
|
const replacement = opening + anchored;
|
|
1594
|
+
state.outputPositions?.replace(beforeFragment, beforeFragment + 1, [replacement], (offset) => offset + opening.length);
|
|
1351
1595
|
state.buffer[beforeFragment] = replacement;
|
|
1352
1596
|
const codeSpan = gfmLifecycle.openCodeSpans.at(-1);
|
|
1353
1597
|
if (codeSpan?.fragment === beforeFragment) codeSpan.prefix = opening + codeSpan.prefix;
|
|
@@ -1359,6 +1603,23 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1359
1603
|
}
|
|
1360
1604
|
return changed;
|
|
1361
1605
|
}
|
|
1606
|
+
function trimTrailingSpaces(buff) {
|
|
1607
|
+
let floor = state.codeFence ? state.codeFence.fragment + 1 : 0;
|
|
1608
|
+
const span = gfmLifecycle.openCodeSpans.at(-1);
|
|
1609
|
+
if (span && span.fragment >= floor) floor = span.fragment + 1;
|
|
1610
|
+
const quote = state.blockquotes.at(-1);
|
|
1611
|
+
if (quote && quote.fragment > floor) floor = quote.fragment;
|
|
1612
|
+
for (let index = buff.length - 1; index >= floor; index--) {
|
|
1613
|
+
const fragment = buff[index];
|
|
1614
|
+
let end = fragment.length;
|
|
1615
|
+
while (end > 0 && fragment.charCodeAt(end - 1) === 32) end--;
|
|
1616
|
+
if (end !== fragment.length) {
|
|
1617
|
+
state.outputPositions?.replace(index, index + 1, [fragment.slice(0, end)]);
|
|
1618
|
+
buff[index] = fragment.slice(0, end);
|
|
1619
|
+
}
|
|
1620
|
+
if (end > 0) break;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1362
1623
|
function consumeCaptionTransition(isInlineElement, tagId) {
|
|
1363
1624
|
captionBoundary = isInlineElement && tagId !== 27 && tagId !== 6 ? 2 : 0;
|
|
1364
1625
|
}
|
|
@@ -1387,13 +1648,15 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1387
1648
|
while (end !== 0 && value.charCodeAt(end - 1) === 32) end--;
|
|
1388
1649
|
if (end === value.length) break;
|
|
1389
1650
|
if (end !== 0) {
|
|
1651
|
+
state.outputPositions?.replace(index, state.buffer.length, [value.slice(0, end)]);
|
|
1390
1652
|
state.buffer[index] = value.slice(0, end);
|
|
1391
1653
|
state.buffer.length = index + 1;
|
|
1392
1654
|
break;
|
|
1393
1655
|
}
|
|
1656
|
+
state.outputPositions?.replace(index, state.buffer.length, []);
|
|
1394
1657
|
state.buffer.length = index;
|
|
1395
1658
|
}
|
|
1396
|
-
const output =
|
|
1659
|
+
const output = ` \n${state.listIndent}`.repeat(captionBreakRun);
|
|
1397
1660
|
captionBreakRun = 0;
|
|
1398
1661
|
state.buffer.push(output);
|
|
1399
1662
|
state.lastContentCache = output;
|
|
@@ -1412,12 +1675,14 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1412
1675
|
captionBoundary = exitSpacing === 0 ? 0 : 1;
|
|
1413
1676
|
captionBoundarySpacing = exitSpacing;
|
|
1414
1677
|
} else if (anchor !== CAPTION_NO_ANCHOR) {
|
|
1678
|
+
state.outputPositions?.replace(anchor, state.buffer.length, []);
|
|
1415
1679
|
state.buffer.length = anchor;
|
|
1416
1680
|
state.lastContentCache = state.buffer.at(-1);
|
|
1417
1681
|
state.lastTextNode = void 0;
|
|
1418
1682
|
} else if (captionBreakRun !== 0 && captionFrameCount === 0) captionBoundary = 2;
|
|
1419
1683
|
}
|
|
1420
1684
|
function processTextNode(textNode, lastNode, lastChar) {
|
|
1685
|
+
if (textNode.trimsAtLineStart) trimTextAtLineStart(textNode, state.buffer);
|
|
1421
1686
|
if (textNode.value) {
|
|
1422
1687
|
if (textNode.excludedFromMarkdown) return;
|
|
1423
1688
|
const ownsCaptionSpace = captionNeedsPreparation();
|
|
@@ -1434,9 +1699,8 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1434
1699
|
if (lastChar && !" \n \r".includes(lastChar) && !" \n \r".includes(textNode.value[0] || "")) textNode.value = ` ${textNode.value}`;
|
|
1435
1700
|
state.pendingInlineWhitespace = false;
|
|
1436
1701
|
}
|
|
1437
|
-
if (plainText && state.depthMap[34] && state.buffer.length === 0) preserveLeadingWhitespace = true;
|
|
1438
1702
|
if (textNode.value === " " && (lastChar === " " || lastChar === "\n" || lastChar === " " || lastChar === "\r")) return;
|
|
1439
|
-
if (!ownsCaptionSpace &&
|
|
1703
|
+
if (!ownsCaptionSpace && shouldAddSpacingBeforeText(lastChar, lastNode, textNode)) textNode.value = ` ${textNode.value}`;
|
|
1440
1704
|
if ((state.depthMap[34] || 0) > 0 && (state.depthMap[25] || 0) > 0) {
|
|
1441
1705
|
const indent = state.listIndent;
|
|
1442
1706
|
let value = textNode.value.replace(/\n(?!\n|$)/g, `\n${indent}`);
|
|
@@ -1447,12 +1711,12 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1447
1711
|
const insideRawHtmlBlock = isInsideRawHtmlBlock(state.depthMap);
|
|
1448
1712
|
let rawHtmlMarkdown = false;
|
|
1449
1713
|
if (insideRawHtmlBlock) rawHtmlMarkdown = trackRawHtmlMarkdownContext(state.buffer, bufferScan);
|
|
1450
|
-
if (!
|
|
1714
|
+
if (!state.depthMap[34] && insideRawHtmlBlock) {
|
|
1451
1715
|
let parent = rawHtmlLink ? textNode.parent : void 0;
|
|
1452
1716
|
while (parent && parent !== rawHtmlLink) parent = parent.parent;
|
|
1453
1717
|
textNode.value = escapeRawHtmlText(textNode.value, state.depthMap, rawHtmlLink !== void 0 && parent === rawHtmlLink);
|
|
1454
1718
|
}
|
|
1455
|
-
if (!
|
|
1719
|
+
if (!state.depthMap[34] && !state.depthMap[23] && (!insideRawHtmlBlock || rawHtmlMarkdown) && mayNeedGfmTextEscape(textNode.value, state.buffer, state.depthMap) && (!insideRawHtmlBlock || !lineOpensRawHtmlBlock(state.buffer, bufferScan))) textNode.value = escapeGfmText(textNode.value, state.buffer, state.depthMap);
|
|
1456
1720
|
if (textNode.generatedMarkdown && textNode.value) textNode.value = `${textNode.generatedMarkdown.prefix}${textNode.value}${textNode.generatedMarkdown.suffix}`;
|
|
1457
1721
|
const wrapWidth = state.options?.wrapWidth;
|
|
1458
1722
|
if (wrapWidth && canWrapHere(state.depthMap)) {
|
|
@@ -1478,9 +1742,16 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1478
1742
|
const { type: eventType, node } = event;
|
|
1479
1743
|
state.depth = node.depth;
|
|
1480
1744
|
if (node.type === 1 ? node.excludedFromMarkdown : node.parent?.excludedFromMarkdown) return;
|
|
1481
|
-
if (
|
|
1482
|
-
|
|
1483
|
-
|
|
1745
|
+
if (state.tableRowOpenerPending && state.depthMap[28] <= 1) {
|
|
1746
|
+
const tagId = node.type === 1 ? node.tagId : void 0;
|
|
1747
|
+
const cellEvent = tagId === 32 || tagId === 31;
|
|
1748
|
+
if (!(cellEvent && eventType === 0) && (state.depthMap[32] || state.depthMap[31] || cellEvent)) {
|
|
1749
|
+
state.tableRowOpenerPending = false;
|
|
1750
|
+
const opener = rowMarker(state);
|
|
1751
|
+
state.buffer.push(opener);
|
|
1752
|
+
state.lastContentCache = opener;
|
|
1753
|
+
state.lastTextNode = void 0;
|
|
1754
|
+
}
|
|
1484
1755
|
}
|
|
1485
1756
|
if (state.listRulePending !== void 0) {
|
|
1486
1757
|
const isVisibleText = node.type === 2 && eventType === 0 && hasNonWhitespace(node.value);
|
|
@@ -1496,7 +1767,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1496
1767
|
const lastNode = state.lastNode;
|
|
1497
1768
|
state.lastNode = event.node;
|
|
1498
1769
|
const buff = state.buffer;
|
|
1499
|
-
if (
|
|
1770
|
+
if (state.preFencePending) {
|
|
1500
1771
|
const preparePendingPreFence = () => {
|
|
1501
1772
|
if (captionNeedsPreparation()) {
|
|
1502
1773
|
flushCaptionBreakRun();
|
|
@@ -1508,7 +1779,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1508
1779
|
const pendingElement = node;
|
|
1509
1780
|
const pendingHandler = pendingElement.tagHandler;
|
|
1510
1781
|
const literalOverride = eventType === 0 ? pendingHandler?.literalEnter : pendingHandler?.literalExit;
|
|
1511
|
-
if (literalOverride &&
|
|
1782
|
+
if (literalOverride && codeOwnsPendingPreFence(state, pendingElement)) state.preFenceLang = getLanguageFromClass(pendingElement.attributes?.class);
|
|
1512
1783
|
if (pendingElement.pluginOutput?.length || literalOverride) {
|
|
1513
1784
|
preparePendingPreFence();
|
|
1514
1785
|
flushPreFence(state);
|
|
@@ -1517,7 +1788,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1517
1788
|
}
|
|
1518
1789
|
let lastBuffEntry = buff.at(-1);
|
|
1519
1790
|
let lastChar = lastBuffEntry?.charAt(lastBuffEntry.length - 1) || "";
|
|
1520
|
-
if (!lastChar &&
|
|
1791
|
+
if (!lastChar && buff.length > 1) {
|
|
1521
1792
|
const code = lastOutputChar(buff);
|
|
1522
1793
|
if (code !== -1) lastChar = String.fromCharCode(code);
|
|
1523
1794
|
}
|
|
@@ -1530,6 +1801,15 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1530
1801
|
const handler = node.tagHandler;
|
|
1531
1802
|
const tagId = element.tagId;
|
|
1532
1803
|
const insideRawHtmlRegion = isInsideRawHtmlBlock(state.depthMap);
|
|
1804
|
+
if (eventType === 0 && state.depthMap[25] && !insideRawHtmlRegion && (tagId === 35 || tagId === 36 || tagId === 34 || tagId === 28) && !handler?.literalEnter && endsAtHardBreak(buff)) {
|
|
1805
|
+
trimTrailingSpaces(buff);
|
|
1806
|
+
const separator = tagId === 35 || tagId === 36 ? `\n${state.listIndent}` : "\n";
|
|
1807
|
+
buff.push(separator);
|
|
1808
|
+
state.lastContentCache = separator;
|
|
1809
|
+
state.lastTextNode = void 0;
|
|
1810
|
+
lastBuffEntry = separator;
|
|
1811
|
+
lastChar = separator.charAt(separator.length - 1);
|
|
1812
|
+
}
|
|
1533
1813
|
if (insideRawHtmlRegion && !inRawHtmlRegion) {
|
|
1534
1814
|
bufferScan[0] = false;
|
|
1535
1815
|
bufferScan[1] = state.buffer.length;
|
|
@@ -1537,7 +1817,7 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1537
1817
|
}
|
|
1538
1818
|
if (eventType === 0 && handler === breakHandler && !element.pluginOutput?.length) {
|
|
1539
1819
|
const inPre = state.depthMap[34] !== 0;
|
|
1540
|
-
let breakOutput =
|
|
1820
|
+
let breakOutput = renderBreak(element, state);
|
|
1541
1821
|
if (captionBoundary !== 0 || captionFrameCount !== 0) {
|
|
1542
1822
|
const pendingCaption = captionFrameCount !== 0 && (captionFrames[(captionFrameCount - 1) * CAPTION_FRAME_SIZE + 2] & CAPTION_OPEN) === 0;
|
|
1543
1823
|
if (!inPre && breakOutput && !hasNonWhitespace(breakOutput) && buff.length === 0 && !hasYieldedContent && state.blockquotes.length === 0 && pendingCaption) breakOutput = void 0;
|
|
@@ -1550,14 +1830,6 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1550
1830
|
lastChar = lastBuffEntry?.charAt(lastBuffEntry.length - 1) || "";
|
|
1551
1831
|
}
|
|
1552
1832
|
}
|
|
1553
|
-
if (plainText && !inPre) {
|
|
1554
|
-
let trailingNewLines = captionBreakRun;
|
|
1555
|
-
if (lastChar === "\n") {
|
|
1556
|
-
trailingNewLines++;
|
|
1557
|
-
if ((lastBuffEntry.length > 1 ? lastBuffEntry.charAt(lastBuffEntry.length - 2) : buff.length > 1 ? buff[buff.length - 2]?.at(-1) : void 0) === "\n") trailingNewLines++;
|
|
1558
|
-
}
|
|
1559
|
-
if (trailingNewLines >= 2) breakOutput = void 0;
|
|
1560
|
-
}
|
|
1561
1833
|
if (state.pendingInlineWhitespace) state.pendingInlineWhitespace = false;
|
|
1562
1834
|
const lastFragment = state.lastContentCache;
|
|
1563
1835
|
const lastTextNode = state.lastTextNode;
|
|
@@ -1574,7 +1846,10 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1574
1846
|
if (!parentInPre || element.parent?.tagId === 34) {
|
|
1575
1847
|
if (breakOutput?.endsWith("\n") && !parentInPre) {
|
|
1576
1848
|
const trimmed = trimAsciiWhitespaceEnd(lastFragment);
|
|
1577
|
-
if (trimmed.length !== lastFragment.length && buff.at(-1) === lastFragment)
|
|
1849
|
+
if (trimmed.length !== lastFragment.length && buff.at(-1) === lastFragment) {
|
|
1850
|
+
state.outputPositions?.replace(buff.length - 1, buff.length, [trimmed]);
|
|
1851
|
+
buff[buff.length - 1] = trimmed;
|
|
1852
|
+
}
|
|
1578
1853
|
}
|
|
1579
1854
|
state.lastTextNode = void 0;
|
|
1580
1855
|
}
|
|
@@ -1594,19 +1869,23 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1594
1869
|
return;
|
|
1595
1870
|
}
|
|
1596
1871
|
let output;
|
|
1597
|
-
|
|
1872
|
+
const hasPluginOutput = !!element.pluginOutput?.length;
|
|
1873
|
+
if (hasPluginOutput) {
|
|
1598
1874
|
output = element.pluginOutput;
|
|
1599
1875
|
element.pluginOutput = void 0;
|
|
1600
1876
|
}
|
|
1601
1877
|
let captionBufferChanged = false;
|
|
1602
1878
|
const eventFn = eventType === 0 ? "enter" : "exit";
|
|
1603
|
-
const isInlineElement = handler
|
|
1879
|
+
const isInlineElement = handler ? handler.isInline === true : tagId === -1;
|
|
1604
1880
|
let gfmAction;
|
|
1605
1881
|
let handlerOutput;
|
|
1606
|
-
const suppressedInPre =
|
|
1882
|
+
const suppressedInPre = (state.depthMap[34] || 0) > 0 && suppressesFormattingInPre(tagId) && !(eventType === 0 ? handler?.literalEnter : handler?.literalExit);
|
|
1883
|
+
const emptyTableRow = eventType === 1 && tagId === 30 && state.tableRowOpenerPending && !output && !handler?.literalExit;
|
|
1884
|
+
if (eventType === 1 && (handler?.literalExit || output) && gfmLifecycle.openCodeSpans.at(-1)?.owner === element) gfmLifecycle.openCodeSpans.pop();
|
|
1885
|
+
if (cleanPass && eventType === 1) cleanPass.exit(element);
|
|
1607
1886
|
if (!output && !suppressedInPre && handler?.[eventFn]) {
|
|
1608
1887
|
if (openLinkFragment >= 0 && eventType === 1 && tagId === 26) {
|
|
1609
|
-
if (dropEmptyLinkText(buff, openLinkFragment)) {
|
|
1888
|
+
if (dropEmptyLinkText(buff, openLinkFragment, state.outputPositions)) {
|
|
1610
1889
|
if (captionFrameCount !== 0) {
|
|
1611
1890
|
captionBreakRun = openLinkCaptionBreakRun;
|
|
1612
1891
|
restoreCaptionBreakFlags(captionFrames, openLinkCaptionFlags, captionFrameCount);
|
|
@@ -1618,7 +1897,11 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1618
1897
|
return;
|
|
1619
1898
|
}
|
|
1620
1899
|
}
|
|
1621
|
-
|
|
1900
|
+
if (cleanPass && eventType === 1 && tagId === 26 && cleanPass.unwrap(element)) {
|
|
1901
|
+
openLinkFragment = -1;
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
const res = handler[eventFn]({
|
|
1622
1905
|
node: element,
|
|
1623
1906
|
state
|
|
1624
1907
|
});
|
|
@@ -1628,12 +1911,24 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1628
1911
|
handlerOutput = res;
|
|
1629
1912
|
}
|
|
1630
1913
|
} else if (res) {
|
|
1631
|
-
|
|
1632
|
-
|
|
1914
|
+
const span = gfmLifecycle.openCodeSpans.at(-1);
|
|
1915
|
+
if (res._tag === "CodeSpanEnter" && span || res._tag === "CodeSpanExit" && span && span.owner !== element) handlerOutput = void 0;
|
|
1916
|
+
else {
|
|
1917
|
+
gfmAction = res;
|
|
1918
|
+
handlerOutput = consumeGfmAction(res, state, gfmLifecycle);
|
|
1919
|
+
}
|
|
1633
1920
|
if (handlerOutput) output = [handlerOutput];
|
|
1634
1921
|
if (res._tag === "BlockquoteExit") captionBufferChanged = true;
|
|
1635
1922
|
}
|
|
1636
1923
|
}
|
|
1924
|
+
if (eventType === 0 && (tagId === 32 || tagId === 31) && state.tableRowOpenerPending && state.depthMap[28] <= 1) {
|
|
1925
|
+
state.tableRowOpenerPending = false;
|
|
1926
|
+
const opener = rowMarker(state);
|
|
1927
|
+
if (output) output.unshift(opener);
|
|
1928
|
+
else output = [opener];
|
|
1929
|
+
}
|
|
1930
|
+
if (emptyTableRow) return;
|
|
1931
|
+
if (eventType === 0 && output && handler?.collapsesInnerWhiteSpace && (hasPluginOutput || handler !== tagHandlers[tagId] || !INLINE_MARKER_TYPE[tagId] && tagId !== 26)) element.hasEnterOutput = output.some((fragment) => fragment.length > 0);
|
|
1637
1932
|
if (captionBreakRun && !(tagId === 106 && eventType === 1) && output) {
|
|
1638
1933
|
flushCaptionBreakRun();
|
|
1639
1934
|
if (gfmAction?._tag !== "BlockquoteEnter") anchorPendingCaptions(state.buffer.length);
|
|
@@ -1694,6 +1989,14 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1694
1989
|
}
|
|
1695
1990
|
if (meaningfulOutput) commitCaptionFrames();
|
|
1696
1991
|
}
|
|
1992
|
+
if (eventType === 1 && tagId === 25 && !state.depthMap[34] && !isInsideTableCell(state) && !handler?.literalExit && endsAtHardBreak(buff)) {
|
|
1993
|
+
trimTrailingSpaces(buff);
|
|
1994
|
+
state.lastContentCache = buff.at(-1);
|
|
1995
|
+
state.lastTextNode = void 0;
|
|
1996
|
+
lastBuffEntry = buff.at(-1);
|
|
1997
|
+
const lastCode = lastOutputChar(buff);
|
|
1998
|
+
lastChar = lastCode === -1 ? "" : String.fromCharCode(lastCode);
|
|
1999
|
+
}
|
|
1697
2000
|
const lastFragment = state.lastContentCache;
|
|
1698
2001
|
if (captionBufferChanged) {
|
|
1699
2002
|
lastBuffEntry = buff.at(-1);
|
|
@@ -1705,12 +2008,14 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1705
2008
|
else rawHtmlLink = void 0;
|
|
1706
2009
|
}
|
|
1707
2010
|
let lastNewLines = 0;
|
|
1708
|
-
if (lastChar === "\n")
|
|
1709
|
-
|
|
2011
|
+
if (lastChar === "\n") {
|
|
2012
|
+
lastNewLines++;
|
|
2013
|
+
if (secondLastChar === "\n") lastNewLines++;
|
|
2014
|
+
}
|
|
1710
2015
|
if (eventType === 1 && openMarkerCount) {
|
|
1711
2016
|
const markerType = handlerOutput === void 0 ? 0 : INLINE_MARKER_TYPE[tagId];
|
|
1712
2017
|
if (markerType && (tagId !== 23 || !state.depthMap[34] && !isInsideRawHtmlBlock(state.depthMap)) && !handler?.literalExit) {
|
|
1713
|
-
const idx = dropEmptyMarker(buff, openMarkers[--openMarkerCount], markerType);
|
|
2018
|
+
const idx = dropEmptyMarker(buff, openMarkers[--openMarkerCount], markerType, state.outputPositions);
|
|
1714
2019
|
if (idx >= 0) {
|
|
1715
2020
|
resetRetractedCaptionFrames(captionFrames, captionFrameCount, idx);
|
|
1716
2021
|
state.lastContentCache = idx > 0 ? buff[idx - 1] : void 0;
|
|
@@ -1720,18 +2025,18 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1720
2025
|
}
|
|
1721
2026
|
}
|
|
1722
2027
|
if (tagId === 6 && !state.depthMap[34] && output?.length === 1 && output[0] === "\n" && lastChar === "\n" && secondLastChar === "\n") output = void 0;
|
|
1723
|
-
const newLineConfig = suppressedInPre ? NO_SPACING : calculateNewLineConfig(node, state
|
|
2028
|
+
const newLineConfig = suppressedInPre ? NO_SPACING : calculateNewLineConfig(node, state, eventType);
|
|
1724
2029
|
const quoteAtStart = eventType === 0 && state.blockquotes.at(-1)?.fragment === state.buffer.length;
|
|
1725
2030
|
const configuredNewLines = quoteAtStart || captionEvent || captionTransition ? 0 : eventType === 1 && tagId === 13 && state.blockquotes.length > 0 ? Math.min(1, newLineConfig[eventType] || 0) : newLineConfig[eventType] || 0;
|
|
1726
|
-
let
|
|
1727
|
-
if (eventType === 1 && output) for (let i = output.length - 1; i >= 0; i--) {
|
|
2031
|
+
let measureFromOutputTail = false;
|
|
2032
|
+
if (eventType === 1 && gfmAction?._tag === "PreExit" && output) for (let i = output.length - 1; i >= 0; i--) {
|
|
1728
2033
|
const frag = output[i];
|
|
1729
2034
|
if (frag) {
|
|
1730
|
-
|
|
2035
|
+
measureFromOutputTail = frag.endsWith("```") || frag.endsWith("~~~");
|
|
1731
2036
|
break;
|
|
1732
2037
|
}
|
|
1733
2038
|
}
|
|
1734
|
-
let newLines = Math.max(0, configuredNewLines -
|
|
2039
|
+
let newLines = Math.max(0, configuredNewLines - (measureFromOutputTail ? 0 : lastNewLines));
|
|
1735
2040
|
if (newLines > 0 && buff.length === 0 && !hasYieldedContent) newLines = 0;
|
|
1736
2041
|
if (state.pendingInlineWhitespace) {
|
|
1737
2042
|
const firstOutput = output?.[0]?.[0] || "";
|
|
@@ -1755,15 +2060,16 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1755
2060
|
state.lastContentCache = fragment;
|
|
1756
2061
|
}
|
|
1757
2062
|
}
|
|
1758
|
-
if (gfmAction) commitGfmAction(gfmAction, state, gfmLifecycle, state.buffer.length);
|
|
2063
|
+
if (gfmAction) commitGfmAction(gfmAction, state, gfmLifecycle, state.buffer.length, element);
|
|
1759
2064
|
updateListIndent(state, element, eventType);
|
|
1760
2065
|
return;
|
|
1761
2066
|
}
|
|
1762
|
-
const newlinesStr = "\n".repeat(newLines);
|
|
1763
2067
|
if (lastChar === " " && buff?.length) {
|
|
1764
|
-
|
|
2068
|
+
trimTrailingSpaces(buff);
|
|
1765
2069
|
state.lastTextNode = void 0;
|
|
2070
|
+
if (!measureFromOutputTail) newLines = Math.max(0, configuredNewLines - newlineRunBefore(buff, buff.length));
|
|
1766
2071
|
}
|
|
2072
|
+
const newlinesStr = "\n".repeat(newLines);
|
|
1767
2073
|
if (eventType === 0) {
|
|
1768
2074
|
if (output) output.unshift(newlinesStr);
|
|
1769
2075
|
else output = [newlinesStr];
|
|
@@ -1787,7 +2093,10 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1787
2093
|
const originalLength = lastFragment.length;
|
|
1788
2094
|
const trimmed = trimAsciiWhitespaceEnd(lastFragment);
|
|
1789
2095
|
if (originalLength - trimmed.length > 0) {
|
|
1790
|
-
if (buff?.length && buff.at(-1) === lastFragment)
|
|
2096
|
+
if (buff?.length && buff.at(-1) === lastFragment) {
|
|
2097
|
+
state.outputPositions?.replace(buff.length - 1, buff.length, [trimmed]);
|
|
2098
|
+
buff[buff.length - 1] = trimmed;
|
|
2099
|
+
}
|
|
1791
2100
|
if (eventType === 1 && isInlineElement) state.pendingInlineWhitespace = true;
|
|
1792
2101
|
}
|
|
1793
2102
|
}
|
|
@@ -1806,21 +2115,15 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1806
2115
|
state.lastContentCache = fragment;
|
|
1807
2116
|
}
|
|
1808
2117
|
}
|
|
1809
|
-
if (gfmAction) commitGfmAction(gfmAction, state, gfmLifecycle, outputStart);
|
|
1810
|
-
if (tagId === 25 && !
|
|
2118
|
+
if (gfmAction) commitGfmAction(gfmAction, state, gfmLifecycle, outputStart, element);
|
|
2119
|
+
if (tagId === 25 && !isInsideTableCell(state)) {
|
|
1811
2120
|
if (eventType === 0) recordItemMarker(state, element.index);
|
|
1812
2121
|
else resolveItemMarker(state, true);
|
|
1813
2122
|
}
|
|
1814
|
-
if (eventType === 0 && tagId === 26 && outputStart < buff.length && buff.at(-1) === "[")
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
if (cleanCaptionLink) {
|
|
1819
|
-
openLinkCaptionBreakRun = captionBreakRun;
|
|
1820
|
-
const snapshot = openLinkCaptionFlags?.length === captionFrameCount ? openLinkCaptionFlags : new Uint8Array(captionFrameCount);
|
|
1821
|
-
for (let index = 0; index < captionFrameCount; index++) snapshot[index] = captionFrames[index * CAPTION_FRAME_SIZE + 2] & CAPTION_INTERNAL_BREAK;
|
|
1822
|
-
openLinkCaptionFlags = snapshot;
|
|
1823
|
-
}
|
|
2123
|
+
if (eventType === 0 && tagId === 26 && outputStart < buff.length && buff.at(-1) === "[") openLink(buff.length - 1);
|
|
2124
|
+
if (cleanPass) {
|
|
2125
|
+
if (eventType === 0) cleanPass.enter(element, outputStart);
|
|
2126
|
+
else if (handlerOutput) cleanPass.closed(element, outputStart, handlerOutput);
|
|
1824
2127
|
}
|
|
1825
2128
|
if (eventType === 0 && handlerOutput !== void 0 && isInlineElement && !handler?.literalEnter) {
|
|
1826
2129
|
const markerType = INLINE_MARKER_TYPE[tagId];
|
|
@@ -1838,74 +2141,16 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1838
2141
|
inRawHtmlRegion = false;
|
|
1839
2142
|
}
|
|
1840
2143
|
}
|
|
1841
|
-
function processHtml(html) {
|
|
1842
|
-
const parseState = {
|
|
1843
|
-
depthMap: state.depthMap,
|
|
1844
|
-
depth: 0,
|
|
1845
|
-
resolvedPlugins,
|
|
1846
|
-
tagOverrideHandlers,
|
|
1847
|
-
plainText: outputFormat !== "markdown"
|
|
1848
|
-
};
|
|
1849
|
-
const handleEvent = resolvedPlugins.length ? (event) => processPluginsForEvent(event, resolvedPlugins, state, processEvent) : processEvent;
|
|
1850
|
-
const leftover = parseHtmlStream(html, parseState, handleEvent);
|
|
1851
|
-
finalizeParse(leftover, parseState, handleEvent);
|
|
1852
|
-
}
|
|
1853
2144
|
function getMarkdown() {
|
|
1854
|
-
const
|
|
1855
|
-
if (htmlState) {
|
|
1856
|
-
state.buffer.length = 0;
|
|
1857
|
-
return content;
|
|
1858
|
-
}
|
|
1859
|
-
const result = plainText && preserveLeadingWhitespace ? content : content.trimStart();
|
|
2145
|
+
const result = trimAsciiWhitespaceEnd(trimOutputStart(state.buffer.join("")));
|
|
1860
2146
|
state.buffer.length = 0;
|
|
1861
|
-
|
|
1862
|
-
return result.trimEnd();
|
|
2147
|
+
return cleanPass ? cleanPass.finish(result).markdown : result;
|
|
1863
2148
|
}
|
|
1864
|
-
function
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
}
|
|
1870
|
-
let unresolvedCaptionFragment = -1;
|
|
1871
|
-
if (state.emptyItemFragment !== void 0 && captionFrames) for (let index = 0; index < captionFrameCount; index++) {
|
|
1872
|
-
const offset = index * CAPTION_FRAME_SIZE;
|
|
1873
|
-
const anchor = captionFrames[offset + 3];
|
|
1874
|
-
if (anchor !== CAPTION_NO_ANCHOR) {
|
|
1875
|
-
unresolvedCaptionFragment = anchor;
|
|
1876
|
-
break;
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
resolveItemMarker(state, false, unresolvedCaptionFragment);
|
|
1880
|
-
const content = state.buffer.join("");
|
|
1881
|
-
const currentContent = hasYieldedContent || plainText && preserveLeadingWhitespace ? content : content.trimStart();
|
|
1882
|
-
const inPre = state.depthMap[34] !== 0;
|
|
1883
|
-
let stableLength = currentContent.length;
|
|
1884
|
-
let retainMutableFragments = false;
|
|
1885
|
-
if (inPre) {
|
|
1886
|
-
const trailingCode = currentContent.charCodeAt(stableLength - 1);
|
|
1887
|
-
while (stableLength > 0 && currentContent.charCodeAt(stableLength - 1) === 32) stableLength--;
|
|
1888
|
-
retainMutableFragments = stableLength < currentContent.length;
|
|
1889
|
-
if (state.lastTextNode?.containsWhitespace && isAsciiWhitespace(trailingCode)) {
|
|
1890
|
-
stableLength = trimAsciiWhitespaceEnd(currentContent).length;
|
|
1891
|
-
retainMutableFragments = stableLength < currentContent.length;
|
|
1892
|
-
} else if (stableLength < currentContent.length) {
|
|
1893
|
-
if (!(stableLength === 0 || currentContent.charCodeAt(stableLength - 1) === 10)) {
|
|
1894
|
-
stableLength = currentContent.length;
|
|
1895
|
-
retainMutableFragments = false;
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
} else {
|
|
1899
|
-
while (stableLength > 0) {
|
|
1900
|
-
const code = currentContent.charCodeAt(stableLength - 1);
|
|
1901
|
-
if (code !== 32 && code !== 10) break;
|
|
1902
|
-
stableLength--;
|
|
1903
|
-
}
|
|
1904
|
-
retainMutableFragments = stableLength < currentContent.length;
|
|
1905
|
-
}
|
|
1906
|
-
const leadingTrimmed = content.length - currentContent.length;
|
|
1907
|
-
let heldFragment = Math.min(openMarkerCount ? openMarkers[0] >> 3 : Infinity, gfmLifecycle.openCodeSpans[0]?.fragment ?? Infinity, state.emptyItemFragment ?? Infinity, state.codeFence?.fragment ?? Infinity, state.blockquotes[0]?.fragment ?? Infinity, openLinkFragment === -1 ? Infinity : openLinkFragment < -1 ? -openLinkFragment - 2 : openLinkFragment);
|
|
1908
|
-
for (let index = 0; index < captionFrameCount; index++) {
|
|
2149
|
+
function getNonQuoteHeldOutputFragment(final = false) {
|
|
2150
|
+
let heldFragment = final ? Infinity : Math.min(openMarkerCount ? openMarkers[0] >> 3 : Infinity, gfmLifecycle.openCodeSpans[0]?.fragment ?? Infinity, state.emptyItemFragment ?? Infinity, state.codeFence?.fragment ?? Infinity, openLinkFragment === -1 ? Infinity : openLinkFragment < -1 ? -openLinkFragment - 2 : openLinkFragment);
|
|
2151
|
+
if (cleanPass && !final) heldFragment = Math.min(heldFragment, cleanPass.held());
|
|
2152
|
+
const captionHoldCount = final ? 0 : captionFrameCount;
|
|
2153
|
+
for (let index = 0; index < captionHoldCount; index++) {
|
|
1909
2154
|
const offset = index * CAPTION_FRAME_SIZE;
|
|
1910
2155
|
const anchor = captionFrames[offset + 3];
|
|
1911
2156
|
if ((captionFrames[offset + 2] & CAPTION_OPEN) === 0 && anchor !== CAPTION_NO_ANCHOR) {
|
|
@@ -1913,56 +2158,60 @@ function createMarkdownProcessor(options = {}, resolvedPlugins = [], tagOverride
|
|
|
1913
2158
|
break;
|
|
1914
2159
|
}
|
|
1915
2160
|
}
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
}
|
|
1926
|
-
if (headingPos < stableLength) stableLength = headingPos;
|
|
1927
|
-
}
|
|
1928
|
-
if (stableLength < lastYieldedLength) stableLength = lastYieldedLength;
|
|
1929
|
-
const newContent = currentContent.slice(lastYieldedLength, stableLength);
|
|
1930
|
-
lastYieldedLength = stableLength;
|
|
1931
|
-
if (newContent) hasYieldedContent = true;
|
|
1932
|
-
if (!fragmentHeld && !headingHeld && (!retainMutableFragments || !inPre)) {
|
|
1933
|
-
if (!resolvedPlugins.length && !options.wrapWidth) {
|
|
1934
|
-
if (retainMutableFragments && leadingTrimmed === 0) {
|
|
1935
|
-
const lastFragment = state.buffer.at(-1);
|
|
1936
|
-
const fragmentStart = currentContent.length - lastFragment.length;
|
|
1937
|
-
const tailStart = Math.max(0, Math.min(stableLength - 2, fragmentStart));
|
|
1938
|
-
const emittedTail = currentContent.slice(tailStart, fragmentStart);
|
|
1939
|
-
state.buffer.length = 0;
|
|
1940
|
-
resetBufferScanCursors(bufferScan);
|
|
1941
|
-
if (emittedTail) state.buffer.push(emittedTail);
|
|
1942
|
-
state.buffer.push(lastFragment);
|
|
1943
|
-
lastYieldedLength = stableLength - tailStart;
|
|
1944
|
-
} else if (!retainMutableFragments) {
|
|
1945
|
-
const tailStart = Math.max(0, stableLength - 2);
|
|
1946
|
-
const emittedTail = currentContent.slice(tailStart, stableLength);
|
|
1947
|
-
state.buffer.length = 0;
|
|
1948
|
-
resetBufferScanCursors(bufferScan);
|
|
1949
|
-
if (emittedTail) state.buffer.push(emittedTail);
|
|
1950
|
-
lastYieldedLength = emittedTail.length;
|
|
1951
|
-
}
|
|
1952
|
-
} else if (!retainMutableFragments && state.buffer.length > 1) {
|
|
1953
|
-
state.buffer.length = 0;
|
|
1954
|
-
resetBufferScanCursors(bufferScan);
|
|
1955
|
-
state.buffer.push(currentContent);
|
|
1956
|
-
}
|
|
2161
|
+
if (heldFragment > state.buffer.length) heldFragment = Infinity;
|
|
2162
|
+
return heldFragment;
|
|
2163
|
+
}
|
|
2164
|
+
function getHeldOutputFragment(final = false) {
|
|
2165
|
+
let heldFragment = getNonQuoteHeldOutputFragment(final);
|
|
2166
|
+
const quoteHoldCount = final ? 0 : state.blockquotes.length;
|
|
2167
|
+
for (let index = 0; index < quoteHoldCount; index++) {
|
|
2168
|
+
const fragment = state.blockquotes[index].fragment;
|
|
2169
|
+
if (fragment < heldFragment) heldFragment = fragment;
|
|
1957
2170
|
}
|
|
1958
|
-
return
|
|
2171
|
+
return heldFragment > state.buffer.length ? Infinity : heldFragment;
|
|
1959
2172
|
}
|
|
1960
|
-
|
|
2173
|
+
const processor = {
|
|
1961
2174
|
processEvent,
|
|
1962
|
-
processHtml,
|
|
1963
2175
|
getMarkdown,
|
|
1964
|
-
|
|
1965
|
-
|
|
2176
|
+
state,
|
|
2177
|
+
getHeldOutputFragment: cleanPass ? getHeldOutputFragment : void 0,
|
|
2178
|
+
finishOutput: cleanPass?.holdsOutput ? (markdown) => cleanPass.finish(markdown) : void 0
|
|
2179
|
+
};
|
|
2180
|
+
if (!createStream) return processor;
|
|
2181
|
+
return {
|
|
2182
|
+
...processor,
|
|
2183
|
+
...createStream({
|
|
2184
|
+
state,
|
|
2185
|
+
options,
|
|
2186
|
+
bufferScan,
|
|
2187
|
+
getMarkdown,
|
|
2188
|
+
holdsOutput: !!cleanPass?.holdsOutput,
|
|
2189
|
+
inRawHtmlRegion: () => inRawHtmlRegion,
|
|
2190
|
+
getNonQuoteHeldOutputFragment,
|
|
2191
|
+
getHeldOutputFragment,
|
|
2192
|
+
settleItemMarker() {
|
|
2193
|
+
let unresolvedCaptionFragment = -1;
|
|
2194
|
+
if (state.emptyItemFragment !== void 0 && captionFrames) for (let index = 0; index < captionFrameCount; index++) {
|
|
2195
|
+
const offset = index * CAPTION_FRAME_SIZE;
|
|
2196
|
+
const anchor = captionFrames[offset + 3];
|
|
2197
|
+
if (anchor !== CAPTION_NO_ANCHOR) {
|
|
2198
|
+
unresolvedCaptionFragment = anchor;
|
|
2199
|
+
break;
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
if (openLinkFragment >= 0 && (unresolvedCaptionFragment === -1 || openLinkFragment < unresolvedCaptionFragment)) unresolvedCaptionFragment = openLinkFragment;
|
|
2203
|
+
if (openMarkerCount) {
|
|
2204
|
+
const markerFragment = openMarkers[0] >> 3;
|
|
2205
|
+
if (unresolvedCaptionFragment === -1 || markerFragment < unresolvedCaptionFragment) unresolvedCaptionFragment = markerFragment;
|
|
2206
|
+
}
|
|
2207
|
+
const codeSpanFragment = gfmLifecycle.openCodeSpans[0]?.fragment;
|
|
2208
|
+
if (codeSpanFragment !== void 0 && (unresolvedCaptionFragment === -1 || codeSpanFragment < unresolvedCaptionFragment)) unresolvedCaptionFragment = codeSpanFragment;
|
|
2209
|
+
resolveItemMarker(state, false, unresolvedCaptionFragment);
|
|
2210
|
+
},
|
|
2211
|
+
markYielded() {
|
|
2212
|
+
hasYieldedContent = true;
|
|
2213
|
+
}
|
|
2214
|
+
})
|
|
1966
2215
|
};
|
|
1967
2216
|
}
|
|
1968
|
-
export {
|
|
2217
|
+
export { createMarkdownProcessor, isAsciiWhitespace, lineOpensRawHtmlBlock, stripBlockquoteListIndent, tagHandlers, trimAsciiWhitespaceEnd };
|