@ai-react-markdown/engine 2.4.1 → 2.4.3
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/dist/index.cjs +174 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -57
- package/dist/index.d.ts +58 -57
- package/dist/index.dev.cjs +174 -58
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +174 -58
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +174 -58
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.dev.js
CHANGED
|
@@ -202,6 +202,10 @@ var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|--
|
|
|
202
202
|
var TRUNCATED_TAG_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)([^<>]*)$/;
|
|
203
203
|
var REF_RE = /!?\[((?:[^[\]\\]|\\.)*)\]/g;
|
|
204
204
|
var BACKTICK_RUN_RE = /`+/g;
|
|
205
|
+
var MD_BLANK_RE = /^[ \t\r]*$/;
|
|
206
|
+
var isMdBlank = (text) => MD_BLANK_RE.test(text);
|
|
207
|
+
var mdTrim = (text) => text.replace(/^[ \t\r]+|[ \t\r]+$/g, "");
|
|
208
|
+
var mdTrimStart = (text) => text.replace(/^[ \t\r]+/, "");
|
|
205
209
|
function computeIndent(text) {
|
|
206
210
|
let indent = 0;
|
|
207
211
|
for (const ch of text) {
|
|
@@ -211,8 +215,25 @@ function computeIndent(text) {
|
|
|
211
215
|
}
|
|
212
216
|
return indent;
|
|
213
217
|
}
|
|
218
|
+
function firstUnescaped(text, ch) {
|
|
219
|
+
for (let i = 0; i < text.length; i++) {
|
|
220
|
+
if (text[i] === "\\") i += 1;
|
|
221
|
+
else if (text[i] === ch) return i;
|
|
222
|
+
}
|
|
223
|
+
return -1;
|
|
224
|
+
}
|
|
225
|
+
function lastUnclosedBracket(text) {
|
|
226
|
+
let open = -1;
|
|
227
|
+
for (let i = 0; i < text.length; i++) {
|
|
228
|
+
const c = text[i];
|
|
229
|
+
if (c === "\\") i += 1;
|
|
230
|
+
else if (c === "[") open = i;
|
|
231
|
+
else if (c === "]") open = -1;
|
|
232
|
+
}
|
|
233
|
+
return open;
|
|
234
|
+
}
|
|
214
235
|
function normalizeLabel(label) {
|
|
215
|
-
const collapsed = label.
|
|
236
|
+
const collapsed = label.replace(/[ \t\r\n]+/g, " ").replace(/^ | $/g, "");
|
|
216
237
|
return collapsed ? normalizeIdentifier(collapsed) : "";
|
|
217
238
|
}
|
|
218
239
|
function canBecomeDdLine(text, confirmed) {
|
|
@@ -289,6 +310,7 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
289
310
|
prevLineWasText: false,
|
|
290
311
|
prevLineWasValidDef: false,
|
|
291
312
|
paragraphHasUnpairedRun: false,
|
|
313
|
+
openBracket: null,
|
|
292
314
|
htmlFlowSinceBlank: false,
|
|
293
315
|
htmlSeamPending: false,
|
|
294
316
|
phasePoisonedAt: Infinity,
|
|
@@ -296,11 +318,11 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
|
|
|
296
318
|
};
|
|
297
319
|
}
|
|
298
320
|
function isPlausibleLinkDefRest(rest) {
|
|
299
|
-
const t = rest
|
|
321
|
+
const t = mdTrim(rest);
|
|
300
322
|
if (t === "") return false;
|
|
301
323
|
const destEnd = linkDestinationEnd(t);
|
|
302
324
|
if (destEnd === -1) return false;
|
|
303
|
-
const after = t.slice(destEnd)
|
|
325
|
+
const after = mdTrim(t.slice(destEnd));
|
|
304
326
|
if (after === "") return true;
|
|
305
327
|
const opener = after[0];
|
|
306
328
|
if (opener !== '"' && opener !== "'" && opener !== "(") return false;
|
|
@@ -310,7 +332,7 @@ function isPlausibleLinkDefRest(rest) {
|
|
|
310
332
|
i += 1;
|
|
311
333
|
continue;
|
|
312
334
|
}
|
|
313
|
-
if (after[i] === closer) return after.slice(i + 1)
|
|
335
|
+
if (after[i] === closer) return isMdBlank(after.slice(i + 1));
|
|
314
336
|
}
|
|
315
337
|
return false;
|
|
316
338
|
}
|
|
@@ -347,6 +369,36 @@ function linkDestinationEnd(t) {
|
|
|
347
369
|
if (balance !== 0 || i === 0) return -1;
|
|
348
370
|
return i;
|
|
349
371
|
}
|
|
372
|
+
function inlineResourceEnd(text, openIdx) {
|
|
373
|
+
let i = openIdx + 1;
|
|
374
|
+
const skipWs = () => {
|
|
375
|
+
while (i < text.length && (text[i] === " " || text[i] === " ")) i += 1;
|
|
376
|
+
};
|
|
377
|
+
skipWs();
|
|
378
|
+
if (text[i] === ")") return i + 1;
|
|
379
|
+
const destEnd = linkDestinationEnd(text.slice(i));
|
|
380
|
+
if (destEnd === -1) return -1;
|
|
381
|
+
i += destEnd;
|
|
382
|
+
const beforeWs = i;
|
|
383
|
+
skipWs();
|
|
384
|
+
if (text[i] === ")") return i + 1;
|
|
385
|
+
if (i === beforeWs) return -1;
|
|
386
|
+
const opener = text[i];
|
|
387
|
+
if (opener !== '"' && opener !== "'" && opener !== "(") return -1;
|
|
388
|
+
const closer = opener === "(" ? ")" : opener;
|
|
389
|
+
for (i += 1; i < text.length; i++) {
|
|
390
|
+
if (text[i] === "\\") {
|
|
391
|
+
i += 1;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (text[i] === closer) {
|
|
395
|
+
i += 1;
|
|
396
|
+
skipWs();
|
|
397
|
+
return text[i] === ")" ? i + 1 : -1;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return -1;
|
|
401
|
+
}
|
|
350
402
|
function classifyBlockStart(text, indent, defListEnabled) {
|
|
351
403
|
if (indent >= 4) return true;
|
|
352
404
|
if (LIST_MARKER_RE.test(text) || FOOTNOTE_DEF_RE.test(text)) return true;
|
|
@@ -364,12 +416,13 @@ function computeFreezeBoundary(text, options, resume) {
|
|
|
364
416
|
let end = text.indexOf("\n", start);
|
|
365
417
|
if (end === -1) end = text.length;
|
|
366
418
|
const confirmed = end < text.length;
|
|
367
|
-
const
|
|
419
|
+
const rawLine = text.slice(start, end);
|
|
420
|
+
const lineText = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
|
|
368
421
|
const ln = {
|
|
369
422
|
start,
|
|
370
423
|
end,
|
|
371
424
|
text: lineText,
|
|
372
|
-
blank: confirmed && lineText
|
|
425
|
+
blank: confirmed && isMdBlank(lineText),
|
|
373
426
|
indent: computeIndent(lineText)
|
|
374
427
|
};
|
|
375
428
|
if (!confirmed) {
|
|
@@ -458,7 +511,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
458
511
|
const isBlockStart = cp.prevLineBlank;
|
|
459
512
|
if (cp.htmlSeamPending && !ln.blank && !cp.htmlFlowSinceBlank && !(cp.commentOpen || cp.piOpen || cp.declOpen || cp.cdataOpen)) {
|
|
460
513
|
const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
|
|
461
|
-
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").
|
|
514
|
+
const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
|
|
462
515
|
if (!defShapedLine && !commentOnly) {
|
|
463
516
|
cp.htmlSeamPending = false;
|
|
464
517
|
}
|
|
@@ -479,13 +532,14 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
479
532
|
const rawOpenAtLineStart = cp.commentOpen || cp.piOpen || cp.declOpen || cp.cdataOpen;
|
|
480
533
|
if (cp.inFence) {
|
|
481
534
|
const close = FENCE_RE.exec(ln.text);
|
|
482
|
-
if (close && close[1][0] === cp.fenceChar && close[1].length >= cp.fenceLen && ln.text.
|
|
535
|
+
if (close && close[1][0] === cp.fenceChar && close[1].length >= cp.fenceLen && isMdBlank(ln.text.slice(close[0].length))) {
|
|
483
536
|
cp.inFence = false;
|
|
484
537
|
cp.fenceChar = "";
|
|
485
538
|
cp.fenceLen = 0;
|
|
486
539
|
}
|
|
487
540
|
cp.blankRun = 0;
|
|
488
541
|
cp.paragraphHasUnpairedRun = false;
|
|
542
|
+
cp.openBracket = null;
|
|
489
543
|
cp.prevLineBlank = false;
|
|
490
544
|
cp.prevLineWasText = false;
|
|
491
545
|
cp.prevLineWasValidDef = false;
|
|
@@ -507,6 +561,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
507
561
|
cp.openIndent = ln.indent;
|
|
508
562
|
cp.blankRun = 0;
|
|
509
563
|
cp.paragraphHasUnpairedRun = false;
|
|
564
|
+
cp.openBracket = null;
|
|
510
565
|
cp.prevLineBlank = false;
|
|
511
566
|
cp.prevLineWasText = false;
|
|
512
567
|
cp.prevLineWasValidDef = false;
|
|
@@ -515,12 +570,13 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
515
570
|
}
|
|
516
571
|
if (cp.inMath) {
|
|
517
572
|
const close = MATH_RUN_RE.exec(ln.text);
|
|
518
|
-
if (close && close[1].length >= cp.mathFenceLen && ln.text.
|
|
573
|
+
if (close && close[1].length >= cp.mathFenceLen && isMdBlank(ln.text.slice(close[0].length))) {
|
|
519
574
|
cp.inMath = false;
|
|
520
575
|
cp.mathFenceLen = 0;
|
|
521
576
|
}
|
|
522
577
|
cp.blankRun = 0;
|
|
523
578
|
cp.paragraphHasUnpairedRun = false;
|
|
579
|
+
cp.openBracket = null;
|
|
524
580
|
cp.prevLineBlank = false;
|
|
525
581
|
cp.prevLineWasText = false;
|
|
526
582
|
cp.prevLineWasValidDef = false;
|
|
@@ -542,6 +598,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
542
598
|
cp.openIndent = ln.indent;
|
|
543
599
|
cp.blankRun = 0;
|
|
544
600
|
cp.paragraphHasUnpairedRun = false;
|
|
601
|
+
cp.openBracket = null;
|
|
545
602
|
cp.prevLineBlank = false;
|
|
546
603
|
cp.prevLineWasText = false;
|
|
547
604
|
cp.prevLineWasValidDef = false;
|
|
@@ -565,6 +622,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
565
622
|
defListSettled: null
|
|
566
623
|
});
|
|
567
624
|
cp.paragraphHasUnpairedRun = false;
|
|
625
|
+
cp.openBracket = null;
|
|
568
626
|
cp.htmlFlowSinceBlank = false;
|
|
569
627
|
cp.prevLineBlank = true;
|
|
570
628
|
cp.prevLineWasText = false;
|
|
@@ -577,13 +635,13 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
577
635
|
} else if (LIST_MARKER_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defListEnabled && DEF_LIST_DD_RE.test(ln.text) || ln.indent >= 4) {
|
|
578
636
|
cp.hazardVerdict = true;
|
|
579
637
|
}
|
|
580
|
-
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(ln.text
|
|
638
|
+
const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
|
|
581
639
|
if (tagStart) {
|
|
582
640
|
cp.htmlFlowSinceBlank = true;
|
|
583
641
|
if (!TYPE6_NAMES.has(tagStart[1].toLowerCase())) cp.hazardVerdict = true;
|
|
584
642
|
}
|
|
585
643
|
const inRawText = cp.htmlFlowSinceBlank || rawOpenAtLineStart;
|
|
586
|
-
const rawFlowStart = ln.indent <= 3 && /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/.test(ln.text
|
|
644
|
+
const rawFlowStart = ln.indent <= 3 && /^<(?:!--|\?|![A-Za-z]|!\[CDATA\[)/.test(mdTrimStart(ln.text));
|
|
587
645
|
const { masked, unpaired } = inRawText ? { masked: null, unpaired: false } : maskIntraLineCodeSpans(ln.text, cp.paragraphHasUnpairedRun);
|
|
588
646
|
if (unpaired) cp.paragraphHasUnpairedRun = true;
|
|
589
647
|
const scanText = masked ?? ln.text;
|
|
@@ -601,28 +659,50 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
601
659
|
if (key && !cp.defs.has(key)) cp.defs.set(key, ln.end);
|
|
602
660
|
}
|
|
603
661
|
}
|
|
604
|
-
if (cp.referenceTaint
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
while ((m = REF_RE.exec(scanText)) !== null) {
|
|
609
|
-
const follow = scanText[m.index + m[0].length];
|
|
610
|
-
if (follow === "(") continue;
|
|
611
|
-
if (follow === ":" && m.index === defBracket) continue;
|
|
612
|
-
const inner = m[1];
|
|
662
|
+
if (cp.referenceTaint) {
|
|
663
|
+
const pushRef = (offset, inner, followAt) => {
|
|
664
|
+
const follow = scanText[followAt];
|
|
665
|
+
if (follow === "(" && inlineResourceEnd(scanText, followAt) !== -1) return;
|
|
613
666
|
let label;
|
|
614
667
|
let footnote = false;
|
|
615
668
|
if (inner.startsWith("^")) {
|
|
616
669
|
footnote = true;
|
|
617
670
|
label = normalizeLabel(inner.slice(1));
|
|
618
671
|
} else if (follow === "[") {
|
|
619
|
-
const explicit = /^\[((?:[^[\]\\]|\\.)*)\]/.exec(scanText.slice(
|
|
672
|
+
const explicit = /^\[((?:[^[\]\\]|\\.)*)\]/.exec(scanText.slice(followAt));
|
|
620
673
|
label = normalizeLabel(explicit && explicit[1] ? explicit[1] : inner);
|
|
621
674
|
} else {
|
|
622
675
|
label = normalizeLabel(inner);
|
|
623
676
|
}
|
|
624
|
-
if (
|
|
625
|
-
|
|
677
|
+
if (label) cp.unresolvedRefs.push({ offset, label, footnote });
|
|
678
|
+
};
|
|
679
|
+
const pending = cp.openBracket;
|
|
680
|
+
cp.openBracket = null;
|
|
681
|
+
if (pending) {
|
|
682
|
+
const close = firstUnescaped(scanText, "]");
|
|
683
|
+
const open = firstUnescaped(scanText, "[");
|
|
684
|
+
const cont = (t) => t.replace(/^ {0,3}>[ \t]?/, "");
|
|
685
|
+
if (close !== -1 && (open === -1 || close < open)) {
|
|
686
|
+
pushRef(pending.offset, `${pending.text}
|
|
687
|
+
${cont(scanText.slice(0, close))}`, close + 1);
|
|
688
|
+
} else if (close === -1 && open === -1) {
|
|
689
|
+
cp.openBracket = { offset: pending.offset, text: `${pending.text}
|
|
690
|
+
${cont(scanText)}` };
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (scanText.includes("[")) {
|
|
694
|
+
const defBracket = validDef ? def.index + def[0].indexOf("[") : -1;
|
|
695
|
+
REF_RE.lastIndex = 0;
|
|
696
|
+
let m;
|
|
697
|
+
while ((m = REF_RE.exec(scanText)) !== null) {
|
|
698
|
+
const followAt = m.index + m[0].length;
|
|
699
|
+
if (scanText[followAt] === ":" && m.index === defBracket) continue;
|
|
700
|
+
pushRef(ln.start + m.index, m[1], followAt);
|
|
701
|
+
}
|
|
702
|
+
const trailingOpen = lastUnclosedBracket(scanText);
|
|
703
|
+
if (trailingOpen !== -1) {
|
|
704
|
+
cp.openBracket = { offset: ln.start + trailingOpen, text: scanText.slice(trailingOpen + 1) };
|
|
705
|
+
}
|
|
626
706
|
}
|
|
627
707
|
}
|
|
628
708
|
const rawSpans = [];
|
|
@@ -683,7 +763,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
683
763
|
if (scanText[pi + 2] === ">") {
|
|
684
764
|
rawSpans.push([pi, pi + 3]);
|
|
685
765
|
pos = pi + 3;
|
|
686
|
-
if (scanText.slice(0, pi)
|
|
766
|
+
if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) poisonRawDivergence();
|
|
687
767
|
continue;
|
|
688
768
|
}
|
|
689
769
|
rawSpans.push([pi, pi + 2]);
|
|
@@ -734,7 +814,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
734
814
|
applyTag(tag, closing);
|
|
735
815
|
}
|
|
736
816
|
if (cp.commentOpen && lastCommentOpenerIdx !== -1 && !inRawText) {
|
|
737
|
-
if (tagText.slice(0, lastCommentOpenerIdx)
|
|
817
|
+
if (!isMdBlank(tagText.slice(0, lastCommentOpenerIdx))) {
|
|
738
818
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + lastCommentOpenerIdx);
|
|
739
819
|
}
|
|
740
820
|
}
|
|
@@ -960,13 +1040,14 @@ function rebaseDualWalk(node, segments, maxEnd, offsetDelta, lineDelta) {
|
|
|
960
1040
|
const position = node.position;
|
|
961
1041
|
if (position) {
|
|
962
1042
|
for (const point of [position.start, position.end]) {
|
|
1043
|
+
if (!point) continue;
|
|
963
1044
|
const seg = point.offset !== void 0 && point.offset <= maxEnd ? segments.find((s) => point.offset >= s.injStart && point.offset <= s.injEnd) : void 0;
|
|
964
1045
|
if (seg) {
|
|
965
1046
|
point.offset += seg.offsetDelta;
|
|
966
|
-
point.line += seg.lineDelta;
|
|
1047
|
+
if (typeof point.line === "number") point.line += seg.lineDelta;
|
|
967
1048
|
} else {
|
|
968
1049
|
if (point.offset !== void 0) point.offset += offsetDelta;
|
|
969
|
-
point.line += lineDelta;
|
|
1050
|
+
if (typeof point.line === "number") point.line += lineDelta;
|
|
970
1051
|
}
|
|
971
1052
|
}
|
|
972
1053
|
}
|
|
@@ -975,6 +1056,8 @@ function rebaseDualWalk(node, segments, maxEnd, offsetDelta, lineDelta) {
|
|
|
975
1056
|
for (const child of children) rebaseDualWalk(child, segments, maxEnd, offsetDelta, lineDelta);
|
|
976
1057
|
}
|
|
977
1058
|
}
|
|
1059
|
+
var TABLE_PART_TAG_RE = /<(?:td|th|tr|tbody|thead|tfoot|caption|col|colgroup)\b/i;
|
|
1060
|
+
var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
|
|
978
1061
|
function spliceTrees(input) {
|
|
979
1062
|
const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
|
|
980
1063
|
const injectedLen = injectionPrefix.length;
|
|
@@ -1031,6 +1114,12 @@ function spliceTrees(input) {
|
|
|
1031
1114
|
return !(start !== void 0 && start < injectedLen);
|
|
1032
1115
|
});
|
|
1033
1116
|
const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
|
|
1117
|
+
if (prefixMdast.some((c) => c.type === "html" && TABLE_PART_TAG_RE.test(c.value))) return null;
|
|
1118
|
+
for (const child of tailMdastChildren) {
|
|
1119
|
+
if (isWrapInvisible(child)) continue;
|
|
1120
|
+
if (child.type !== "html") break;
|
|
1121
|
+
if (STRAY_SYNTHESIZED_END_TAG_RE.test(child.value) || TABLE_PART_TAG_RE.test(child.value)) return null;
|
|
1122
|
+
}
|
|
1034
1123
|
const aligned = alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible);
|
|
1035
1124
|
if (aligned === null) return null;
|
|
1036
1125
|
const hastChildren = aligned.children;
|
|
@@ -1133,6 +1222,9 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
|
|
|
1133
1222
|
nextIdx = pairIdx + 1 + stripped;
|
|
1134
1223
|
const candidate = visibles[nextIdx];
|
|
1135
1224
|
if (!candidate) return null;
|
|
1225
|
+
if (start === void 0 && sepBuffer.some((sep) => sep.type !== "text" || sep.value !== "\n")) {
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1136
1228
|
if (start !== void 0) {
|
|
1137
1229
|
const cStart = candidate.position?.start?.offset;
|
|
1138
1230
|
const cEnd = candidate.position?.end?.offset;
|
|
@@ -1149,7 +1241,13 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
|
|
|
1149
1241
|
const trailingGaps = sawContent ? trailingStripped : Math.max(0, visibles.length - 1);
|
|
1150
1242
|
const seam = visibles.length > 0 && tailWrapVisible ? 1 : 0;
|
|
1151
1243
|
const last = out[out.length - 1];
|
|
1244
|
+
if (last !== void 0 && last.type === "text" && last.position !== void 0 && last.value.trim() === "") {
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1152
1247
|
const lastIsLiteral = last !== void 0 && last.type === "text" && last.value.trim() !== "";
|
|
1248
|
+
if (lastIsLiteral && pairIdx >= 0 && visibles[pairIdx].type !== "html") {
|
|
1249
|
+
return null;
|
|
1250
|
+
}
|
|
1153
1251
|
const litOwnerEnd = pairIdx >= 0 ? visibles[pairIdx].position?.end?.offset : void 0;
|
|
1154
1252
|
const litEnd = lastIsLiteral ? last.position?.end?.offset : void 0;
|
|
1155
1253
|
if (lastIsLiteral && last.position !== void 0 && (litEnd === void 0 || litOwnerEnd === void 0)) {
|
|
@@ -1186,8 +1284,16 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
|
|
|
1186
1284
|
const v = lastPaired.value;
|
|
1187
1285
|
const lastLt = v.lastIndexOf("<");
|
|
1188
1286
|
if (lastLt !== -1 && /^<[!?]/.test(v.slice(lastLt))) return null;
|
|
1287
|
+
const lastOut = out[out.length - 1];
|
|
1288
|
+
const outEnd = lastOut?.type === "element" ? lastOut.position?.end?.offset : void 0;
|
|
1289
|
+
const blockEnd = lastPaired.position?.end?.offset;
|
|
1290
|
+
if (outEnd !== void 0 && blockEnd !== void 0 && outEnd < blockEnd) return null;
|
|
1189
1291
|
}
|
|
1190
1292
|
if (sepBuffer.length !== trailingGaps && sepBuffer.length !== trailingGaps + 1) return null;
|
|
1293
|
+
for (let j = pairIdx + 1; j < visibles.length; j++) {
|
|
1294
|
+
const v = visibles[j];
|
|
1295
|
+
if (v.type === "html" && !/^\s*<[!?]/.test(v.value)) return null;
|
|
1296
|
+
}
|
|
1191
1297
|
for (let i = 0; i < trailingGaps + seam; i++) {
|
|
1192
1298
|
out.push({ type: "text", value: "\n" });
|
|
1193
1299
|
}
|
|
@@ -1230,8 +1336,9 @@ function stripInjectedHast(tailMdast, tailHast, injectedLen, tailWrapVisible) {
|
|
|
1230
1336
|
}
|
|
1231
1337
|
function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
|
|
1232
1338
|
const firstText = tailHastChildren[0];
|
|
1233
|
-
if (!firstText) return false;
|
|
1234
1339
|
const firstVisible = tailMdastChildren.find((c) => !isWrapInvisible(c));
|
|
1340
|
+
if (firstVisible?.type === "html" && STRAY_SYNTHESIZED_END_TAG_RE.test(firstVisible.value)) return null;
|
|
1341
|
+
if (!firstText) return false;
|
|
1235
1342
|
if (!isSeparatorText(firstText)) {
|
|
1236
1343
|
if (firstText.type === "text" && firstText.position === void 0 && firstVisible?.type === "html") {
|
|
1237
1344
|
if (/^\s*<\/[A-Za-z][A-Za-z0-9-]*\s*>/.test(firstVisible.value)) return true;
|
|
@@ -1672,17 +1779,8 @@ function phantomSuffixCloser(content) {
|
|
|
1672
1779
|
}
|
|
1673
1780
|
|
|
1674
1781
|
// src/components/extractContributions.ts
|
|
1675
|
-
function fakeAnchorElement(url) {
|
|
1676
|
-
return { type: "element", tagName: "a", properties: { href: url }, children: [] };
|
|
1677
|
-
}
|
|
1678
|
-
function sanitizeDefUrl(url, urlTransform) {
|
|
1679
|
-
if (!urlTransform) return url;
|
|
1680
|
-
const result = urlTransform(url, "href", fakeAnchorElement(url));
|
|
1681
|
-
return result == null ? "" : String(result);
|
|
1682
|
-
}
|
|
1683
1782
|
function* extractContributions(mdast, options = {}) {
|
|
1684
1783
|
const phantomFn = options.phantomFootnoteLabels;
|
|
1685
|
-
const urlTransform = options.urlTransform;
|
|
1686
1784
|
const out = [];
|
|
1687
1785
|
visit3(mdast, (n) => {
|
|
1688
1786
|
if (n.type === "footnoteReference") {
|
|
@@ -1710,7 +1808,7 @@ function* extractContributions(mdast, options = {}) {
|
|
|
1710
1808
|
out.push({
|
|
1711
1809
|
kind: "linkDef",
|
|
1712
1810
|
label: normalizeId(d.identifier),
|
|
1713
|
-
url:
|
|
1811
|
+
url: d.url,
|
|
1714
1812
|
title: d.title
|
|
1715
1813
|
});
|
|
1716
1814
|
}
|
|
@@ -1782,6 +1880,7 @@ function createRegistry(onEmpty) {
|
|
|
1782
1880
|
}
|
|
1783
1881
|
},
|
|
1784
1882
|
contributeLabels(symbol, footnotes, links) {
|
|
1883
|
+
if (!this.chunkOrder.includes(symbol)) return;
|
|
1785
1884
|
const data = this.chunkData.get(symbol);
|
|
1786
1885
|
if (data) {
|
|
1787
1886
|
data.ownFootnoteLabels = footnotes;
|
|
@@ -1806,6 +1905,7 @@ function createRegistry(onEmpty) {
|
|
|
1806
1905
|
this._notify();
|
|
1807
1906
|
},
|
|
1808
1907
|
contributeChunkData(symbol, data) {
|
|
1908
|
+
if (!this.chunkOrder.includes(symbol)) return;
|
|
1809
1909
|
this.chunkData.set(symbol, data);
|
|
1810
1910
|
this.labelSet.footnoteLabels = /* @__PURE__ */ new Set();
|
|
1811
1911
|
this.labelSet.linkLabels = /* @__PURE__ */ new Set();
|
|
@@ -1911,14 +2011,16 @@ import rehypeUnwrapImages from "rehype-unwrap-images";
|
|
|
1911
2011
|
import { SKIP as SKIP3, visit as visit4 } from "unist-util-visit";
|
|
1912
2012
|
var IMAGE_TAGS = /* @__PURE__ */ new Set(["img", "cross-chunk-image"]);
|
|
1913
2013
|
var LINK_TAGS = /* @__PURE__ */ new Set(["a", "cross-chunk-link"]);
|
|
1914
|
-
function applicable(node, inLink) {
|
|
2014
|
+
function applicable(node, inLink, seen) {
|
|
1915
2015
|
let image = 0 /* Unknown */;
|
|
1916
2016
|
for (const child of node.children) {
|
|
1917
2017
|
if (child.type === "text" && /^\s*$/.test(child.value)) continue;
|
|
1918
2018
|
if (child.type === "element" && IMAGE_TAGS.has(child.tagName)) {
|
|
2019
|
+
if (child.tagName !== "img") seen.placeholder = true;
|
|
1919
2020
|
image = 1 /* ContainsImage */;
|
|
1920
2021
|
} else if (!inLink && child.type === "element" && LINK_TAGS.has(child.tagName)) {
|
|
1921
|
-
|
|
2022
|
+
if (child.tagName !== "a") seen.placeholder = true;
|
|
2023
|
+
const inner = applicable(child, true, seen);
|
|
1922
2024
|
if (inner === 2 /* ContainsOther */) return 2 /* ContainsOther */;
|
|
1923
2025
|
if (inner === 1 /* ContainsImage */) image = 1 /* ContainsImage */;
|
|
1924
2026
|
} else {
|
|
@@ -1930,9 +2032,9 @@ function applicable(node, inLink) {
|
|
|
1930
2032
|
function rehypeUnwrapCrossChunkImages() {
|
|
1931
2033
|
return function transform(tree) {
|
|
1932
2034
|
visit4(tree, "element", (node, index, parent) => {
|
|
1933
|
-
if (node.tagName
|
|
1934
|
-
|
|
1935
|
-
|
|
2035
|
+
if (node.tagName !== "p" || !parent || typeof index !== "number") return;
|
|
2036
|
+
const seen = { placeholder: false };
|
|
2037
|
+
if (applicable(node, false, seen) === 1 /* ContainsImage */ && seen.placeholder) {
|
|
1936
2038
|
parent.children.splice(index, 1, ...node.children);
|
|
1937
2039
|
return [SKIP3, index];
|
|
1938
2040
|
}
|
|
@@ -3420,14 +3522,11 @@ function isProtocolAllowed(url, allowed) {
|
|
|
3420
3522
|
}
|
|
3421
3523
|
function sanitizeCrossChunkUrl(rawUrl, key, tagName, urlTransform, schema) {
|
|
3422
3524
|
rawUrl = normalizeUri2(rawUrl);
|
|
3525
|
+
const allowed = Object.hasOwn(schema, "protocols") ? schema.protocols?.[key] : sanitizeSchema.protocols?.[key];
|
|
3526
|
+
if (allowed && allowed.length > 0 && !isProtocolAllowed(rawUrl, allowed)) return null;
|
|
3423
3527
|
const transformed = urlTransform(rawUrl, key, fakeElement(tagName, key, rawUrl));
|
|
3424
|
-
if (transformed == null) return
|
|
3425
|
-
|
|
3426
|
-
if (stringUrl === "") return "";
|
|
3427
|
-
const callerProtocols = schema.protocols;
|
|
3428
|
-
const allowed = callerProtocols === void 0 || callerProtocols === null ? sanitizeSchema.protocols?.[key] : callerProtocols[key];
|
|
3429
|
-
if (!allowed || allowed.length === 0) return stringUrl;
|
|
3430
|
-
return isProtocolAllowed(stringUrl, allowed) ? stringUrl : "";
|
|
3528
|
+
if (transformed == null) return null;
|
|
3529
|
+
return String(transformed);
|
|
3431
3530
|
}
|
|
3432
3531
|
|
|
3433
3532
|
// src/plugins/defs.ts
|
|
@@ -3819,15 +3918,28 @@ var LITERAL_CONTENT_CLOSE_REGEX = {
|
|
|
3819
3918
|
math: /<\/math\s*>/gi,
|
|
3820
3919
|
svg: /<\/svg\s*>/gi
|
|
3821
3920
|
};
|
|
3822
|
-
function
|
|
3921
|
+
function restOfLineIsBlank(content, pos) {
|
|
3922
|
+
for (let i = pos; i < content.length; i++) {
|
|
3923
|
+
const c = content[i];
|
|
3924
|
+
if (c === "\n") return true;
|
|
3925
|
+
if (c !== " " && c !== " " && c !== "\r") return false;
|
|
3926
|
+
}
|
|
3927
|
+
return true;
|
|
3928
|
+
}
|
|
3929
|
+
function lineHasBacktick(content, pos) {
|
|
3930
|
+
for (let i = pos; i < content.length && content[i] !== "\n"; i++) {
|
|
3931
|
+
if (content[i] === "`") return true;
|
|
3932
|
+
}
|
|
3933
|
+
return false;
|
|
3934
|
+
}
|
|
3935
|
+
function lineIndentBefore(content, pos) {
|
|
3823
3936
|
let i = pos - 1;
|
|
3824
|
-
let
|
|
3825
|
-
while (i >= 0 && content[i] === " ") {
|
|
3826
|
-
|
|
3827
|
-
if (spaces > 3) return false;
|
|
3937
|
+
let indent = 0;
|
|
3938
|
+
while (i >= 0 && (content[i] === " " || content[i] === " ")) {
|
|
3939
|
+
indent += content[i] === " " ? 4 : 1;
|
|
3828
3940
|
i--;
|
|
3829
3941
|
}
|
|
3830
|
-
return i < 0 || content[i] === "\n" || content[i] === "\r";
|
|
3942
|
+
return i < 0 || content[i] === "\n" || content[i] === "\r" ? indent : -1;
|
|
3831
3943
|
}
|
|
3832
3944
|
function findClosingBacktickRun(content, start, n) {
|
|
3833
3945
|
let i = start;
|
|
@@ -3848,6 +3960,7 @@ function splitByProtectedRegions(content) {
|
|
|
3848
3960
|
let multilineStart = -1;
|
|
3849
3961
|
let multilineFenceMarker = null;
|
|
3850
3962
|
let multilineFenceLength = 0;
|
|
3963
|
+
let multilineFenceIndent = 0;
|
|
3851
3964
|
function pushProtected(start, end) {
|
|
3852
3965
|
if (start > lastIndex) {
|
|
3853
3966
|
segments.push({ text: content.substring(lastIndex, start), isCode: false });
|
|
@@ -3861,7 +3974,8 @@ function splitByProtectedRegions(content) {
|
|
|
3861
3974
|
if (multilineStart !== -1) {
|
|
3862
3975
|
if (char === multilineFenceMarker) {
|
|
3863
3976
|
const runLen = getRepeatedMarkerLength(content, i, multilineFenceMarker);
|
|
3864
|
-
|
|
3977
|
+
const closerIndent = lineIndentBefore(content, i);
|
|
3978
|
+
if (runLen >= multilineFenceLength && closerIndent !== -1 && closerIndent <= multilineFenceIndent + 3 && restOfLineIsBlank(content, i + runLen)) {
|
|
3865
3979
|
pushProtected(multilineStart, i + runLen);
|
|
3866
3980
|
multilineStart = -1;
|
|
3867
3981
|
multilineFenceMarker = null;
|
|
@@ -3877,10 +3991,12 @@ function splitByProtectedRegions(content) {
|
|
|
3877
3991
|
}
|
|
3878
3992
|
if (char === "`" || char === "~") {
|
|
3879
3993
|
const runLen = getRepeatedMarkerLength(content, i, char);
|
|
3880
|
-
|
|
3994
|
+
const openerIndent = lineIndentBefore(content, i);
|
|
3995
|
+
if (runLen >= 3 && openerIndent !== -1 && !(char === "`" && lineHasBacktick(content, i + runLen))) {
|
|
3881
3996
|
multilineStart = i;
|
|
3882
3997
|
multilineFenceMarker = char;
|
|
3883
3998
|
multilineFenceLength = runLen;
|
|
3999
|
+
multilineFenceIndent = openerIndent;
|
|
3884
4000
|
i += runLen;
|
|
3885
4001
|
continue;
|
|
3886
4002
|
}
|