@ai-matrx/content-ir 0.19.15 → 0.19.18
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/CHANGELOG.md +17 -0
- package/dist/index.cjs +223 -203
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +223 -204
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +223 -203
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +3 -1
- package/dist/source.d.ts +3 -1
- package/dist/source.js +223 -204
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
package/dist/source.d.cts
CHANGED
|
@@ -488,6 +488,8 @@ interface LinkDefinition {
|
|
|
488
488
|
declare function normalizeLinkLabel(label: string): string;
|
|
489
489
|
/** Every link reference definition in `text` (first one wins, as in CommonMark); fenced code is skipped. */
|
|
490
490
|
declare function collectLinkDefinitions(text: string): Map<string, LinkDefinition>;
|
|
491
|
+
/** The line indices (text split on "\n") that ARE link reference definitions — GFM renders nothing for them. */
|
|
492
|
+
declare function findLinkDefinitionLines(text: string): number[];
|
|
491
493
|
/**
|
|
492
494
|
* `fragment` with every reference link whose label is defined rewritten inline.
|
|
493
495
|
* An image (`![alt][ref]`) resolves too. Nothing else changes.
|
|
@@ -724,4 +726,4 @@ declare function findTableStart(lines: readonly string[], from?: number): number
|
|
|
724
726
|
/** Index just past the table whose header is at `start` (header, delimiter, then continuation rows). */
|
|
725
727
|
declare function findTableEnd(lines: readonly string[], start: number): number;
|
|
726
728
|
|
|
727
|
-
export { AFTER_WINDOW, BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type LinkDefinition, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
|
729
|
+
export { AFTER_WINDOW, BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type LinkDefinition, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
package/dist/source.d.ts
CHANGED
|
@@ -488,6 +488,8 @@ interface LinkDefinition {
|
|
|
488
488
|
declare function normalizeLinkLabel(label: string): string;
|
|
489
489
|
/** Every link reference definition in `text` (first one wins, as in CommonMark); fenced code is skipped. */
|
|
490
490
|
declare function collectLinkDefinitions(text: string): Map<string, LinkDefinition>;
|
|
491
|
+
/** The line indices (text split on "\n") that ARE link reference definitions — GFM renders nothing for them. */
|
|
492
|
+
declare function findLinkDefinitionLines(text: string): number[];
|
|
491
493
|
/**
|
|
492
494
|
* `fragment` with every reference link whose label is defined rewritten inline.
|
|
493
495
|
* An image (`![alt][ref]`) resolves too. Nothing else changes.
|
|
@@ -724,4 +726,4 @@ declare function findTableStart(lines: readonly string[], from?: number): number
|
|
|
724
726
|
/** Index just past the table whose header is at `start` (header, delimiter, then continuation rows). */
|
|
725
727
|
declare function findTableEnd(lines: readonly string[], start: number): number;
|
|
726
728
|
|
|
727
|
-
export { AFTER_WINDOW, BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type LinkDefinition, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
|
729
|
+
export { AFTER_WINDOW, BacktickRuns, type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type CodeRange, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type FenceEnd, type FenceLineKind, type FenceLines, type FenceOpener, FenceReader, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type LinkDefinition, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
package/dist/source.js
CHANGED
|
@@ -997,6 +997,204 @@ var XmlContainerTracker = class {
|
|
|
997
997
|
}
|
|
998
998
|
};
|
|
999
999
|
|
|
1000
|
+
// source/gfm-table.ts
|
|
1001
|
+
function splitRowSegments(line) {
|
|
1002
|
+
const segments = [];
|
|
1003
|
+
let start = 0;
|
|
1004
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
1005
|
+
const ch = line[i];
|
|
1006
|
+
if (ch === "\\") {
|
|
1007
|
+
i += 1;
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
1010
|
+
if (ch === "|") {
|
|
1011
|
+
segments.push(line.slice(start, i));
|
|
1012
|
+
start = i + 1;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
segments.push(line.slice(start));
|
|
1016
|
+
return segments;
|
|
1017
|
+
}
|
|
1018
|
+
function rowCells(line) {
|
|
1019
|
+
const cells = splitRowSegments(line).map((cell) => cell.trim());
|
|
1020
|
+
if (cells.length > 1 && cells[0] === "") cells.shift();
|
|
1021
|
+
if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
|
|
1022
|
+
else if (cells.length === 1 && cells[0] === "" && !line.includes("|")) cells.pop();
|
|
1023
|
+
return cells;
|
|
1024
|
+
}
|
|
1025
|
+
function unescapeCellPipes(cell) {
|
|
1026
|
+
return cell.replace(/\\\|/g, "|");
|
|
1027
|
+
}
|
|
1028
|
+
var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$|\[\^[^\]\s]+\]:)/;
|
|
1029
|
+
var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
1030
|
+
var HTML_RAW = /^<(?:script|pre|style|textarea)(?:[\s>]|$)/i;
|
|
1031
|
+
var HTML_COMMENT_ETC = /^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[)/;
|
|
1032
|
+
var HTML_BLOCK_NAMES = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
|
|
1033
|
+
var HTML_BLOCK_TAG = new RegExp(`^</?(?:${HTML_BLOCK_NAMES})(?:[\\s>]|/>|$)`, "i");
|
|
1034
|
+
var ATTRIBUTE = `\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?`;
|
|
1035
|
+
var HTML_COMPLETE_TAG = new RegExp(`^(?:<[A-Za-z][A-Za-z0-9-]*(?:${ATTRIBUTE})*\\s*/?>|</[A-Za-z][A-Za-z0-9-]*\\s*>)\\s*$`);
|
|
1036
|
+
var HTML_BLOCK_NAME_SET = /* @__PURE__ */ new Set([
|
|
1037
|
+
// Condition 1 (raw text) and condition 6 (block) tag names — CommonMark 0.31.
|
|
1038
|
+
"script",
|
|
1039
|
+
"pre",
|
|
1040
|
+
"style",
|
|
1041
|
+
"textarea",
|
|
1042
|
+
...HTML_BLOCK_NAMES.replace("h[1-6]", "h1|h2|h3|h4|h5|h6").split("|")
|
|
1043
|
+
]);
|
|
1044
|
+
function isHtmlBlockTagName(name) {
|
|
1045
|
+
return HTML_BLOCK_NAME_SET.has(name.toLowerCase());
|
|
1046
|
+
}
|
|
1047
|
+
function startsHtmlBlock(trimmed) {
|
|
1048
|
+
if (!trimmed.startsWith("<")) return false;
|
|
1049
|
+
return HTML_RAW.test(trimmed) || HTML_COMMENT_ETC.test(trimmed) || HTML_BLOCK_TAG.test(trimmed) || HTML_COMPLETE_TAG.test(trimmed);
|
|
1050
|
+
}
|
|
1051
|
+
function lineIndent(line) {
|
|
1052
|
+
let column = 0;
|
|
1053
|
+
for (const ch of line) {
|
|
1054
|
+
if (ch === " ") column += 1;
|
|
1055
|
+
else if (ch === " ") column += 4 - column % 4;
|
|
1056
|
+
else break;
|
|
1057
|
+
}
|
|
1058
|
+
return column;
|
|
1059
|
+
}
|
|
1060
|
+
var LIST_MARKER = /^([ \t]*)([-+*]|\d{1,9}[.)])([ \t]+|$)/;
|
|
1061
|
+
function markerContentColumn(marker) {
|
|
1062
|
+
const markerEnd = lineIndent(marker[1] ?? "") + (marker[2] ?? "").length;
|
|
1063
|
+
const gap = marker[3] ? lineIndent(" ".repeat(markerEnd) + marker[3]) - markerEnd : 1;
|
|
1064
|
+
return markerEnd + (gap >= 1 && gap <= 4 ? gap : 1);
|
|
1065
|
+
}
|
|
1066
|
+
function tableContainerIndent(lines, start) {
|
|
1067
|
+
return tableContainerIndentOf(lines, start, false);
|
|
1068
|
+
}
|
|
1069
|
+
function tableContainerIndentOf(lines, start, ownItem) {
|
|
1070
|
+
const own = ownItem ? LIST_MARKER.exec(lines[start] ?? "") : null;
|
|
1071
|
+
if (own) return markerContentColumn(own);
|
|
1072
|
+
const header = lineIndent(lines[start] ?? "");
|
|
1073
|
+
if (header === 0) return 0;
|
|
1074
|
+
for (let k = start - 1; k >= 0; k -= 1) {
|
|
1075
|
+
const line = lines[k] ?? "";
|
|
1076
|
+
if (!line.trim()) continue;
|
|
1077
|
+
const indent = lineIndent(line);
|
|
1078
|
+
const marker = LIST_MARKER.exec(line);
|
|
1079
|
+
if (marker && indent < header) {
|
|
1080
|
+
const content = markerContentColumn(marker);
|
|
1081
|
+
if (content <= header) return content;
|
|
1082
|
+
continue;
|
|
1083
|
+
}
|
|
1084
|
+
if (indent === 0) return 0;
|
|
1085
|
+
}
|
|
1086
|
+
return 0;
|
|
1087
|
+
}
|
|
1088
|
+
var DELIMITER_CELL = /^:?-+:?$/;
|
|
1089
|
+
function isGfmDelimiterRow(line) {
|
|
1090
|
+
const trimmed = line.trim();
|
|
1091
|
+
if (!trimmed.includes("|")) return false;
|
|
1092
|
+
const cells = rowCells(trimmed);
|
|
1093
|
+
return cells.length > 0 && cells.every((cell) => DELIMITER_CELL.test(cell));
|
|
1094
|
+
}
|
|
1095
|
+
function isPipeLedRow(line) {
|
|
1096
|
+
const trimmed = line.trim();
|
|
1097
|
+
return trimmed.startsWith("|") && trimmed.includes("|", 1);
|
|
1098
|
+
}
|
|
1099
|
+
function isTableDelimiter(line) {
|
|
1100
|
+
if (line === void 0 || !isGfmDelimiterRow(line)) return false;
|
|
1101
|
+
return !BLOCK_START.test(line.trim());
|
|
1102
|
+
}
|
|
1103
|
+
function startsPipelessTable(header, delimiter) {
|
|
1104
|
+
const head = header.trim();
|
|
1105
|
+
if (!head || isPipeLedRow(head) || !head.startsWith("|") && startsBlock(head)) return false;
|
|
1106
|
+
if (!isTableDelimiter(delimiter)) return false;
|
|
1107
|
+
return rowCells(head).length === rowCells(delimiter.trim()).length;
|
|
1108
|
+
}
|
|
1109
|
+
function continuesTable(line, containerIndent = 0) {
|
|
1110
|
+
const trimmed = line.trim();
|
|
1111
|
+
if (!trimmed) return false;
|
|
1112
|
+
if (lineIndent(line) - containerIndent >= 4) return false;
|
|
1113
|
+
return trimmed.startsWith("|") || !startsBlock(trimmed);
|
|
1114
|
+
}
|
|
1115
|
+
function opensTable(lines, index) {
|
|
1116
|
+
const line = lines[index] ?? "";
|
|
1117
|
+
if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
|
|
1118
|
+
return !isLazyContinuation(lines, index) && !insideHtmlBlock(lines, index);
|
|
1119
|
+
}
|
|
1120
|
+
var QUOTE_LINE = /^ {0,3}>/;
|
|
1121
|
+
var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
1122
|
+
var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
1123
|
+
function htmlBlockEnd(trimmed) {
|
|
1124
|
+
if (HTML_RAW.test(trimmed)) return /<\/(?:script|pre|style|textarea)>/i;
|
|
1125
|
+
if (trimmed.startsWith("<!--")) return /-->/;
|
|
1126
|
+
if (trimmed.startsWith("<?")) return /\?>/;
|
|
1127
|
+
if (trimmed.startsWith("<![CDATA[")) return /\]\]>/;
|
|
1128
|
+
if (/^<![A-Za-z]/.test(trimmed)) return />/;
|
|
1129
|
+
if (HTML_BLOCK_TAG.test(trimmed)) return null;
|
|
1130
|
+
if (HTML_COMPLETE_TAG.test(trimmed)) return null;
|
|
1131
|
+
return void 0;
|
|
1132
|
+
}
|
|
1133
|
+
function insideHtmlBlock(lines, index) {
|
|
1134
|
+
let start = index;
|
|
1135
|
+
while (start > 0 && (lines[start - 1] ?? "").trim()) start -= 1;
|
|
1136
|
+
let open;
|
|
1137
|
+
let paragraph = false;
|
|
1138
|
+
for (let k = start; k < index; k += 1) {
|
|
1139
|
+
const line = lines[k] ?? "";
|
|
1140
|
+
if (open !== void 0) {
|
|
1141
|
+
if (open && open.test(line)) open = void 0;
|
|
1142
|
+
continue;
|
|
1143
|
+
}
|
|
1144
|
+
const trimmed = line.trim();
|
|
1145
|
+
const end = lineIndent(line) < 4 ? htmlBlockEnd(trimmed) : void 0;
|
|
1146
|
+
const type7 = end === null && !HTML_BLOCK_TAG.test(trimmed);
|
|
1147
|
+
const interrupts = end !== void 0 && !(paragraph && type7);
|
|
1148
|
+
if (!interrupts) {
|
|
1149
|
+
paragraph = true;
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
paragraph = false;
|
|
1153
|
+
open = end && end.test(trimmed.slice(2)) ? void 0 : end;
|
|
1154
|
+
}
|
|
1155
|
+
return open !== void 0;
|
|
1156
|
+
}
|
|
1157
|
+
function isLazyContinuation(lines, index) {
|
|
1158
|
+
const header = lines[index] ?? "";
|
|
1159
|
+
let first = -1;
|
|
1160
|
+
for (let k = index - 1; k >= 0; k -= 1) {
|
|
1161
|
+
const line = lines[k] ?? "";
|
|
1162
|
+
const trimmed = line.trim();
|
|
1163
|
+
if (!trimmed) break;
|
|
1164
|
+
if (breaksParagraph(trimmed)) break;
|
|
1165
|
+
const marker = LIST_MARKER.exec(line);
|
|
1166
|
+
if (marker) {
|
|
1167
|
+
const rest = line.slice(marker[0].length).trim();
|
|
1168
|
+
if (!rest || breaksParagraph(rest)) break;
|
|
1169
|
+
first = k;
|
|
1170
|
+
break;
|
|
1171
|
+
}
|
|
1172
|
+
first = k;
|
|
1173
|
+
if (QUOTE_LINE.test(line)) break;
|
|
1174
|
+
}
|
|
1175
|
+
if (first < 0) return false;
|
|
1176
|
+
const start = lines[first] ?? "";
|
|
1177
|
+
if (QUOTE_LINE.test(start)) return !QUOTE_LINE.test(header);
|
|
1178
|
+
return lineIndent(header) < tableContainerIndentOf(lines, first, true);
|
|
1179
|
+
}
|
|
1180
|
+
function tableStartsAt(lines, index) {
|
|
1181
|
+
const header = lines[index] ?? "";
|
|
1182
|
+
const delimiter = lines[index + 1];
|
|
1183
|
+
if (!opensTable(lines, index) || !isTableDelimiter(delimiter)) return false;
|
|
1184
|
+
if (rowCells(header).length !== rowCells(delimiter).length) return false;
|
|
1185
|
+
return lineIndent(header) - tableContainerIndent(lines, index) < 4;
|
|
1186
|
+
}
|
|
1187
|
+
function findTableStart(lines, from = 0) {
|
|
1188
|
+
for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
|
|
1189
|
+
return -1;
|
|
1190
|
+
}
|
|
1191
|
+
function findTableEnd(lines, start) {
|
|
1192
|
+
const container = tableContainerIndent(lines, start);
|
|
1193
|
+
let end = Math.min(lines.length, start + 2);
|
|
1194
|
+
while (end < lines.length && continuesTable(lines[end] ?? "", container)) end += 1;
|
|
1195
|
+
return end;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1000
1198
|
// source/tokenize.ts
|
|
1001
1199
|
var NOT_WHITESPACE = /\S/;
|
|
1002
1200
|
var DIRECTIVE_OPEN = /^(:{2,})([A-Za-z][\w-]*)/;
|
|
@@ -1838,9 +2036,12 @@ var Tokenizer = class {
|
|
|
1838
2036
|
});
|
|
1839
2037
|
}
|
|
1840
2038
|
}
|
|
2039
|
+
if (isHtmlBlockTagName(root)) return null;
|
|
1841
2040
|
return this.island("xml_container", p, this.n, false, { tag: root });
|
|
1842
2041
|
}
|
|
1843
2042
|
if (isUnclosedGenericXmlOpening(seg)) {
|
|
2043
|
+
const name = /^\s*<([A-Za-z_][\w.:-]*)/.exec(seg)?.[1] ?? "";
|
|
2044
|
+
if (isHtmlBlockTagName(name)) return null;
|
|
1844
2045
|
return this.island("xml_container", p, this.n, false, {});
|
|
1845
2046
|
}
|
|
1846
2047
|
return null;
|
|
@@ -2610,20 +2811,36 @@ function normalizeLinkLabel(label) {
|
|
|
2610
2811
|
var DEFINITION = /^ {0,3}\[((?:[^\]\\]|\\.){1,999})\]:[ \t]*(?:<([^<>\n]*)>|(\S+))(?:[ \t]+(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|\(((?:[^()\\]|\\.)*)\)))?[ \t]*$/;
|
|
2611
2812
|
function collectLinkDefinitions(text) {
|
|
2612
2813
|
const defs = /* @__PURE__ */ new Map();
|
|
2613
|
-
|
|
2814
|
+
for (const { label, definition } of scanLinkDefinitions(text)) {
|
|
2815
|
+
const key = normalizeLinkLabel(label);
|
|
2816
|
+
if (key && !defs.has(key)) defs.set(key, definition);
|
|
2817
|
+
}
|
|
2818
|
+
return defs;
|
|
2819
|
+
}
|
|
2820
|
+
function findLinkDefinitionLines(text) {
|
|
2821
|
+
return scanLinkDefinitions(text).map(({ line }) => line);
|
|
2822
|
+
}
|
|
2823
|
+
function scanLinkDefinitions(text) {
|
|
2824
|
+
const found = [];
|
|
2825
|
+
if (!text.includes("]:")) return found;
|
|
2614
2826
|
const lines = text.split("\n");
|
|
2615
2827
|
const kinds = fenceLineKinds(text);
|
|
2828
|
+
let previousWasDefinition = false;
|
|
2616
2829
|
lines.forEach((line, i) => {
|
|
2830
|
+
const wasDefinition = previousWasDefinition;
|
|
2831
|
+
previousWasDefinition = false;
|
|
2617
2832
|
if (kinds[i] !== "prose") return;
|
|
2618
2833
|
const m = DEFINITION.exec(line);
|
|
2619
2834
|
if (!m) return;
|
|
2835
|
+
const above = i > 0 ? lines[i - 1] ?? "" : "";
|
|
2836
|
+
const opensBlock = i === 0 || !above.trim() || wasDefinition || kinds[i - 1] === "close" || /^ {0,3}(?:#{1,6}(?:\s|$)|(?:[-*_][ \t]*){3,}$)/.test(above);
|
|
2837
|
+
if (!opensBlock) return;
|
|
2620
2838
|
const label = m[1] ?? "";
|
|
2621
2839
|
if (label.startsWith("^")) return;
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
defs.set(key, { url: m[2] ?? m[3] ?? "", title: m[4] ?? m[5] ?? m[6] ?? null });
|
|
2840
|
+
previousWasDefinition = true;
|
|
2841
|
+
found.push({ line: i, label, definition: { url: m[2] ?? m[3] ?? "", title: m[4] ?? m[5] ?? m[6] ?? null } });
|
|
2625
2842
|
});
|
|
2626
|
-
return
|
|
2843
|
+
return found;
|
|
2627
2844
|
}
|
|
2628
2845
|
var REFERENCE = /(!?)\[((?:[^\]\\]|\\.)*)\](?:\[((?:[^\]\\]|\\.)*)\])?(?![(:[])/g;
|
|
2629
2846
|
var escapeTitle = (title) => title.replace(/["\\]/g, "\\$&");
|
|
@@ -2648,204 +2865,6 @@ function resolveReferenceLinks(fragment, defs) {
|
|
|
2648
2865
|
return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
|
|
2649
2866
|
}
|
|
2650
2867
|
|
|
2651
|
-
|
|
2652
|
-
function splitRowSegments(line) {
|
|
2653
|
-
const segments = [];
|
|
2654
|
-
let start = 0;
|
|
2655
|
-
for (let i = 0; i < line.length; i += 1) {
|
|
2656
|
-
const ch = line[i];
|
|
2657
|
-
if (ch === "\\") {
|
|
2658
|
-
i += 1;
|
|
2659
|
-
continue;
|
|
2660
|
-
}
|
|
2661
|
-
if (ch === "|") {
|
|
2662
|
-
segments.push(line.slice(start, i));
|
|
2663
|
-
start = i + 1;
|
|
2664
|
-
}
|
|
2665
|
-
}
|
|
2666
|
-
segments.push(line.slice(start));
|
|
2667
|
-
return segments;
|
|
2668
|
-
}
|
|
2669
|
-
function rowCells(line) {
|
|
2670
|
-
const cells = splitRowSegments(line).map((cell) => cell.trim());
|
|
2671
|
-
if (cells.length > 1 && cells[0] === "") cells.shift();
|
|
2672
|
-
if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
|
|
2673
|
-
else if (cells.length === 1 && cells[0] === "" && !line.includes("|")) cells.pop();
|
|
2674
|
-
return cells;
|
|
2675
|
-
}
|
|
2676
|
-
function unescapeCellPipes(cell) {
|
|
2677
|
-
return cell.replace(/\\\|/g, "|");
|
|
2678
|
-
}
|
|
2679
|
-
var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$|\[\^[^\]\s]+\]:)/;
|
|
2680
|
-
var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
2681
|
-
var HTML_RAW = /^<(?:script|pre|style|textarea)(?:[\s>]|$)/i;
|
|
2682
|
-
var HTML_COMMENT_ETC = /^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[)/;
|
|
2683
|
-
var HTML_BLOCK_NAMES = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
|
|
2684
|
-
var HTML_BLOCK_TAG = new RegExp(`^</?(?:${HTML_BLOCK_NAMES})(?:[\\s>]|/>|$)`, "i");
|
|
2685
|
-
var ATTRIBUTE = `\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?`;
|
|
2686
|
-
var HTML_COMPLETE_TAG = new RegExp(`^(?:<[A-Za-z][A-Za-z0-9-]*(?:${ATTRIBUTE})*\\s*/?>|</[A-Za-z][A-Za-z0-9-]*\\s*>)\\s*$`);
|
|
2687
|
-
var HTML_BLOCK_NAME_SET = /* @__PURE__ */ new Set([
|
|
2688
|
-
// Condition 1 (raw text) and condition 6 (block) tag names — CommonMark 0.31.
|
|
2689
|
-
"script",
|
|
2690
|
-
"pre",
|
|
2691
|
-
"style",
|
|
2692
|
-
"textarea",
|
|
2693
|
-
...HTML_BLOCK_NAMES.replace("h[1-6]", "h1|h2|h3|h4|h5|h6").split("|")
|
|
2694
|
-
]);
|
|
2695
|
-
function isHtmlBlockTagName(name) {
|
|
2696
|
-
return HTML_BLOCK_NAME_SET.has(name.toLowerCase());
|
|
2697
|
-
}
|
|
2698
|
-
function startsHtmlBlock(trimmed) {
|
|
2699
|
-
if (!trimmed.startsWith("<")) return false;
|
|
2700
|
-
return HTML_RAW.test(trimmed) || HTML_COMMENT_ETC.test(trimmed) || HTML_BLOCK_TAG.test(trimmed) || HTML_COMPLETE_TAG.test(trimmed);
|
|
2701
|
-
}
|
|
2702
|
-
function lineIndent(line) {
|
|
2703
|
-
let column = 0;
|
|
2704
|
-
for (const ch of line) {
|
|
2705
|
-
if (ch === " ") column += 1;
|
|
2706
|
-
else if (ch === " ") column += 4 - column % 4;
|
|
2707
|
-
else break;
|
|
2708
|
-
}
|
|
2709
|
-
return column;
|
|
2710
|
-
}
|
|
2711
|
-
var LIST_MARKER = /^([ \t]*)([-+*]|\d{1,9}[.)])([ \t]+|$)/;
|
|
2712
|
-
function markerContentColumn(marker) {
|
|
2713
|
-
const markerEnd = lineIndent(marker[1] ?? "") + (marker[2] ?? "").length;
|
|
2714
|
-
const gap = marker[3] ? lineIndent(" ".repeat(markerEnd) + marker[3]) - markerEnd : 1;
|
|
2715
|
-
return markerEnd + (gap >= 1 && gap <= 4 ? gap : 1);
|
|
2716
|
-
}
|
|
2717
|
-
function tableContainerIndent(lines, start) {
|
|
2718
|
-
return tableContainerIndentOf(lines, start, false);
|
|
2719
|
-
}
|
|
2720
|
-
function tableContainerIndentOf(lines, start, ownItem) {
|
|
2721
|
-
const own = ownItem ? LIST_MARKER.exec(lines[start] ?? "") : null;
|
|
2722
|
-
if (own) return markerContentColumn(own);
|
|
2723
|
-
const header = lineIndent(lines[start] ?? "");
|
|
2724
|
-
if (header === 0) return 0;
|
|
2725
|
-
for (let k = start - 1; k >= 0; k -= 1) {
|
|
2726
|
-
const line = lines[k] ?? "";
|
|
2727
|
-
if (!line.trim()) continue;
|
|
2728
|
-
const indent = lineIndent(line);
|
|
2729
|
-
const marker = LIST_MARKER.exec(line);
|
|
2730
|
-
if (marker && indent < header) {
|
|
2731
|
-
const content = markerContentColumn(marker);
|
|
2732
|
-
if (content <= header) return content;
|
|
2733
|
-
continue;
|
|
2734
|
-
}
|
|
2735
|
-
if (indent === 0) return 0;
|
|
2736
|
-
}
|
|
2737
|
-
return 0;
|
|
2738
|
-
}
|
|
2739
|
-
var DELIMITER_CELL = /^:?-+:?$/;
|
|
2740
|
-
function isGfmDelimiterRow(line) {
|
|
2741
|
-
const trimmed = line.trim();
|
|
2742
|
-
if (!trimmed.includes("|")) return false;
|
|
2743
|
-
const cells = rowCells(trimmed);
|
|
2744
|
-
return cells.length > 0 && cells.every((cell) => DELIMITER_CELL.test(cell));
|
|
2745
|
-
}
|
|
2746
|
-
function isPipeLedRow(line) {
|
|
2747
|
-
const trimmed = line.trim();
|
|
2748
|
-
return trimmed.startsWith("|") && trimmed.includes("|", 1);
|
|
2749
|
-
}
|
|
2750
|
-
function isTableDelimiter(line) {
|
|
2751
|
-
if (line === void 0 || !isGfmDelimiterRow(line)) return false;
|
|
2752
|
-
return !BLOCK_START.test(line.trim());
|
|
2753
|
-
}
|
|
2754
|
-
function startsPipelessTable(header, delimiter) {
|
|
2755
|
-
const head = header.trim();
|
|
2756
|
-
if (!head || isPipeLedRow(head) || !head.startsWith("|") && startsBlock(head)) return false;
|
|
2757
|
-
if (!isTableDelimiter(delimiter)) return false;
|
|
2758
|
-
return rowCells(head).length === rowCells(delimiter.trim()).length;
|
|
2759
|
-
}
|
|
2760
|
-
function continuesTable(line, containerIndent = 0) {
|
|
2761
|
-
const trimmed = line.trim();
|
|
2762
|
-
if (!trimmed) return false;
|
|
2763
|
-
if (lineIndent(line) - containerIndent >= 4) return false;
|
|
2764
|
-
return trimmed.startsWith("|") || !startsBlock(trimmed);
|
|
2765
|
-
}
|
|
2766
|
-
function opensTable(lines, index) {
|
|
2767
|
-
const line = lines[index] ?? "";
|
|
2768
|
-
if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
|
|
2769
|
-
return !isLazyContinuation(lines, index) && !insideHtmlBlock(lines, index);
|
|
2770
|
-
}
|
|
2771
|
-
var QUOTE_LINE = /^ {0,3}>/;
|
|
2772
|
-
var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
2773
|
-
var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
2774
|
-
function htmlBlockEnd(trimmed) {
|
|
2775
|
-
if (HTML_RAW.test(trimmed)) return /<\/(?:script|pre|style|textarea)>/i;
|
|
2776
|
-
if (trimmed.startsWith("<!--")) return /-->/;
|
|
2777
|
-
if (trimmed.startsWith("<?")) return /\?>/;
|
|
2778
|
-
if (trimmed.startsWith("<![CDATA[")) return /\]\]>/;
|
|
2779
|
-
if (/^<![A-Za-z]/.test(trimmed)) return />/;
|
|
2780
|
-
if (HTML_BLOCK_TAG.test(trimmed)) return null;
|
|
2781
|
-
if (HTML_COMPLETE_TAG.test(trimmed)) return null;
|
|
2782
|
-
return void 0;
|
|
2783
|
-
}
|
|
2784
|
-
function insideHtmlBlock(lines, index) {
|
|
2785
|
-
let start = index;
|
|
2786
|
-
while (start > 0 && (lines[start - 1] ?? "").trim()) start -= 1;
|
|
2787
|
-
let open;
|
|
2788
|
-
let paragraph = false;
|
|
2789
|
-
for (let k = start; k < index; k += 1) {
|
|
2790
|
-
const line = lines[k] ?? "";
|
|
2791
|
-
if (open !== void 0) {
|
|
2792
|
-
if (open && open.test(line)) open = void 0;
|
|
2793
|
-
continue;
|
|
2794
|
-
}
|
|
2795
|
-
const trimmed = line.trim();
|
|
2796
|
-
const end = lineIndent(line) < 4 ? htmlBlockEnd(trimmed) : void 0;
|
|
2797
|
-
const type7 = end === null && !HTML_BLOCK_TAG.test(trimmed);
|
|
2798
|
-
const interrupts = end !== void 0 && !(paragraph && type7);
|
|
2799
|
-
if (!interrupts) {
|
|
2800
|
-
paragraph = true;
|
|
2801
|
-
continue;
|
|
2802
|
-
}
|
|
2803
|
-
paragraph = false;
|
|
2804
|
-
open = end && end.test(trimmed.slice(2)) ? void 0 : end;
|
|
2805
|
-
}
|
|
2806
|
-
return open !== void 0;
|
|
2807
|
-
}
|
|
2808
|
-
function isLazyContinuation(lines, index) {
|
|
2809
|
-
const header = lines[index] ?? "";
|
|
2810
|
-
let first = -1;
|
|
2811
|
-
for (let k = index - 1; k >= 0; k -= 1) {
|
|
2812
|
-
const line = lines[k] ?? "";
|
|
2813
|
-
const trimmed = line.trim();
|
|
2814
|
-
if (!trimmed) break;
|
|
2815
|
-
if (breaksParagraph(trimmed)) break;
|
|
2816
|
-
const marker = LIST_MARKER.exec(line);
|
|
2817
|
-
if (marker) {
|
|
2818
|
-
const rest = line.slice(marker[0].length).trim();
|
|
2819
|
-
if (!rest || breaksParagraph(rest)) break;
|
|
2820
|
-
first = k;
|
|
2821
|
-
break;
|
|
2822
|
-
}
|
|
2823
|
-
first = k;
|
|
2824
|
-
if (QUOTE_LINE.test(line)) break;
|
|
2825
|
-
}
|
|
2826
|
-
if (first < 0) return false;
|
|
2827
|
-
const start = lines[first] ?? "";
|
|
2828
|
-
if (QUOTE_LINE.test(start)) return !QUOTE_LINE.test(header);
|
|
2829
|
-
return lineIndent(header) < tableContainerIndentOf(lines, first, true);
|
|
2830
|
-
}
|
|
2831
|
-
function tableStartsAt(lines, index) {
|
|
2832
|
-
const header = lines[index] ?? "";
|
|
2833
|
-
const delimiter = lines[index + 1];
|
|
2834
|
-
if (!opensTable(lines, index) || !isTableDelimiter(delimiter)) return false;
|
|
2835
|
-
if (rowCells(header).length !== rowCells(delimiter).length) return false;
|
|
2836
|
-
return lineIndent(header) - tableContainerIndent(lines, index) < 4;
|
|
2837
|
-
}
|
|
2838
|
-
function findTableStart(lines, from = 0) {
|
|
2839
|
-
for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
|
|
2840
|
-
return -1;
|
|
2841
|
-
}
|
|
2842
|
-
function findTableEnd(lines, start) {
|
|
2843
|
-
const container = tableContainerIndent(lines, start);
|
|
2844
|
-
let end = Math.min(lines.length, start + 2);
|
|
2845
|
-
while (end < lines.length && continuesTable(lines[end] ?? "", container)) end += 1;
|
|
2846
|
-
return end;
|
|
2847
|
-
}
|
|
2848
|
-
|
|
2849
|
-
export { AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
|
2868
|
+
export { AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensTable, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
|
|
2850
2869
|
//# sourceMappingURL=source.js.map
|
|
2851
2870
|
//# sourceMappingURL=source.js.map
|