@ai-matrx/content-ir 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/index.cjs +442 -0
- 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 +419 -1
- package/dist/index.js.map +1 -1
- package/dist/source.cjs +442 -0
- package/dist/source.cjs.map +1 -1
- package/dist/source.d.cts +157 -1
- package/dist/source.d.ts +157 -1
- package/dist/source.js +419 -1
- package/dist/source.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.21.0
|
|
4
|
+
|
|
5
|
+
### `/source`: the markdown text helpers move in from matrx-frontend (chat-package-move P14)
|
|
6
|
+
|
|
7
|
+
- New on `@ai-matrx/content-ir/source`, unchanged in behavior: `unwrapCodeSpans`, `removeCodeSpans`,
|
|
8
|
+
`replaceFences`, `soleFence`; `markdownToPlainText`, `mathToReadable`, `unwrapKindEnvelopes`; `cleanMarkdown`;
|
|
9
|
+
`FENCE_META_KEY`, `splitFenceInfo`, `parseFenceMeta`, `parseLineRanges` (+ `FenceInfo`, `FenceMeta`);
|
|
10
|
+
`DIRECTIVE_CONTAINER_OPEN`, `DirectiveContainerTracker`; `TITLED_IMAGE_LINE`; `isInsideInlineCode`,
|
|
11
|
+
`indexOutsideInlineCode`, `hasUnclosedBacktickRun`; `initialXmlBalance`, `findBalancedXmlClose`
|
|
12
|
+
(+ `XmlBalanceState`, `XmlBalanceOptions`); `findWholeTableStart`, `startsLikeTableRow`,
|
|
13
|
+
`isGrowingDelimiterRow`, `trailingTableStart`.
|
|
14
|
+
- `splitFenceInfo` omits `language` / `meta` when empty instead of setting them to `undefined`.
|
|
15
|
+
|
|
16
|
+
### Consumer action
|
|
17
|
+
|
|
18
|
+
- matrx-frontend: import these from `@ai-matrx/content-ir/source` (the app's old modules re-export or are gone).
|
|
19
|
+
|
|
3
20
|
## 0.20.1
|
|
4
21
|
|
|
5
22
|
### `humanizeIdentifier`: already-human text, plurals, null
|
package/dist/index.cjs
CHANGED
|
@@ -8087,6 +8087,424 @@ function resolveReferenceLinks(fragment, defs) {
|
|
|
8087
8087
|
return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
|
|
8088
8088
|
}
|
|
8089
8089
|
|
|
8090
|
+
// source/code-range-edits.ts
|
|
8091
|
+
function unwrapCodeSpans(text) {
|
|
8092
|
+
if (!text.includes("`")) return text;
|
|
8093
|
+
return mapCodeRanges(text, (range, raw) => range.kind === "span" ? codeSpanText(raw) : raw);
|
|
8094
|
+
}
|
|
8095
|
+
function removeCodeSpans(text) {
|
|
8096
|
+
if (!text.includes("`")) return text;
|
|
8097
|
+
return mapCodeRanges(text, (range, raw) => range.kind === "span" ? "" : raw);
|
|
8098
|
+
}
|
|
8099
|
+
function replaceFences(text, fn) {
|
|
8100
|
+
if (!text.includes("```") && !text.includes("~~~")) return text;
|
|
8101
|
+
return mapCodeRanges(text, (range, raw) => {
|
|
8102
|
+
if (range.kind !== "fence") return raw;
|
|
8103
|
+
const parts = fenceParts(raw);
|
|
8104
|
+
return fn({ lang: parts?.opener.lang ?? "", body: parts?.body ?? raw, closed: parts?.closed ?? false, raw });
|
|
8105
|
+
});
|
|
8106
|
+
}
|
|
8107
|
+
function soleFence(text, options = {}) {
|
|
8108
|
+
const trimmed = text.trim();
|
|
8109
|
+
if (!trimmed.startsWith("`") && !trimmed.startsWith("~")) return null;
|
|
8110
|
+
const ranges = findCodeRanges(trimmed);
|
|
8111
|
+
const only = ranges.length === 1 ? ranges[0] : void 0;
|
|
8112
|
+
if (!only || only.kind !== "fence" || only.start !== 0 || only.end !== trimmed.length) return null;
|
|
8113
|
+
const parts = fenceParts(trimmed);
|
|
8114
|
+
if (!parts || !parts.closed && !options.allowUnclosed) return null;
|
|
8115
|
+
return { lang: parts.opener.lang, body: parts.body, closed: parts.closed };
|
|
8116
|
+
}
|
|
8117
|
+
|
|
8118
|
+
// source/plain-text.ts
|
|
8119
|
+
var INLINE_PATTERNS = [
|
|
8120
|
+
// [label](href) → label. Runs first so emphasis inside a label still unwraps.
|
|
8121
|
+
[/\[([^\]]+)\]\([^)]*\)/g, "$1"],
|
|
8122
|
+
[/\*\*\*(?=\S)([\s\S]*?\S)\*\*\*/g, "$1"],
|
|
8123
|
+
[/___(?=\S)([\s\S]*?\S)___/g, "$1"],
|
|
8124
|
+
[/\*\*(?=\S)([\s\S]*?\S)\*\*/g, "$1"],
|
|
8125
|
+
[/__(?=\S)([\s\S]*?\S)__/g, "$1"],
|
|
8126
|
+
[/~~(?=\S)([\s\S]*?\S)~~/g, "$1"],
|
|
8127
|
+
[/\*(?=\S)([^*\n]*?\S)\*/g, "$1"],
|
|
8128
|
+
// Underscore italics only between word boundaries: snake_case_names are not
|
|
8129
|
+
// emphasis, and mangling an identifier is a worse defect than a stray marker.
|
|
8130
|
+
[/(^|[\s(])_(?=\S)([^_\n]*?\S)_(?=[\s).,;:!?]|$)/g, "$1$2"]
|
|
8131
|
+
];
|
|
8132
|
+
var MATH_STRUCTURAL = [
|
|
8133
|
+
[/\\(?:d|t)?frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g, "$1/$2"],
|
|
8134
|
+
[/\\sqrt\s*\{([^{}]*)\}/g, "\u221A($1)"]
|
|
8135
|
+
];
|
|
8136
|
+
var MATH_PATTERNS = [
|
|
8137
|
+
// Environments (\begin{aligned} … \end{aligned}) carry no meaning in a
|
|
8138
|
+
// one-line preview; drop the wrapper, keep the contents. Without this the
|
|
8139
|
+
// catch-all below turned them into the word "aligned" twice.
|
|
8140
|
+
[/\\(?:begin|end)\s*\{[^{}]*\}/g, " "],
|
|
8141
|
+
// A TeX line break inside a preview is just a space.
|
|
8142
|
+
[/\\\\/g, " "],
|
|
8143
|
+
// TeX spacing commands (\, \; \: thin/medium space, \! negative space).
|
|
8144
|
+
[/\\[,;:]/g, " "],
|
|
8145
|
+
[/\\!/g, ""],
|
|
8146
|
+
// \left\{ … \right\} — the escaped-brace forms, which the character-class
|
|
8147
|
+
// rule below cannot reach because the brace is preceded by a backslash.
|
|
8148
|
+
[/\\(?:left|right)\s*\\?([([\]|){}])/g, "$1"],
|
|
8149
|
+
// NOTE: every command below ends with (?![a-zA-Z]) and NOT \b. `_` is a WORD
|
|
8150
|
+
// character, so \b fails after `\sum_` — which silently left every
|
|
8151
|
+
// summation, integral and limit card reading as "sum_" / "int_".
|
|
8152
|
+
[/\\times(?![a-zA-Z])/g, "\xD7"],
|
|
8153
|
+
[/\\div(?![a-zA-Z])/g, "\xF7"],
|
|
8154
|
+
[/\\pm(?![a-zA-Z])/g, "\xB1"],
|
|
8155
|
+
[/\\cdot(?![a-zA-Z])/g, "\xB7"],
|
|
8156
|
+
[/\\leq(?![a-zA-Z])/g, "\u2264"],
|
|
8157
|
+
[/\\geq(?![a-zA-Z])/g, "\u2265"],
|
|
8158
|
+
[/\\neq(?![a-zA-Z])/g, "\u2260"],
|
|
8159
|
+
[/\\approx(?![a-zA-Z])/g, "\u2248"],
|
|
8160
|
+
[/\\infty(?![a-zA-Z])/g, "\u221E"],
|
|
8161
|
+
[/\\pi(?![a-zA-Z])/g, "\u03C0"],
|
|
8162
|
+
[/\\theta(?![a-zA-Z])/g, "\u03B8"],
|
|
8163
|
+
[/\\alpha(?![a-zA-Z])/g, "\u03B1"],
|
|
8164
|
+
[/\\beta(?![a-zA-Z])/g, "\u03B2"],
|
|
8165
|
+
[/\\Delta(?![a-zA-Z])/g, "\u0394"],
|
|
8166
|
+
[/\\delta(?![a-zA-Z])/g, "\u03B4"],
|
|
8167
|
+
[/\\sum(?![a-zA-Z])/g, "\u03A3"],
|
|
8168
|
+
[/\\prod(?![a-zA-Z])/g, "\u220F"],
|
|
8169
|
+
[/\\int(?![a-zA-Z])/g, "\u222B"],
|
|
8170
|
+
[/\\lim(?![a-zA-Z])/g, "lim"],
|
|
8171
|
+
[/\\(?:rightarrow|to)(?![a-zA-Z])/g, "\u2192"],
|
|
8172
|
+
// Braces that only ever grouped a script or argument: ^{2} → ^2, _{i} → _i.
|
|
8173
|
+
[/([_^])\s*\{([^{}]*)\}/g, "$1$2"],
|
|
8174
|
+
// Any remaining single-argument command: \text{x} / \mathrm{x} → x.
|
|
8175
|
+
[/\\[a-zA-Z]+\s*\{([^{}]*)\}/g, "$1"],
|
|
8176
|
+
// Bare commands we did not translate: drop the backslash, keep the word.
|
|
8177
|
+
[/\\([a-zA-Z]+)/g, "$1"]
|
|
8178
|
+
];
|
|
8179
|
+
var MATH_REGIONS = [
|
|
8180
|
+
/\\\[([\s\S]*?)\\\]/g,
|
|
8181
|
+
/\\\(([\s\S]*?)\\\)/g,
|
|
8182
|
+
/\$\$([\s\S]*?)\$\$/g
|
|
8183
|
+
];
|
|
8184
|
+
function mathToReadable(expression) {
|
|
8185
|
+
let text = expression;
|
|
8186
|
+
for (let pass = 0; pass < 8; pass += 1) {
|
|
8187
|
+
const before = text;
|
|
8188
|
+
for (const [pattern, replacement] of MATH_STRUCTURAL) {
|
|
8189
|
+
text = text.replace(pattern, replacement);
|
|
8190
|
+
}
|
|
8191
|
+
if (text === before) break;
|
|
8192
|
+
}
|
|
8193
|
+
for (const [pattern, replacement] of MATH_PATTERNS) {
|
|
8194
|
+
text = text.replace(pattern, replacement);
|
|
8195
|
+
}
|
|
8196
|
+
return text.trim();
|
|
8197
|
+
}
|
|
8198
|
+
function markdownToPlainText(value) {
|
|
8199
|
+
if (!value) return "";
|
|
8200
|
+
const mathChunks = [];
|
|
8201
|
+
let text = value;
|
|
8202
|
+
for (const region of MATH_REGIONS) {
|
|
8203
|
+
text = text.replace(region, (_match, inner) => {
|
|
8204
|
+
mathChunks.push(mathToReadable(inner));
|
|
8205
|
+
return `\uE000MATH${mathChunks.length - 1}\uE001`;
|
|
8206
|
+
});
|
|
8207
|
+
}
|
|
8208
|
+
for (const [pattern, replacement] of INLINE_PATTERNS) {
|
|
8209
|
+
text = text.replace(pattern, replacement);
|
|
8210
|
+
}
|
|
8211
|
+
text = unwrapCodeSpans(text);
|
|
8212
|
+
text = text.replace(
|
|
8213
|
+
/\uE000MATH(\d+)\uE001/g,
|
|
8214
|
+
(_m, index) => mathChunks[Number(index)] ?? ""
|
|
8215
|
+
);
|
|
8216
|
+
return text.replace(/[ \t]{2,}/g, " ").trim();
|
|
8217
|
+
}
|
|
8218
|
+
function unwrapKindEnvelopes(value) {
|
|
8219
|
+
if (!value) return "";
|
|
8220
|
+
if (!value.includes("<artifact")) return value;
|
|
8221
|
+
return tokenizeSource(value).map((block) => {
|
|
8222
|
+
if (block.kind !== "island" || block.islandType !== "xml_attr" && block.islandType !== "xml_container") {
|
|
8223
|
+
return block.raw;
|
|
8224
|
+
}
|
|
8225
|
+
const match = /^\s*<artifact\b[^>]*>([\s\S]*?)<\/artifact>\s*$/.exec(block.raw);
|
|
8226
|
+
return match ? (match[1] ?? "").replace(/^\n/, "").replace(/\n$/, "") : block.raw;
|
|
8227
|
+
}).join("");
|
|
8228
|
+
}
|
|
8229
|
+
|
|
8230
|
+
// source/clean-markdown.ts
|
|
8231
|
+
var cleanMarkdown = (text) => {
|
|
8232
|
+
if (!text || typeof text !== "string") return "";
|
|
8233
|
+
let cleanedText = text;
|
|
8234
|
+
const lines = cleanedText.split("\n");
|
|
8235
|
+
const processedLines = [];
|
|
8236
|
+
for (let line of lines) {
|
|
8237
|
+
let processedLine = line;
|
|
8238
|
+
if (processedLine.trim() === "") {
|
|
8239
|
+
processedLines.push(processedLine);
|
|
8240
|
+
continue;
|
|
8241
|
+
}
|
|
8242
|
+
processedLine = processedLine.replace(/^#{1,6}\s+(.+)$/, "$1");
|
|
8243
|
+
processedLine = processedLine.replace(/(\*\*|__)(.*?)\1/, "$2");
|
|
8244
|
+
processedLine = processedLine.replace(/(\*|_)(.*?)\1/, "$2");
|
|
8245
|
+
processedLine = unwrapCodeSpans(processedLine);
|
|
8246
|
+
processedLine = processedLine.replace(/\[([^\]]+)\]\(([^)]+)\)/, "$1");
|
|
8247
|
+
processedLine = processedLine.replace(/!\[([^\]]*)\]\(([^)]+)\)/, "$1");
|
|
8248
|
+
processedLine = processedLine.replace(/^>\s*(.+)$/, "$1");
|
|
8249
|
+
processedLine = processedLine.replace(/^(\*{3,}|-{3,}|_{3,})$/, "");
|
|
8250
|
+
processedLine = processedLine.replace(/^(\s*[-+*]\s+|\s*\d+\.\s+)(.+)$/, "$2");
|
|
8251
|
+
processedLine = processedLine.replace(/<\/?[^>]+(>|$)/g, "");
|
|
8252
|
+
processedLines.push(processedLine);
|
|
8253
|
+
}
|
|
8254
|
+
cleanedText = processedLines.join("\n");
|
|
8255
|
+
cleanedText = replaceFences(cleanedText, ({ body }) => body);
|
|
8256
|
+
return cleanedText;
|
|
8257
|
+
};
|
|
8258
|
+
|
|
8259
|
+
// source/fence-meta.ts
|
|
8260
|
+
var FENCE_META_KEY = "fenceMeta";
|
|
8261
|
+
function splitFenceInfo(info) {
|
|
8262
|
+
const trimmed = info.trim();
|
|
8263
|
+
if (!trimmed) return {};
|
|
8264
|
+
const firstSpace = trimmed.search(/\s/);
|
|
8265
|
+
let token = firstSpace === -1 ? trimmed : trimmed.slice(0, firstSpace);
|
|
8266
|
+
let rest = firstSpace === -1 ? "" : trimmed.slice(firstSpace).trim();
|
|
8267
|
+
const braceAt = token.indexOf("{");
|
|
8268
|
+
if (braceAt > 0) {
|
|
8269
|
+
rest = `${token.slice(braceAt)} ${rest}`.trim();
|
|
8270
|
+
token = token.slice(0, braceAt);
|
|
8271
|
+
}
|
|
8272
|
+
const colonAt = token.indexOf(":");
|
|
8273
|
+
if (colonAt > 0 && colonAt < token.length - 1) {
|
|
8274
|
+
const filename = token.slice(colonAt + 1);
|
|
8275
|
+
rest = `title="${filename}" ${rest}`.trim();
|
|
8276
|
+
token = token.slice(0, colonAt);
|
|
8277
|
+
}
|
|
8278
|
+
if (token.startsWith("{")) {
|
|
8279
|
+
rest = `${token} ${rest}`.trim();
|
|
8280
|
+
token = "";
|
|
8281
|
+
}
|
|
8282
|
+
const out = {};
|
|
8283
|
+
if (token) out.language = token;
|
|
8284
|
+
if (rest) out.meta = rest;
|
|
8285
|
+
return out;
|
|
8286
|
+
}
|
|
8287
|
+
var TITLE_RE = /(?:^|\s)(?:title|filename|file)=(?:"([^"]*)"|'([^']*)'|(\S+))/i;
|
|
8288
|
+
var RANGES_RE = /(?:^|\s)\{([\d\s,-]+)\}/;
|
|
8289
|
+
var LINE_NUMBERS_RE = /(?:^|\s)showLineNumbers(?:\{(\d+)\})?(?=\s|$)/;
|
|
8290
|
+
var MAX_HIGHLIGHT_LINES = 1e4;
|
|
8291
|
+
function parseFenceMeta(meta) {
|
|
8292
|
+
const result = { highlightLines: [] };
|
|
8293
|
+
if (!meta) return result;
|
|
8294
|
+
const title = TITLE_RE.exec(meta);
|
|
8295
|
+
if (title) {
|
|
8296
|
+
const value = (title[1] ?? title[2] ?? title[3] ?? "").trim();
|
|
8297
|
+
if (value) result.title = value;
|
|
8298
|
+
}
|
|
8299
|
+
const ranges = RANGES_RE.exec(meta);
|
|
8300
|
+
if (ranges) result.highlightLines = parseLineRanges(ranges[1] ?? "");
|
|
8301
|
+
const lineNumbers = LINE_NUMBERS_RE.exec(meta);
|
|
8302
|
+
if (lineNumbers) {
|
|
8303
|
+
result.showLineNumbers = true;
|
|
8304
|
+
if (lineNumbers[1]) {
|
|
8305
|
+
const start = Number.parseInt(lineNumbers[1], 10);
|
|
8306
|
+
if (Number.isFinite(start) && start > 0) result.startLine = start;
|
|
8307
|
+
}
|
|
8308
|
+
}
|
|
8309
|
+
return result;
|
|
8310
|
+
}
|
|
8311
|
+
function parseLineRanges(spec) {
|
|
8312
|
+
const lines = /* @__PURE__ */ new Set();
|
|
8313
|
+
for (const part of spec.split(",")) {
|
|
8314
|
+
const piece = part.trim();
|
|
8315
|
+
if (!piece) continue;
|
|
8316
|
+
const range = /^(\d+)\s*-\s*(\d+)$/.exec(piece);
|
|
8317
|
+
if (range) {
|
|
8318
|
+
const from = Number.parseInt(range[1] ?? "", 10);
|
|
8319
|
+
const to = Number.parseInt(range[2] ?? "", 10);
|
|
8320
|
+
if (from < 1 || to < from) continue;
|
|
8321
|
+
for (let n = from; n <= to && lines.size < MAX_HIGHLIGHT_LINES; n += 1) {
|
|
8322
|
+
lines.add(n);
|
|
8323
|
+
}
|
|
8324
|
+
continue;
|
|
8325
|
+
}
|
|
8326
|
+
if (/^\d+$/.test(piece)) {
|
|
8327
|
+
const n = Number.parseInt(piece, 10);
|
|
8328
|
+
if (n >= 1) lines.add(n);
|
|
8329
|
+
}
|
|
8330
|
+
}
|
|
8331
|
+
return [...lines].sort((a, b) => a - b);
|
|
8332
|
+
}
|
|
8333
|
+
|
|
8334
|
+
// source/directive-container.ts
|
|
8335
|
+
var DIRECTIVE_CONTAINER_OPEN = /^[ \t]{0,3}(:{3,})[A-Za-z][\w-]*/;
|
|
8336
|
+
var CLOSE = /^[ \t]{0,3}(:{3,})[ \t]*$/;
|
|
8337
|
+
var DirectiveContainerTracker = class {
|
|
8338
|
+
stack;
|
|
8339
|
+
fence = null;
|
|
8340
|
+
constructor(openingLine) {
|
|
8341
|
+
const m = DIRECTIVE_CONTAINER_OPEN.exec(openingLine);
|
|
8342
|
+
this.stack = [m ? m[1].length : 3];
|
|
8343
|
+
}
|
|
8344
|
+
/** Feed the next line (after the opener). True once the outermost container has closed on this line. */
|
|
8345
|
+
consume(line) {
|
|
8346
|
+
if (this.fence) {
|
|
8347
|
+
if (this.fence.feed(line)) this.fence = null;
|
|
8348
|
+
return false;
|
|
8349
|
+
}
|
|
8350
|
+
const opener = fenceOpenerOf(line);
|
|
8351
|
+
if (opener) {
|
|
8352
|
+
this.fence = new FenceReader(opener);
|
|
8353
|
+
return false;
|
|
8354
|
+
}
|
|
8355
|
+
const open = DIRECTIVE_CONTAINER_OPEN.exec(line);
|
|
8356
|
+
if (open) {
|
|
8357
|
+
this.stack.push(open[1].length);
|
|
8358
|
+
return false;
|
|
8359
|
+
}
|
|
8360
|
+
const close = CLOSE.exec(line);
|
|
8361
|
+
if (close && close[1].length >= (this.stack[this.stack.length - 1] ?? 3)) {
|
|
8362
|
+
this.stack.pop();
|
|
8363
|
+
return this.stack.length === 0;
|
|
8364
|
+
}
|
|
8365
|
+
return false;
|
|
8366
|
+
}
|
|
8367
|
+
};
|
|
8368
|
+
|
|
8369
|
+
// source/image-figure.ts
|
|
8370
|
+
var TITLED_IMAGE_LINE = /^[ \t]{0,3}!\[[^\]\n]*\]\(\s*<?[^\s)>]+>?\s+(?:"[^"\n]+"|'[^'\n]+')\s*\)[ \t]*$/;
|
|
8371
|
+
|
|
8372
|
+
// source/inline-code-span.ts
|
|
8373
|
+
function isInsideInlineCode(line, at) {
|
|
8374
|
+
let i = 0;
|
|
8375
|
+
while (i <= at && i < line.length) {
|
|
8376
|
+
if (line[i] === "\\") {
|
|
8377
|
+
i += 2;
|
|
8378
|
+
continue;
|
|
8379
|
+
}
|
|
8380
|
+
if (line[i] !== "`") {
|
|
8381
|
+
i += 1;
|
|
8382
|
+
continue;
|
|
8383
|
+
}
|
|
8384
|
+
let run = 0;
|
|
8385
|
+
while (line[i + run] === "`") run += 1;
|
|
8386
|
+
let close = -1;
|
|
8387
|
+
for (let j = i + run; j < line.length; ) {
|
|
8388
|
+
if (line[j] !== "`") {
|
|
8389
|
+
j += 1;
|
|
8390
|
+
continue;
|
|
8391
|
+
}
|
|
8392
|
+
let r = 0;
|
|
8393
|
+
while (line[j + r] === "`") r += 1;
|
|
8394
|
+
if (r === run) {
|
|
8395
|
+
close = j;
|
|
8396
|
+
break;
|
|
8397
|
+
}
|
|
8398
|
+
j += r;
|
|
8399
|
+
}
|
|
8400
|
+
if (close === -1) {
|
|
8401
|
+
i += run;
|
|
8402
|
+
continue;
|
|
8403
|
+
}
|
|
8404
|
+
if (at > i && at < close + run) return true;
|
|
8405
|
+
i = close + run;
|
|
8406
|
+
}
|
|
8407
|
+
return false;
|
|
8408
|
+
}
|
|
8409
|
+
function indexOutsideInlineCode(line, needle, from = 0) {
|
|
8410
|
+
for (let idx = line.indexOf(needle, from); idx !== -1; idx = line.indexOf(needle, idx + 1)) {
|
|
8411
|
+
if (!isInsideInlineCode(line, idx)) return idx;
|
|
8412
|
+
}
|
|
8413
|
+
return -1;
|
|
8414
|
+
}
|
|
8415
|
+
function hasUnclosedBacktickRun(text) {
|
|
8416
|
+
let i = 0;
|
|
8417
|
+
while (i < text.length) {
|
|
8418
|
+
if (text[i] === "\\") {
|
|
8419
|
+
i += 2;
|
|
8420
|
+
continue;
|
|
8421
|
+
}
|
|
8422
|
+
if (text[i] !== "`") {
|
|
8423
|
+
i += 1;
|
|
8424
|
+
continue;
|
|
8425
|
+
}
|
|
8426
|
+
let run = 0;
|
|
8427
|
+
while (text[i + run] === "`") run += 1;
|
|
8428
|
+
let close = -1;
|
|
8429
|
+
for (let j = i + run; j < text.length; ) {
|
|
8430
|
+
if (text[j] !== "`") {
|
|
8431
|
+
j += 1;
|
|
8432
|
+
continue;
|
|
8433
|
+
}
|
|
8434
|
+
let r = 0;
|
|
8435
|
+
while (text[j + r] === "`") r += 1;
|
|
8436
|
+
if (r === run) {
|
|
8437
|
+
close = j;
|
|
8438
|
+
break;
|
|
8439
|
+
}
|
|
8440
|
+
j += r;
|
|
8441
|
+
}
|
|
8442
|
+
if (close === -1) return true;
|
|
8443
|
+
i = close + run;
|
|
8444
|
+
}
|
|
8445
|
+
return false;
|
|
8446
|
+
}
|
|
8447
|
+
|
|
8448
|
+
// source/xml-tag-balance.ts
|
|
8449
|
+
function initialXmlBalance() {
|
|
8450
|
+
return { depth: 1, fence: null };
|
|
8451
|
+
}
|
|
8452
|
+
function escapeRegExp(value) {
|
|
8453
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8454
|
+
}
|
|
8455
|
+
function findBalancedXmlClose(line, tagName, state, { trackFences = true, nest = true } = {}) {
|
|
8456
|
+
if (state.fence) {
|
|
8457
|
+
if (state.fence.feed(line)) state.fence = null;
|
|
8458
|
+
return -1;
|
|
8459
|
+
}
|
|
8460
|
+
const opener = trackFences ? fenceOpenerOf(line) : null;
|
|
8461
|
+
if (opener) {
|
|
8462
|
+
state.fence = new FenceReader(opener);
|
|
8463
|
+
return -1;
|
|
8464
|
+
}
|
|
8465
|
+
const tag = new RegExp(
|
|
8466
|
+
`<(\\/?)${escapeRegExp(tagName)}(?=[\\s>/])[^<>]*?(\\/?)>`,
|
|
8467
|
+
"g"
|
|
8468
|
+
);
|
|
8469
|
+
for (const match of line.matchAll(tag)) {
|
|
8470
|
+
const closing = match[1] === "/";
|
|
8471
|
+
const selfClosing = match[2] === "/";
|
|
8472
|
+
if (closing) {
|
|
8473
|
+
state.depth -= 1;
|
|
8474
|
+
if (state.depth === 0) return match.index ?? -1;
|
|
8475
|
+
} else if (nest && !selfClosing && line.slice(0, match.index).trim() === "") {
|
|
8476
|
+
state.depth += 1;
|
|
8477
|
+
}
|
|
8478
|
+
}
|
|
8479
|
+
return -1;
|
|
8480
|
+
}
|
|
8481
|
+
|
|
8482
|
+
// source/gfm-table-lines.ts
|
|
8483
|
+
function findWholeTableStart(lines, from = 0) {
|
|
8484
|
+
for (let i = Math.max(0, from); i + 1 < lines.length; i += 1) if (tableStartsAt(lines, i)) return i;
|
|
8485
|
+
return -1;
|
|
8486
|
+
}
|
|
8487
|
+
function startsLikeTableRow(line) {
|
|
8488
|
+
return /^\s*\|/.test(line);
|
|
8489
|
+
}
|
|
8490
|
+
function isGrowingDelimiterRow(line) {
|
|
8491
|
+
return /^[\s|:-]*-[\s|:-]*$/.test(line);
|
|
8492
|
+
}
|
|
8493
|
+
function trailingTableStart(lines, end = lines.length) {
|
|
8494
|
+
const isTableLine = (line) => startsLikeTableRow(line) || continuesTable(line.trimStart());
|
|
8495
|
+
let start = end;
|
|
8496
|
+
while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
|
|
8497
|
+
if (start === end && end > 1 && isGrowingDelimiterRow(lines[end - 1] ?? "") && continuesTable((lines[end - 2] ?? "").trimStart())) {
|
|
8498
|
+
start = end - 1;
|
|
8499
|
+
while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
|
|
8500
|
+
}
|
|
8501
|
+
for (let head = start; head < end; head += 1) {
|
|
8502
|
+
if (startsLikeTableRow(lines[head] ?? "")) return head;
|
|
8503
|
+
if (end - head > 1 && isGrowingDelimiterRow(lines[head + 1] ?? "")) return head;
|
|
8504
|
+
}
|
|
8505
|
+
return end;
|
|
8506
|
+
}
|
|
8507
|
+
|
|
8090
8508
|
exports.ACTION_BY_CLASS = ACTION_BY_CLASS;
|
|
8091
8509
|
exports.AFTER_WINDOW = AFTER_WINDOW;
|
|
8092
8510
|
exports.BacktickRuns = BacktickRuns;
|
|
@@ -8095,8 +8513,11 @@ exports.CAPABILITY_BY_CLASS = CAPABILITY_BY_CLASS;
|
|
|
8095
8513
|
exports.CLASSES = CLASSES;
|
|
8096
8514
|
exports.CONTROL_KEYS = CONTROL_KEYS;
|
|
8097
8515
|
exports.CONTROL_KEY_FIELDS = CONTROL_KEY_FIELDS;
|
|
8516
|
+
exports.DIRECTIVE_CONTAINER_OPEN = DIRECTIVE_CONTAINER_OPEN;
|
|
8098
8517
|
exports.DIRECTIVE_VERSION = DIRECTIVE_VERSION;
|
|
8518
|
+
exports.DirectiveContainerTracker = DirectiveContainerTracker;
|
|
8099
8519
|
exports.DirectiveDecodeError = DirectiveDecodeError;
|
|
8520
|
+
exports.FENCE_META_KEY = FENCE_META_KEY;
|
|
8100
8521
|
exports.FENCE_OPENER_WHITESPACE = FENCE_OPENER_WHITESPACE;
|
|
8101
8522
|
exports.FENCE_WHITESPACE = FENCE_WHITESPACE;
|
|
8102
8523
|
exports.FenceReader = FenceReader;
|
|
@@ -8121,6 +8542,7 @@ exports.RUN_RESULT_KIND = RUN_RESULT_KIND;
|
|
|
8121
8542
|
exports.SIDE_EFFECT_CLASSES = SIDE_EFFECT_CLASSES;
|
|
8122
8543
|
exports.SLUG_PREFIX = SLUG_PREFIX;
|
|
8123
8544
|
exports.SourceSpliceError = SourceSpliceError;
|
|
8545
|
+
exports.TITLED_IMAGE_LINE = TITLED_IMAGE_LINE;
|
|
8124
8546
|
exports.XmlContainerTracker = XmlContainerTracker;
|
|
8125
8547
|
exports.advancePartialKind = advancePartialKind;
|
|
8126
8548
|
exports.asKindInstance = asKindInstance;
|
|
@@ -8135,6 +8557,7 @@ exports.buildKindDirective = buildKindDirective;
|
|
|
8135
8557
|
exports.capabilityOf = capabilityOf;
|
|
8136
8558
|
exports.classifyInboundEnvelopeMetadata = classifyInboundEnvelopeMetadata;
|
|
8137
8559
|
exports.classifyInnerFenceLine = classifyInnerFenceLine;
|
|
8560
|
+
exports.cleanMarkdown = cleanMarkdown;
|
|
8138
8561
|
exports.closeFence = closeFence;
|
|
8139
8562
|
exports.codeSpanText = codeSpanText;
|
|
8140
8563
|
exports.collectLinkDefinitions = collectLinkDefinitions;
|
|
@@ -8165,14 +8588,19 @@ exports.fenceNestsInnerFences = fenceNestsInnerFences;
|
|
|
8165
8588
|
exports.fenceOpenerOf = fenceOpenerOf;
|
|
8166
8589
|
exports.fenceParts = fenceParts;
|
|
8167
8590
|
exports.fieldsToDbPayload = fieldsToDbPayload;
|
|
8591
|
+
exports.findBalancedXmlClose = findBalancedXmlClose;
|
|
8168
8592
|
exports.findCodeRanges = findCodeRanges;
|
|
8169
8593
|
exports.findInlineCodeSpans = findInlineCodeSpans;
|
|
8170
8594
|
exports.findLinkDefinitionLines = findLinkDefinitionLines;
|
|
8171
8595
|
exports.findTableEnd = findTableEnd;
|
|
8172
8596
|
exports.findTableStart = findTableStart;
|
|
8597
|
+
exports.findWholeTableStart = findWholeTableStart;
|
|
8173
8598
|
exports.fingerprintText = fingerprintText;
|
|
8174
8599
|
exports.formatBlockLabel = formatBlockLabel;
|
|
8175
8600
|
exports.getParseSession = getParseSession;
|
|
8601
|
+
exports.hasUnclosedBacktickRun = hasUnclosedBacktickRun;
|
|
8602
|
+
exports.indexOutsideInlineCode = indexOutsideInlineCode;
|
|
8603
|
+
exports.initialXmlBalance = initialXmlBalance;
|
|
8176
8604
|
exports.injectKindIntoObjectSchema = injectKindIntoObjectSchema;
|
|
8177
8605
|
exports.irPathIsUnderOrEqual = irPathIsUnderOrEqual;
|
|
8178
8606
|
exports.irPathKey = irPathKey;
|
|
@@ -8184,7 +8612,9 @@ exports.isDuplicateBlockSlug = isDuplicateBlockSlug;
|
|
|
8184
8612
|
exports.isEmptyResidue = isEmptyResidue;
|
|
8185
8613
|
exports.isEscapedBracketMath = isEscapedBracketMath;
|
|
8186
8614
|
exports.isGfmDelimiterRow = isGfmDelimiterRow;
|
|
8615
|
+
exports.isGrowingDelimiterRow = isGrowingDelimiterRow;
|
|
8187
8616
|
exports.isHtmlBlockTagName = isHtmlBlockTagName;
|
|
8617
|
+
exports.isInsideInlineCode = isInsideInlineCode;
|
|
8188
8618
|
exports.isIrEnvelopeCache = isIrEnvelopeCache;
|
|
8189
8619
|
exports.isJsonAnyField = isJsonAnyField;
|
|
8190
8620
|
exports.isKindDirective = isKindDirective;
|
|
@@ -8216,6 +8646,8 @@ exports.mapCodeRanges = mapCodeRanges;
|
|
|
8216
8646
|
exports.mapInlineCodeSpans = mapInlineCodeSpans;
|
|
8217
8647
|
exports.mapPosition = mapPosition;
|
|
8218
8648
|
exports.mapRange = mapRange;
|
|
8649
|
+
exports.markdownToPlainText = markdownToPlainText;
|
|
8650
|
+
exports.mathToReadable = mathToReadable;
|
|
8219
8651
|
exports.mergeResidueIntoValue = mergeResidueIntoValue;
|
|
8220
8652
|
exports.normalizeAiSchemaInput = normalizeAiSchemaInput;
|
|
8221
8653
|
exports.normalizeJsonRegion = normalizeJsonRegion;
|
|
@@ -8228,7 +8660,9 @@ exports.opensStrippedHtmlBlock = opensStrippedHtmlBlock;
|
|
|
8228
8660
|
exports.opensTable = opensTable;
|
|
8229
8661
|
exports.pairDisplayMath = pairDisplayMath;
|
|
8230
8662
|
exports.parseDirectiveSlug = parseDirectiveSlug;
|
|
8663
|
+
exports.parseFenceMeta = parseFenceMeta;
|
|
8231
8664
|
exports.parseFenceOpener = parseFenceOpener;
|
|
8665
|
+
exports.parseLineRanges = parseLineRanges;
|
|
8232
8666
|
exports.pendingCodeSpanStart = pendingCodeSpanStart;
|
|
8233
8667
|
exports.pendingDisplayMathOpener = pendingDisplayMathOpener;
|
|
8234
8668
|
exports.readEnvelope = readEnvelope;
|
|
@@ -8241,6 +8675,8 @@ exports.readXmlTag = readXmlTag;
|
|
|
8241
8675
|
exports.reconstructRegionValue = reconstructRegionValue;
|
|
8242
8676
|
exports.rehydrateNodeOutcome = rehydrateNodeOutcome;
|
|
8243
8677
|
exports.rehydrateRunResult = rehydrateRunResult;
|
|
8678
|
+
exports.removeCodeSpans = removeCodeSpans;
|
|
8679
|
+
exports.replaceFences = replaceFences;
|
|
8244
8680
|
exports.resetLegacyShellUses = resetLegacyShellUses;
|
|
8245
8681
|
exports.resolveReferenceLinks = resolveReferenceLinks;
|
|
8246
8682
|
exports.resolvesInContent = resolvesInContent;
|
|
@@ -8256,10 +8692,13 @@ exports.schemaStructureDepth = schemaStructureDepth;
|
|
|
8256
8692
|
exports.setJsonRootKeyLookup = setJsonRootKeyLookup;
|
|
8257
8693
|
exports.singleDollarAfter = singleDollarAfter;
|
|
8258
8694
|
exports.singleDollarMathEnd = singleDollarMathEnd;
|
|
8695
|
+
exports.soleFence = soleFence;
|
|
8259
8696
|
exports.spliceSave = spliceSave;
|
|
8697
|
+
exports.splitFenceInfo = splitFenceInfo;
|
|
8260
8698
|
exports.splitRowSegments = splitRowSegments;
|
|
8261
8699
|
exports.splitsSurrogatePair = splitsSurrogatePair;
|
|
8262
8700
|
exports.startsHtmlBlock = startsHtmlBlock;
|
|
8701
|
+
exports.startsLikeTableRow = startsLikeTableRow;
|
|
8263
8702
|
exports.startsPipelessTable = startsPipelessTable;
|
|
8264
8703
|
exports.storageToKindSchema = storageToKindSchema;
|
|
8265
8704
|
exports.stripControlKeys = stripControlKeys;
|
|
@@ -8270,10 +8709,13 @@ exports.titleCaseToken = titleCaseToken;
|
|
|
8270
8709
|
exports.toCodePointOffset = toCodePointOffset;
|
|
8271
8710
|
exports.toUtf16Offset = toUtf16Offset;
|
|
8272
8711
|
exports.tokenizeSource = tokenizeSource;
|
|
8712
|
+
exports.trailingTableStart = trailingTableStart;
|
|
8273
8713
|
exports.trimFenceLine = trimFenceLine;
|
|
8274
8714
|
exports.tryDecodeDirective = tryDecodeDirective;
|
|
8275
8715
|
exports.tryDecodeDirectiveContent = tryDecodeDirectiveContent;
|
|
8276
8716
|
exports.unescapeCellPipes = unescapeCellPipes;
|
|
8717
|
+
exports.unwrapCodeSpans = unwrapCodeSpans;
|
|
8718
|
+
exports.unwrapKindEnvelopes = unwrapKindEnvelopes;
|
|
8277
8719
|
exports.validateBlockSchemaSavePlan = validateBlockSchemaSavePlan;
|
|
8278
8720
|
exports.validateStructuralLeg = validateStructuralLeg;
|
|
8279
8721
|
exports.withControlKeyFields = withControlKeyFields;
|