@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.19.18
|
|
4
|
+
### Unreleased
|
|
5
|
+
|
|
6
|
+
- `/source` **An unclosed HTML block tag owns nothing** (verify-RC-B4 round 9): a line-leading `<div>`, `<section>`, `<details>`… that never closes is no `xml_container` island running to the end of the text — GFM ends that HTML block at the blank line, so the text after it stays prose (the Visual editor showed a whole note swallowed as a "Section · div, not closed" island). The tag stays an inline `xml_tag` island; a closed container is still one island; an unclosed custom tag still owns the rest. Python twin moved; island vectors +5.
|
|
7
|
+
|
|
8
|
+
## 0.19.17
|
|
9
|
+
### Unreleased
|
|
10
|
+
|
|
11
|
+
- **Release note:** 0.19.16 was tagged but never reached npm — its tag points at a commit whose workspace lockfile (`apps/pnpm-lock.yaml`) was out of date, so every publish retry of that immutable tag fails at `pnpm install --frozen-lockfile`. The round-9 changes it carried ship in the next version.
|
|
12
|
+
|
|
13
|
+
## 0.19.16
|
|
14
|
+
|
|
15
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
16
|
+
`git diff npm/content-ir-core/v0.19.14..npm/content-ir-core/v0.19.16 -- apps/shared/content-ir-core`).
|
|
17
|
+
No source changes intended and no consumer action required.
|
|
18
|
+
|
|
3
19
|
## 0.19.15
|
|
4
20
|
|
|
5
21
|
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
@@ -39,6 +55,7 @@ No source changes intended and no consumer action required.
|
|
|
39
55
|
## 0.19.9
|
|
40
56
|
### Unreleased
|
|
41
57
|
|
|
58
|
+
- `/source` **Round 9 verifier findings (verify-RC-B4 R9-1, R9-4, R9-5):** a footnote definition (`[^1]: …`) ends a table (Python twin moved); a table never opens INSIDE an HTML block that opened above it with no blank line (`<details>` then `| a | b |` is raw HTML — types 1–5 end at their marker, 6–7 at the blank line, 7 cannot interrupt a paragraph); new THE link-reference rule — `collectLinkDefinitions(text)`, `findLinkDefinitionLines(text)`, `resolveReferenceLinks(fragment, defs)`, `normalizeLinkLabel` — so a cell or split block resolves `[Apple Support][1]` against the document's definitions, as GFM does (a definition cannot interrupt a paragraph or a row run). Vectors +2 ends, +11 starts, +1 document.
|
|
42
59
|
- `/source` **`isHtmlBlockTagName(name)`** (verify-RC-B4 round 9): the tag names CommonMark reads as an HTML BLOCK when they open a line (conditions 1 and 6: `div`, `details`, `section`, `script`, …; case-insensitive) — so a splitter can leave such a line to the markdown renderer, ending where GFM ends it, instead of opening a custom XML container that owns what follows.
|
|
43
60
|
- `/source` **A table ends where GFM ends it (verify-RC-B4 round 9):** `continuesTable` / `findTableEnd` end a table at an HTML block start (all seven CommonMark 4.6 conditions — `<script`/`<pre`/`<style`/`<textarea`, `<!--`, `<?`, `<!X`, `<![CDATA[`, a block tag name, or any other complete tag alone on its line such as `</artifact>`) and at indented code: a line 4+ columns past the table's container. New `startsHtmlBlock`, `lineIndent`, `tableContainerIndent` (the content column of the list item a table sits in); `continuesTable(line, containerIndent = 0)`. A lone `|` is a row (one empty cell) — `rowCells("|")` is `[""]`, no longer `[]`. Since 0.19.4 an HTML line or an indented line after a table was read as a table row. Shared vectors gain `tableEnds` (30 cases, each judged against remark-gfm in matrx-frontend); the Python twin moved with them.
|
|
44
61
|
- `/source` **A table never opens on a lazy continuation line (verify-RC-B4 round 9):** `opensTable` / `tableStartsAt` / `findTableStart` refuse a header that lazily continues a list item's or a block quote's paragraph (no blank line above, not indented to the item's content column, or missing the quote's `>`) — GFM reads it as paragraph text (`- item` then `| a | b |` is no table). Vectors gain `tableStarts` (15 cases, judged against remark-gfm).
|
package/dist/index.cjs
CHANGED
|
@@ -6059,6 +6059,204 @@ var XmlContainerTracker = class {
|
|
|
6059
6059
|
}
|
|
6060
6060
|
};
|
|
6061
6061
|
|
|
6062
|
+
// source/gfm-table.ts
|
|
6063
|
+
function splitRowSegments(line) {
|
|
6064
|
+
const segments = [];
|
|
6065
|
+
let start = 0;
|
|
6066
|
+
for (let i = 0; i < line.length; i += 1) {
|
|
6067
|
+
const ch = line[i];
|
|
6068
|
+
if (ch === "\\") {
|
|
6069
|
+
i += 1;
|
|
6070
|
+
continue;
|
|
6071
|
+
}
|
|
6072
|
+
if (ch === "|") {
|
|
6073
|
+
segments.push(line.slice(start, i));
|
|
6074
|
+
start = i + 1;
|
|
6075
|
+
}
|
|
6076
|
+
}
|
|
6077
|
+
segments.push(line.slice(start));
|
|
6078
|
+
return segments;
|
|
6079
|
+
}
|
|
6080
|
+
function rowCells(line) {
|
|
6081
|
+
const cells = splitRowSegments(line).map((cell) => cell.trim());
|
|
6082
|
+
if (cells.length > 1 && cells[0] === "") cells.shift();
|
|
6083
|
+
if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
|
|
6084
|
+
else if (cells.length === 1 && cells[0] === "" && !line.includes("|")) cells.pop();
|
|
6085
|
+
return cells;
|
|
6086
|
+
}
|
|
6087
|
+
function unescapeCellPipes(cell) {
|
|
6088
|
+
return cell.replace(/\\\|/g, "|");
|
|
6089
|
+
}
|
|
6090
|
+
var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$|\[\^[^\]\s]+\]:)/;
|
|
6091
|
+
var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
6092
|
+
var HTML_RAW = /^<(?:script|pre|style|textarea)(?:[\s>]|$)/i;
|
|
6093
|
+
var HTML_COMMENT_ETC = /^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[)/;
|
|
6094
|
+
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";
|
|
6095
|
+
var HTML_BLOCK_TAG = new RegExp(`^</?(?:${HTML_BLOCK_NAMES})(?:[\\s>]|/>|$)`, "i");
|
|
6096
|
+
var ATTRIBUTE = `\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?`;
|
|
6097
|
+
var HTML_COMPLETE_TAG = new RegExp(`^(?:<[A-Za-z][A-Za-z0-9-]*(?:${ATTRIBUTE})*\\s*/?>|</[A-Za-z][A-Za-z0-9-]*\\s*>)\\s*$`);
|
|
6098
|
+
var HTML_BLOCK_NAME_SET = /* @__PURE__ */ new Set([
|
|
6099
|
+
// Condition 1 (raw text) and condition 6 (block) tag names — CommonMark 0.31.
|
|
6100
|
+
"script",
|
|
6101
|
+
"pre",
|
|
6102
|
+
"style",
|
|
6103
|
+
"textarea",
|
|
6104
|
+
...HTML_BLOCK_NAMES.replace("h[1-6]", "h1|h2|h3|h4|h5|h6").split("|")
|
|
6105
|
+
]);
|
|
6106
|
+
function isHtmlBlockTagName(name) {
|
|
6107
|
+
return HTML_BLOCK_NAME_SET.has(name.toLowerCase());
|
|
6108
|
+
}
|
|
6109
|
+
function startsHtmlBlock(trimmed) {
|
|
6110
|
+
if (!trimmed.startsWith("<")) return false;
|
|
6111
|
+
return HTML_RAW.test(trimmed) || HTML_COMMENT_ETC.test(trimmed) || HTML_BLOCK_TAG.test(trimmed) || HTML_COMPLETE_TAG.test(trimmed);
|
|
6112
|
+
}
|
|
6113
|
+
function lineIndent(line) {
|
|
6114
|
+
let column = 0;
|
|
6115
|
+
for (const ch of line) {
|
|
6116
|
+
if (ch === " ") column += 1;
|
|
6117
|
+
else if (ch === " ") column += 4 - column % 4;
|
|
6118
|
+
else break;
|
|
6119
|
+
}
|
|
6120
|
+
return column;
|
|
6121
|
+
}
|
|
6122
|
+
var LIST_MARKER = /^([ \t]*)([-+*]|\d{1,9}[.)])([ \t]+|$)/;
|
|
6123
|
+
function markerContentColumn(marker) {
|
|
6124
|
+
const markerEnd = lineIndent(marker[1] ?? "") + (marker[2] ?? "").length;
|
|
6125
|
+
const gap = marker[3] ? lineIndent(" ".repeat(markerEnd) + marker[3]) - markerEnd : 1;
|
|
6126
|
+
return markerEnd + (gap >= 1 && gap <= 4 ? gap : 1);
|
|
6127
|
+
}
|
|
6128
|
+
function tableContainerIndent(lines, start) {
|
|
6129
|
+
return tableContainerIndentOf(lines, start, false);
|
|
6130
|
+
}
|
|
6131
|
+
function tableContainerIndentOf(lines, start, ownItem) {
|
|
6132
|
+
const own = ownItem ? LIST_MARKER.exec(lines[start] ?? "") : null;
|
|
6133
|
+
if (own) return markerContentColumn(own);
|
|
6134
|
+
const header = lineIndent(lines[start] ?? "");
|
|
6135
|
+
if (header === 0) return 0;
|
|
6136
|
+
for (let k = start - 1; k >= 0; k -= 1) {
|
|
6137
|
+
const line = lines[k] ?? "";
|
|
6138
|
+
if (!line.trim()) continue;
|
|
6139
|
+
const indent = lineIndent(line);
|
|
6140
|
+
const marker = LIST_MARKER.exec(line);
|
|
6141
|
+
if (marker && indent < header) {
|
|
6142
|
+
const content = markerContentColumn(marker);
|
|
6143
|
+
if (content <= header) return content;
|
|
6144
|
+
continue;
|
|
6145
|
+
}
|
|
6146
|
+
if (indent === 0) return 0;
|
|
6147
|
+
}
|
|
6148
|
+
return 0;
|
|
6149
|
+
}
|
|
6150
|
+
var DELIMITER_CELL = /^:?-+:?$/;
|
|
6151
|
+
function isGfmDelimiterRow(line) {
|
|
6152
|
+
const trimmed = line.trim();
|
|
6153
|
+
if (!trimmed.includes("|")) return false;
|
|
6154
|
+
const cells = rowCells(trimmed);
|
|
6155
|
+
return cells.length > 0 && cells.every((cell) => DELIMITER_CELL.test(cell));
|
|
6156
|
+
}
|
|
6157
|
+
function isPipeLedRow(line) {
|
|
6158
|
+
const trimmed = line.trim();
|
|
6159
|
+
return trimmed.startsWith("|") && trimmed.includes("|", 1);
|
|
6160
|
+
}
|
|
6161
|
+
function isTableDelimiter(line) {
|
|
6162
|
+
if (line === void 0 || !isGfmDelimiterRow(line)) return false;
|
|
6163
|
+
return !BLOCK_START.test(line.trim());
|
|
6164
|
+
}
|
|
6165
|
+
function startsPipelessTable(header, delimiter) {
|
|
6166
|
+
const head = header.trim();
|
|
6167
|
+
if (!head || isPipeLedRow(head) || !head.startsWith("|") && startsBlock(head)) return false;
|
|
6168
|
+
if (!isTableDelimiter(delimiter)) return false;
|
|
6169
|
+
return rowCells(head).length === rowCells(delimiter.trim()).length;
|
|
6170
|
+
}
|
|
6171
|
+
function continuesTable(line, containerIndent = 0) {
|
|
6172
|
+
const trimmed = line.trim();
|
|
6173
|
+
if (!trimmed) return false;
|
|
6174
|
+
if (lineIndent(line) - containerIndent >= 4) return false;
|
|
6175
|
+
return trimmed.startsWith("|") || !startsBlock(trimmed);
|
|
6176
|
+
}
|
|
6177
|
+
function opensTable(lines, index) {
|
|
6178
|
+
const line = lines[index] ?? "";
|
|
6179
|
+
if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
|
|
6180
|
+
return !isLazyContinuation(lines, index) && !insideHtmlBlock(lines, index);
|
|
6181
|
+
}
|
|
6182
|
+
var QUOTE_LINE = /^ {0,3}>/;
|
|
6183
|
+
var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
6184
|
+
var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
6185
|
+
function htmlBlockEnd(trimmed) {
|
|
6186
|
+
if (HTML_RAW.test(trimmed)) return /<\/(?:script|pre|style|textarea)>/i;
|
|
6187
|
+
if (trimmed.startsWith("<!--")) return /-->/;
|
|
6188
|
+
if (trimmed.startsWith("<?")) return /\?>/;
|
|
6189
|
+
if (trimmed.startsWith("<![CDATA[")) return /\]\]>/;
|
|
6190
|
+
if (/^<![A-Za-z]/.test(trimmed)) return />/;
|
|
6191
|
+
if (HTML_BLOCK_TAG.test(trimmed)) return null;
|
|
6192
|
+
if (HTML_COMPLETE_TAG.test(trimmed)) return null;
|
|
6193
|
+
return void 0;
|
|
6194
|
+
}
|
|
6195
|
+
function insideHtmlBlock(lines, index) {
|
|
6196
|
+
let start = index;
|
|
6197
|
+
while (start > 0 && (lines[start - 1] ?? "").trim()) start -= 1;
|
|
6198
|
+
let open;
|
|
6199
|
+
let paragraph = false;
|
|
6200
|
+
for (let k = start; k < index; k += 1) {
|
|
6201
|
+
const line = lines[k] ?? "";
|
|
6202
|
+
if (open !== void 0) {
|
|
6203
|
+
if (open && open.test(line)) open = void 0;
|
|
6204
|
+
continue;
|
|
6205
|
+
}
|
|
6206
|
+
const trimmed = line.trim();
|
|
6207
|
+
const end = lineIndent(line) < 4 ? htmlBlockEnd(trimmed) : void 0;
|
|
6208
|
+
const type7 = end === null && !HTML_BLOCK_TAG.test(trimmed);
|
|
6209
|
+
const interrupts = end !== void 0 && !(paragraph && type7);
|
|
6210
|
+
if (!interrupts) {
|
|
6211
|
+
paragraph = true;
|
|
6212
|
+
continue;
|
|
6213
|
+
}
|
|
6214
|
+
paragraph = false;
|
|
6215
|
+
open = end && end.test(trimmed.slice(2)) ? void 0 : end;
|
|
6216
|
+
}
|
|
6217
|
+
return open !== void 0;
|
|
6218
|
+
}
|
|
6219
|
+
function isLazyContinuation(lines, index) {
|
|
6220
|
+
const header = lines[index] ?? "";
|
|
6221
|
+
let first = -1;
|
|
6222
|
+
for (let k = index - 1; k >= 0; k -= 1) {
|
|
6223
|
+
const line = lines[k] ?? "";
|
|
6224
|
+
const trimmed = line.trim();
|
|
6225
|
+
if (!trimmed) break;
|
|
6226
|
+
if (breaksParagraph(trimmed)) break;
|
|
6227
|
+
const marker = LIST_MARKER.exec(line);
|
|
6228
|
+
if (marker) {
|
|
6229
|
+
const rest = line.slice(marker[0].length).trim();
|
|
6230
|
+
if (!rest || breaksParagraph(rest)) break;
|
|
6231
|
+
first = k;
|
|
6232
|
+
break;
|
|
6233
|
+
}
|
|
6234
|
+
first = k;
|
|
6235
|
+
if (QUOTE_LINE.test(line)) break;
|
|
6236
|
+
}
|
|
6237
|
+
if (first < 0) return false;
|
|
6238
|
+
const start = lines[first] ?? "";
|
|
6239
|
+
if (QUOTE_LINE.test(start)) return !QUOTE_LINE.test(header);
|
|
6240
|
+
return lineIndent(header) < tableContainerIndentOf(lines, first, true);
|
|
6241
|
+
}
|
|
6242
|
+
function tableStartsAt(lines, index) {
|
|
6243
|
+
const header = lines[index] ?? "";
|
|
6244
|
+
const delimiter = lines[index + 1];
|
|
6245
|
+
if (!opensTable(lines, index) || !isTableDelimiter(delimiter)) return false;
|
|
6246
|
+
if (rowCells(header).length !== rowCells(delimiter).length) return false;
|
|
6247
|
+
return lineIndent(header) - tableContainerIndent(lines, index) < 4;
|
|
6248
|
+
}
|
|
6249
|
+
function findTableStart(lines, from = 0) {
|
|
6250
|
+
for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
|
|
6251
|
+
return -1;
|
|
6252
|
+
}
|
|
6253
|
+
function findTableEnd(lines, start) {
|
|
6254
|
+
const container = tableContainerIndent(lines, start);
|
|
6255
|
+
let end = Math.min(lines.length, start + 2);
|
|
6256
|
+
while (end < lines.length && continuesTable(lines[end] ?? "", container)) end += 1;
|
|
6257
|
+
return end;
|
|
6258
|
+
}
|
|
6259
|
+
|
|
6062
6260
|
// source/tokenize.ts
|
|
6063
6261
|
var NOT_WHITESPACE = /\S/;
|
|
6064
6262
|
var DIRECTIVE_OPEN = /^(:{2,})([A-Za-z][\w-]*)/;
|
|
@@ -6900,9 +7098,12 @@ var Tokenizer = class {
|
|
|
6900
7098
|
});
|
|
6901
7099
|
}
|
|
6902
7100
|
}
|
|
7101
|
+
if (isHtmlBlockTagName(root)) return null;
|
|
6903
7102
|
return this.island("xml_container", p, this.n, false, { tag: root });
|
|
6904
7103
|
}
|
|
6905
7104
|
if (isUnclosedGenericXmlOpening(seg)) {
|
|
7105
|
+
const name = /^\s*<([A-Za-z_][\w.:-]*)/.exec(seg)?.[1] ?? "";
|
|
7106
|
+
if (isHtmlBlockTagName(name)) return null;
|
|
6906
7107
|
return this.island("xml_container", p, this.n, false, {});
|
|
6907
7108
|
}
|
|
6908
7109
|
return null;
|
|
@@ -7672,20 +7873,36 @@ function normalizeLinkLabel(label) {
|
|
|
7672
7873
|
var DEFINITION = /^ {0,3}\[((?:[^\]\\]|\\.){1,999})\]:[ \t]*(?:<([^<>\n]*)>|(\S+))(?:[ \t]+(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|\(((?:[^()\\]|\\.)*)\)))?[ \t]*$/;
|
|
7673
7874
|
function collectLinkDefinitions(text) {
|
|
7674
7875
|
const defs = /* @__PURE__ */ new Map();
|
|
7675
|
-
|
|
7876
|
+
for (const { label, definition } of scanLinkDefinitions(text)) {
|
|
7877
|
+
const key = normalizeLinkLabel(label);
|
|
7878
|
+
if (key && !defs.has(key)) defs.set(key, definition);
|
|
7879
|
+
}
|
|
7880
|
+
return defs;
|
|
7881
|
+
}
|
|
7882
|
+
function findLinkDefinitionLines(text) {
|
|
7883
|
+
return scanLinkDefinitions(text).map(({ line }) => line);
|
|
7884
|
+
}
|
|
7885
|
+
function scanLinkDefinitions(text) {
|
|
7886
|
+
const found = [];
|
|
7887
|
+
if (!text.includes("]:")) return found;
|
|
7676
7888
|
const lines = text.split("\n");
|
|
7677
7889
|
const kinds = fenceLineKinds(text);
|
|
7890
|
+
let previousWasDefinition = false;
|
|
7678
7891
|
lines.forEach((line, i) => {
|
|
7892
|
+
const wasDefinition = previousWasDefinition;
|
|
7893
|
+
previousWasDefinition = false;
|
|
7679
7894
|
if (kinds[i] !== "prose") return;
|
|
7680
7895
|
const m = DEFINITION.exec(line);
|
|
7681
7896
|
if (!m) return;
|
|
7897
|
+
const above = i > 0 ? lines[i - 1] ?? "" : "";
|
|
7898
|
+
const opensBlock = i === 0 || !above.trim() || wasDefinition || kinds[i - 1] === "close" || /^ {0,3}(?:#{1,6}(?:\s|$)|(?:[-*_][ \t]*){3,}$)/.test(above);
|
|
7899
|
+
if (!opensBlock) return;
|
|
7682
7900
|
const label = m[1] ?? "";
|
|
7683
7901
|
if (label.startsWith("^")) return;
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
defs.set(key, { url: m[2] ?? m[3] ?? "", title: m[4] ?? m[5] ?? m[6] ?? null });
|
|
7902
|
+
previousWasDefinition = true;
|
|
7903
|
+
found.push({ line: i, label, definition: { url: m[2] ?? m[3] ?? "", title: m[4] ?? m[5] ?? m[6] ?? null } });
|
|
7687
7904
|
});
|
|
7688
|
-
return
|
|
7905
|
+
return found;
|
|
7689
7906
|
}
|
|
7690
7907
|
var REFERENCE = /(!?)\[((?:[^\]\\]|\\.)*)\](?:\[((?:[^\]\\]|\\.)*)\])?(?![(:[])/g;
|
|
7691
7908
|
var escapeTitle = (title) => title.replace(/["\\]/g, "\\$&");
|
|
@@ -7710,204 +7927,6 @@ function resolveReferenceLinks(fragment, defs) {
|
|
|
7710
7927
|
return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
|
|
7711
7928
|
}
|
|
7712
7929
|
|
|
7713
|
-
// source/gfm-table.ts
|
|
7714
|
-
function splitRowSegments(line) {
|
|
7715
|
-
const segments = [];
|
|
7716
|
-
let start = 0;
|
|
7717
|
-
for (let i = 0; i < line.length; i += 1) {
|
|
7718
|
-
const ch = line[i];
|
|
7719
|
-
if (ch === "\\") {
|
|
7720
|
-
i += 1;
|
|
7721
|
-
continue;
|
|
7722
|
-
}
|
|
7723
|
-
if (ch === "|") {
|
|
7724
|
-
segments.push(line.slice(start, i));
|
|
7725
|
-
start = i + 1;
|
|
7726
|
-
}
|
|
7727
|
-
}
|
|
7728
|
-
segments.push(line.slice(start));
|
|
7729
|
-
return segments;
|
|
7730
|
-
}
|
|
7731
|
-
function rowCells(line) {
|
|
7732
|
-
const cells = splitRowSegments(line).map((cell) => cell.trim());
|
|
7733
|
-
if (cells.length > 1 && cells[0] === "") cells.shift();
|
|
7734
|
-
if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
|
|
7735
|
-
else if (cells.length === 1 && cells[0] === "" && !line.includes("|")) cells.pop();
|
|
7736
|
-
return cells;
|
|
7737
|
-
}
|
|
7738
|
-
function unescapeCellPipes(cell) {
|
|
7739
|
-
return cell.replace(/\\\|/g, "|");
|
|
7740
|
-
}
|
|
7741
|
-
var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$|\[\^[^\]\s]+\]:)/;
|
|
7742
|
-
var startsBlock = (trimmed) => BLOCK_START.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
7743
|
-
var HTML_RAW = /^<(?:script|pre|style|textarea)(?:[\s>]|$)/i;
|
|
7744
|
-
var HTML_COMMENT_ETC = /^(?:<!--|<\?|<![A-Za-z]|<!\[CDATA\[)/;
|
|
7745
|
-
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";
|
|
7746
|
-
var HTML_BLOCK_TAG = new RegExp(`^</?(?:${HTML_BLOCK_NAMES})(?:[\\s>]|/>|$)`, "i");
|
|
7747
|
-
var ATTRIBUTE = `\\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\\s*=\\s*(?:[^\\s"'=<>\`]+|'[^']*'|"[^"]*"))?`;
|
|
7748
|
-
var HTML_COMPLETE_TAG = new RegExp(`^(?:<[A-Za-z][A-Za-z0-9-]*(?:${ATTRIBUTE})*\\s*/?>|</[A-Za-z][A-Za-z0-9-]*\\s*>)\\s*$`);
|
|
7749
|
-
var HTML_BLOCK_NAME_SET = /* @__PURE__ */ new Set([
|
|
7750
|
-
// Condition 1 (raw text) and condition 6 (block) tag names — CommonMark 0.31.
|
|
7751
|
-
"script",
|
|
7752
|
-
"pre",
|
|
7753
|
-
"style",
|
|
7754
|
-
"textarea",
|
|
7755
|
-
...HTML_BLOCK_NAMES.replace("h[1-6]", "h1|h2|h3|h4|h5|h6").split("|")
|
|
7756
|
-
]);
|
|
7757
|
-
function isHtmlBlockTagName(name) {
|
|
7758
|
-
return HTML_BLOCK_NAME_SET.has(name.toLowerCase());
|
|
7759
|
-
}
|
|
7760
|
-
function startsHtmlBlock(trimmed) {
|
|
7761
|
-
if (!trimmed.startsWith("<")) return false;
|
|
7762
|
-
return HTML_RAW.test(trimmed) || HTML_COMMENT_ETC.test(trimmed) || HTML_BLOCK_TAG.test(trimmed) || HTML_COMPLETE_TAG.test(trimmed);
|
|
7763
|
-
}
|
|
7764
|
-
function lineIndent(line) {
|
|
7765
|
-
let column = 0;
|
|
7766
|
-
for (const ch of line) {
|
|
7767
|
-
if (ch === " ") column += 1;
|
|
7768
|
-
else if (ch === " ") column += 4 - column % 4;
|
|
7769
|
-
else break;
|
|
7770
|
-
}
|
|
7771
|
-
return column;
|
|
7772
|
-
}
|
|
7773
|
-
var LIST_MARKER = /^([ \t]*)([-+*]|\d{1,9}[.)])([ \t]+|$)/;
|
|
7774
|
-
function markerContentColumn(marker) {
|
|
7775
|
-
const markerEnd = lineIndent(marker[1] ?? "") + (marker[2] ?? "").length;
|
|
7776
|
-
const gap = marker[3] ? lineIndent(" ".repeat(markerEnd) + marker[3]) - markerEnd : 1;
|
|
7777
|
-
return markerEnd + (gap >= 1 && gap <= 4 ? gap : 1);
|
|
7778
|
-
}
|
|
7779
|
-
function tableContainerIndent(lines, start) {
|
|
7780
|
-
return tableContainerIndentOf(lines, start, false);
|
|
7781
|
-
}
|
|
7782
|
-
function tableContainerIndentOf(lines, start, ownItem) {
|
|
7783
|
-
const own = ownItem ? LIST_MARKER.exec(lines[start] ?? "") : null;
|
|
7784
|
-
if (own) return markerContentColumn(own);
|
|
7785
|
-
const header = lineIndent(lines[start] ?? "");
|
|
7786
|
-
if (header === 0) return 0;
|
|
7787
|
-
for (let k = start - 1; k >= 0; k -= 1) {
|
|
7788
|
-
const line = lines[k] ?? "";
|
|
7789
|
-
if (!line.trim()) continue;
|
|
7790
|
-
const indent = lineIndent(line);
|
|
7791
|
-
const marker = LIST_MARKER.exec(line);
|
|
7792
|
-
if (marker && indent < header) {
|
|
7793
|
-
const content = markerContentColumn(marker);
|
|
7794
|
-
if (content <= header) return content;
|
|
7795
|
-
continue;
|
|
7796
|
-
}
|
|
7797
|
-
if (indent === 0) return 0;
|
|
7798
|
-
}
|
|
7799
|
-
return 0;
|
|
7800
|
-
}
|
|
7801
|
-
var DELIMITER_CELL = /^:?-+:?$/;
|
|
7802
|
-
function isGfmDelimiterRow(line) {
|
|
7803
|
-
const trimmed = line.trim();
|
|
7804
|
-
if (!trimmed.includes("|")) return false;
|
|
7805
|
-
const cells = rowCells(trimmed);
|
|
7806
|
-
return cells.length > 0 && cells.every((cell) => DELIMITER_CELL.test(cell));
|
|
7807
|
-
}
|
|
7808
|
-
function isPipeLedRow(line) {
|
|
7809
|
-
const trimmed = line.trim();
|
|
7810
|
-
return trimmed.startsWith("|") && trimmed.includes("|", 1);
|
|
7811
|
-
}
|
|
7812
|
-
function isTableDelimiter(line) {
|
|
7813
|
-
if (line === void 0 || !isGfmDelimiterRow(line)) return false;
|
|
7814
|
-
return !BLOCK_START.test(line.trim());
|
|
7815
|
-
}
|
|
7816
|
-
function startsPipelessTable(header, delimiter) {
|
|
7817
|
-
const head = header.trim();
|
|
7818
|
-
if (!head || isPipeLedRow(head) || !head.startsWith("|") && startsBlock(head)) return false;
|
|
7819
|
-
if (!isTableDelimiter(delimiter)) return false;
|
|
7820
|
-
return rowCells(head).length === rowCells(delimiter.trim()).length;
|
|
7821
|
-
}
|
|
7822
|
-
function continuesTable(line, containerIndent = 0) {
|
|
7823
|
-
const trimmed = line.trim();
|
|
7824
|
-
if (!trimmed) return false;
|
|
7825
|
-
if (lineIndent(line) - containerIndent >= 4) return false;
|
|
7826
|
-
return trimmed.startsWith("|") || !startsBlock(trimmed);
|
|
7827
|
-
}
|
|
7828
|
-
function opensTable(lines, index) {
|
|
7829
|
-
const line = lines[index] ?? "";
|
|
7830
|
-
if (!isPipeLedRow(line) && !startsPipelessTable(line, lines[index + 1])) return false;
|
|
7831
|
-
return !isLazyContinuation(lines, index) && !insideHtmlBlock(lines, index);
|
|
7832
|
-
}
|
|
7833
|
-
var QUOTE_LINE = /^ {0,3}>/;
|
|
7834
|
-
var THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
7835
|
-
var breaksParagraph = (trimmed) => /^#{1,6}(?:\s|$)/.test(trimmed) || THEMATIC_BREAK.test(trimmed) || opensStrictFence(trimmed) || startsHtmlBlock(trimmed);
|
|
7836
|
-
function htmlBlockEnd(trimmed) {
|
|
7837
|
-
if (HTML_RAW.test(trimmed)) return /<\/(?:script|pre|style|textarea)>/i;
|
|
7838
|
-
if (trimmed.startsWith("<!--")) return /-->/;
|
|
7839
|
-
if (trimmed.startsWith("<?")) return /\?>/;
|
|
7840
|
-
if (trimmed.startsWith("<![CDATA[")) return /\]\]>/;
|
|
7841
|
-
if (/^<![A-Za-z]/.test(trimmed)) return />/;
|
|
7842
|
-
if (HTML_BLOCK_TAG.test(trimmed)) return null;
|
|
7843
|
-
if (HTML_COMPLETE_TAG.test(trimmed)) return null;
|
|
7844
|
-
return void 0;
|
|
7845
|
-
}
|
|
7846
|
-
function insideHtmlBlock(lines, index) {
|
|
7847
|
-
let start = index;
|
|
7848
|
-
while (start > 0 && (lines[start - 1] ?? "").trim()) start -= 1;
|
|
7849
|
-
let open;
|
|
7850
|
-
let paragraph = false;
|
|
7851
|
-
for (let k = start; k < index; k += 1) {
|
|
7852
|
-
const line = lines[k] ?? "";
|
|
7853
|
-
if (open !== void 0) {
|
|
7854
|
-
if (open && open.test(line)) open = void 0;
|
|
7855
|
-
continue;
|
|
7856
|
-
}
|
|
7857
|
-
const trimmed = line.trim();
|
|
7858
|
-
const end = lineIndent(line) < 4 ? htmlBlockEnd(trimmed) : void 0;
|
|
7859
|
-
const type7 = end === null && !HTML_BLOCK_TAG.test(trimmed);
|
|
7860
|
-
const interrupts = end !== void 0 && !(paragraph && type7);
|
|
7861
|
-
if (!interrupts) {
|
|
7862
|
-
paragraph = true;
|
|
7863
|
-
continue;
|
|
7864
|
-
}
|
|
7865
|
-
paragraph = false;
|
|
7866
|
-
open = end && end.test(trimmed.slice(2)) ? void 0 : end;
|
|
7867
|
-
}
|
|
7868
|
-
return open !== void 0;
|
|
7869
|
-
}
|
|
7870
|
-
function isLazyContinuation(lines, index) {
|
|
7871
|
-
const header = lines[index] ?? "";
|
|
7872
|
-
let first = -1;
|
|
7873
|
-
for (let k = index - 1; k >= 0; k -= 1) {
|
|
7874
|
-
const line = lines[k] ?? "";
|
|
7875
|
-
const trimmed = line.trim();
|
|
7876
|
-
if (!trimmed) break;
|
|
7877
|
-
if (breaksParagraph(trimmed)) break;
|
|
7878
|
-
const marker = LIST_MARKER.exec(line);
|
|
7879
|
-
if (marker) {
|
|
7880
|
-
const rest = line.slice(marker[0].length).trim();
|
|
7881
|
-
if (!rest || breaksParagraph(rest)) break;
|
|
7882
|
-
first = k;
|
|
7883
|
-
break;
|
|
7884
|
-
}
|
|
7885
|
-
first = k;
|
|
7886
|
-
if (QUOTE_LINE.test(line)) break;
|
|
7887
|
-
}
|
|
7888
|
-
if (first < 0) return false;
|
|
7889
|
-
const start = lines[first] ?? "";
|
|
7890
|
-
if (QUOTE_LINE.test(start)) return !QUOTE_LINE.test(header);
|
|
7891
|
-
return lineIndent(header) < tableContainerIndentOf(lines, first, true);
|
|
7892
|
-
}
|
|
7893
|
-
function tableStartsAt(lines, index) {
|
|
7894
|
-
const header = lines[index] ?? "";
|
|
7895
|
-
const delimiter = lines[index + 1];
|
|
7896
|
-
if (!opensTable(lines, index) || !isTableDelimiter(delimiter)) return false;
|
|
7897
|
-
if (rowCells(header).length !== rowCells(delimiter).length) return false;
|
|
7898
|
-
return lineIndent(header) - tableContainerIndent(lines, index) < 4;
|
|
7899
|
-
}
|
|
7900
|
-
function findTableStart(lines, from = 0) {
|
|
7901
|
-
for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
|
|
7902
|
-
return -1;
|
|
7903
|
-
}
|
|
7904
|
-
function findTableEnd(lines, start) {
|
|
7905
|
-
const container = tableContainerIndent(lines, start);
|
|
7906
|
-
let end = Math.min(lines.length, start + 2);
|
|
7907
|
-
while (end < lines.length && continuesTable(lines[end] ?? "", container)) end += 1;
|
|
7908
|
-
return end;
|
|
7909
|
-
}
|
|
7910
|
-
|
|
7911
7930
|
exports.ACTION_BY_CLASS = ACTION_BY_CLASS;
|
|
7912
7931
|
exports.AFTER_WINDOW = AFTER_WINDOW;
|
|
7913
7932
|
exports.BacktickRuns = BacktickRuns;
|
|
@@ -7984,6 +8003,7 @@ exports.fenceParts = fenceParts;
|
|
|
7984
8003
|
exports.fieldsToDbPayload = fieldsToDbPayload;
|
|
7985
8004
|
exports.findCodeRanges = findCodeRanges;
|
|
7986
8005
|
exports.findInlineCodeSpans = findInlineCodeSpans;
|
|
8006
|
+
exports.findLinkDefinitionLines = findLinkDefinitionLines;
|
|
7987
8007
|
exports.findTableEnd = findTableEnd;
|
|
7988
8008
|
exports.findTableStart = findTableStart;
|
|
7989
8009
|
exports.fingerprintText = fingerprintText;
|