@ai-matrx/content-ir 0.20.1 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/source.js CHANGED
@@ -1206,6 +1206,8 @@ function findTableEnd(lines, start) {
1206
1206
  }
1207
1207
 
1208
1208
  // source/tokenize.ts
1209
+ var QUOTE_PREFIX = /^ {0,3}>(?: ?>)* ?/;
1210
+ var QUOTED_JSON_FENCE_LANGS = /* @__PURE__ */ new Set(["", "json", "jsonc", "json5"]);
1209
1211
  var NOT_WHITESPACE = /\S/;
1210
1212
  var DIRECTIVE_OPEN = /^(:{2,})([A-Za-z][\w-]*)/;
1211
1213
  var MKDOCS_OPEN = /^(!!!|\?\?\?\+?)[ \t]+([A-Za-z][\w-]*)/;
@@ -1695,6 +1697,8 @@ var Tokenizer = class {
1695
1697
  if (indent <= 3 && !listNested && t.startsWith(">")) {
1696
1698
  const callout = this.callout(p, li, t);
1697
1699
  if (callout) return callout;
1700
+ const lifted = this.quotedJsonFence(p, li, seg);
1701
+ if (lifted) return lifted;
1698
1702
  }
1699
1703
  if (atParaStart && indent <= 3 && t.startsWith("[^")) {
1700
1704
  const footnote = this.footnoteDefinition(p, li, t);
@@ -1890,6 +1894,42 @@ var Tokenizer = class {
1890
1894
  streaming: this.streaming
1891
1895
  };
1892
1896
  }
1897
+ /**
1898
+ * A JSON-family fence (unlabelled, json, jsonc, json5) opening on a quoted line. The renderer LIFTS it out
1899
+ * of the quote (matrx-frontend V1, never-raw law): the quote prefix is removed from every line of the
1900
+ * region, so the region is an ordinary top-level fence — drawn as code up to its own closer, which may sit on
1901
+ * a line that carries no `>` at all. The editor must lock at least what the renderer draws, so the island
1902
+ * runs from the quoted opener line to that closer (found on the lines with their quote prefix removed).
1903
+ */
1904
+ quotedJsonFence(p, li, seg) {
1905
+ const m = QUOTE_PREFIX.exec(seg);
1906
+ if (!m) return null;
1907
+ const opener = fenceOpenerOf(seg.slice(m[0].length));
1908
+ if (!opener || opener.char !== "`" || !QUOTED_JSON_FENCE_LANGS.has(opener.lang.toLowerCase())) return null;
1909
+ const base = this.fenceLines;
1910
+ const lines = {
1911
+ ...base,
1912
+ line: (k) => {
1913
+ const text = base.line(k);
1914
+ if (text === null) return null;
1915
+ const q = QUOTE_PREFIX.exec(text);
1916
+ return q ? text.slice(q[0].length) : text;
1917
+ }
1918
+ };
1919
+ let first = li;
1920
+ while (first > 0 && li - first < 400 && QUOTE_PREFIX.test(this.lineText(first - 1))) first--;
1921
+ for (let k = first; k < li; k++) {
1922
+ const o = fenceOpenerOf(lines.line(k) ?? "");
1923
+ if (!o || o.char !== "`" || QUOTED_JSON_FENCE_LANGS.has(o.lang.toLowerCase())) continue;
1924
+ const c = closeFence(lines, k, o);
1925
+ if (!c.closed || c.line >= li) return null;
1926
+ k = c.line;
1927
+ }
1928
+ const end = closeFence(lines, li, opener);
1929
+ const meta = { fence: "`", ticks: opener.ticks, lang: opener.lang };
1930
+ if (end.closed) return this.island("fence", p, this.contentEnds[end.line], true, meta);
1931
+ return this.island("fence", p, this.n, false, meta);
1932
+ }
1893
1933
  /**
1894
1934
  * Backtick fence — THE one closer (`closeFence`, source/code-ranges.ts): the
1895
1935
  * nested-fence rule for markdown fences with the strict-CommonMark retry, the
@@ -1922,44 +1962,14 @@ var Tokenizer = class {
1922
1962
  if (normalized && SPECIAL_CODE_LANGUAGES.has(normalized)) meta.special = normalized;
1923
1963
  const close = closeFence(this.fenceLines, li, opener);
1924
1964
  if (close.closed) {
1925
- const tildeEnd = this.contentEnds[close.line];
1926
- const end = this.rendererOverflow(li + 1, close.line, tildeEnd);
1927
- return this.island("fence", p, end, end === this.n ? this.overflowComplete : true, meta);
1965
+ return this.island("fence", p, this.contentEnds[close.line], true, meta);
1928
1966
  }
1929
1967
  return this.island("fence", p, this.n, false, meta);
1930
1968
  }
1931
- /** Completion of the last `rendererOverflow` that ran to the end of the text. */
1932
- overflowComplete = true;
1933
- /**
1934
- * The renderer's splitter does not know ~~~ fences: it reads the lines inside
1935
- * one as ordinary lines, so a ```` ``` ```` fence (or an XML section, a JSON
1936
- * block…) that STARTS inside the tilde fence can run past its closer. The
1937
- * editor must lock at least what the renderer draws (verify-RC-B3 residual
1938
- * R5), so a tilde island extends over every block the renderer would detect
1939
- * starting inside it. Returns the island's end.
1940
- */
1941
- rendererOverflow(firstLine, closeLine, tildeEnd) {
1942
- let end = tildeEnd;
1943
- this.overflowComplete = true;
1944
- for (let j = firstLine; j <= closeLine && j < this.lineCount; j++) {
1945
- const start = this.lineStarts[j];
1946
- if (this.lineIsBlank(j)) continue;
1947
- if (fenceOpenerOf(this.lineText(j))?.char === "~") continue;
1948
- const inner = this.detectBlockUncached(start, j, false);
1949
- if (!inner) continue;
1950
- if (this.streaming && inner.end >= tildeEnd && this.paragraphMayGrow(inner.end)) {
1951
- this.overflowComplete = false;
1952
- return this.n;
1953
- }
1954
- if (inner.end > end) {
1955
- end = inner.end;
1956
- this.overflowComplete = inner.complete;
1957
- }
1958
- const lastLine = this.lineOf(Math.max(start, inner.end - 1));
1959
- if (lastLine > j) j = lastLine;
1960
- }
1961
- return end;
1962
- }
1969
+ // A tilde island ends at its closer. The renderer's splitter treats `~~~` as a real fence since
1970
+ // matrx-frontend A4 (2026-09-30): the lines inside are code, so nothing that starts inside one runs
1971
+ // past the closer (the 0.14.2 "overflow" assumed the renderer did not know ~~~ and, kept, swallowed the
1972
+ // next fence's opener into the tilde island: a ````md block after a ~~~ block was left unlocked).
1963
1973
  /**
1964
1974
  * A line-leading `$$` that OPENS a math pair (source/math-pairs.ts — the
1965
1975
  * core's rule). A closer, an unpaired `$$`, or a prose pair is never a block:
@@ -2875,6 +2885,424 @@ function resolveReferenceLinks(fragment, defs) {
2875
2885
  return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
2876
2886
  }
2877
2887
 
2878
- 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, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceOpener, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes };
2888
+ // source/code-range-edits.ts
2889
+ function unwrapCodeSpans(text) {
2890
+ if (!text.includes("`")) return text;
2891
+ return mapCodeRanges(text, (range, raw) => range.kind === "span" ? codeSpanText(raw) : raw);
2892
+ }
2893
+ function removeCodeSpans(text) {
2894
+ if (!text.includes("`")) return text;
2895
+ return mapCodeRanges(text, (range, raw) => range.kind === "span" ? "" : raw);
2896
+ }
2897
+ function replaceFences(text, fn) {
2898
+ if (!text.includes("```") && !text.includes("~~~")) return text;
2899
+ return mapCodeRanges(text, (range, raw) => {
2900
+ if (range.kind !== "fence") return raw;
2901
+ const parts = fenceParts(raw);
2902
+ return fn({ lang: parts?.opener.lang ?? "", body: parts?.body ?? raw, closed: parts?.closed ?? false, raw });
2903
+ });
2904
+ }
2905
+ function soleFence(text, options = {}) {
2906
+ const trimmed = text.trim();
2907
+ if (!trimmed.startsWith("`") && !trimmed.startsWith("~")) return null;
2908
+ const ranges = findCodeRanges(trimmed);
2909
+ const only = ranges.length === 1 ? ranges[0] : void 0;
2910
+ if (!only || only.kind !== "fence" || only.start !== 0 || only.end !== trimmed.length) return null;
2911
+ const parts = fenceParts(trimmed);
2912
+ if (!parts || !parts.closed && !options.allowUnclosed) return null;
2913
+ return { lang: parts.opener.lang, body: parts.body, closed: parts.closed };
2914
+ }
2915
+
2916
+ // source/plain-text.ts
2917
+ var INLINE_PATTERNS = [
2918
+ // [label](href) → label. Runs first so emphasis inside a label still unwraps.
2919
+ [/\[([^\]]+)\]\([^)]*\)/g, "$1"],
2920
+ [/\*\*\*(?=\S)([\s\S]*?\S)\*\*\*/g, "$1"],
2921
+ [/___(?=\S)([\s\S]*?\S)___/g, "$1"],
2922
+ [/\*\*(?=\S)([\s\S]*?\S)\*\*/g, "$1"],
2923
+ [/__(?=\S)([\s\S]*?\S)__/g, "$1"],
2924
+ [/~~(?=\S)([\s\S]*?\S)~~/g, "$1"],
2925
+ [/\*(?=\S)([^*\n]*?\S)\*/g, "$1"],
2926
+ // Underscore italics only between word boundaries: snake_case_names are not
2927
+ // emphasis, and mangling an identifier is a worse defect than a stray marker.
2928
+ [/(^|[\s(])_(?=\S)([^_\n]*?\S)_(?=[\s).,;:!?]|$)/g, "$1$2"]
2929
+ ];
2930
+ var MATH_STRUCTURAL = [
2931
+ [/\\(?:d|t)?frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g, "$1/$2"],
2932
+ [/\\sqrt\s*\{([^{}]*)\}/g, "\u221A($1)"]
2933
+ ];
2934
+ var MATH_PATTERNS = [
2935
+ // Environments (\begin{aligned} … \end{aligned}) carry no meaning in a
2936
+ // one-line preview; drop the wrapper, keep the contents. Without this the
2937
+ // catch-all below turned them into the word "aligned" twice.
2938
+ [/\\(?:begin|end)\s*\{[^{}]*\}/g, " "],
2939
+ // A TeX line break inside a preview is just a space.
2940
+ [/\\\\/g, " "],
2941
+ // TeX spacing commands (\, \; \: thin/medium space, \! negative space).
2942
+ [/\\[,;:]/g, " "],
2943
+ [/\\!/g, ""],
2944
+ // \left\{ … \right\} — the escaped-brace forms, which the character-class
2945
+ // rule below cannot reach because the brace is preceded by a backslash.
2946
+ [/\\(?:left|right)\s*\\?([([\]|){}])/g, "$1"],
2947
+ // NOTE: every command below ends with (?![a-zA-Z]) and NOT \b. `_` is a WORD
2948
+ // character, so \b fails after `\sum_` — which silently left every
2949
+ // summation, integral and limit card reading as "sum_" / "int_".
2950
+ [/\\times(?![a-zA-Z])/g, "\xD7"],
2951
+ [/\\div(?![a-zA-Z])/g, "\xF7"],
2952
+ [/\\pm(?![a-zA-Z])/g, "\xB1"],
2953
+ [/\\cdot(?![a-zA-Z])/g, "\xB7"],
2954
+ [/\\leq(?![a-zA-Z])/g, "\u2264"],
2955
+ [/\\geq(?![a-zA-Z])/g, "\u2265"],
2956
+ [/\\neq(?![a-zA-Z])/g, "\u2260"],
2957
+ [/\\approx(?![a-zA-Z])/g, "\u2248"],
2958
+ [/\\infty(?![a-zA-Z])/g, "\u221E"],
2959
+ [/\\pi(?![a-zA-Z])/g, "\u03C0"],
2960
+ [/\\theta(?![a-zA-Z])/g, "\u03B8"],
2961
+ [/\\alpha(?![a-zA-Z])/g, "\u03B1"],
2962
+ [/\\beta(?![a-zA-Z])/g, "\u03B2"],
2963
+ [/\\Delta(?![a-zA-Z])/g, "\u0394"],
2964
+ [/\\delta(?![a-zA-Z])/g, "\u03B4"],
2965
+ [/\\sum(?![a-zA-Z])/g, "\u03A3"],
2966
+ [/\\prod(?![a-zA-Z])/g, "\u220F"],
2967
+ [/\\int(?![a-zA-Z])/g, "\u222B"],
2968
+ [/\\lim(?![a-zA-Z])/g, "lim"],
2969
+ [/\\(?:rightarrow|to)(?![a-zA-Z])/g, "\u2192"],
2970
+ // Braces that only ever grouped a script or argument: ^{2} → ^2, _{i} → _i.
2971
+ [/([_^])\s*\{([^{}]*)\}/g, "$1$2"],
2972
+ // Any remaining single-argument command: \text{x} / \mathrm{x} → x.
2973
+ [/\\[a-zA-Z]+\s*\{([^{}]*)\}/g, "$1"],
2974
+ // Bare commands we did not translate: drop the backslash, keep the word.
2975
+ [/\\([a-zA-Z]+)/g, "$1"]
2976
+ ];
2977
+ var MATH_REGIONS = [
2978
+ /\\\[([\s\S]*?)\\\]/g,
2979
+ /\\\(([\s\S]*?)\\\)/g,
2980
+ /\$\$([\s\S]*?)\$\$/g
2981
+ ];
2982
+ function mathToReadable(expression) {
2983
+ let text = expression;
2984
+ for (let pass = 0; pass < 8; pass += 1) {
2985
+ const before = text;
2986
+ for (const [pattern, replacement] of MATH_STRUCTURAL) {
2987
+ text = text.replace(pattern, replacement);
2988
+ }
2989
+ if (text === before) break;
2990
+ }
2991
+ for (const [pattern, replacement] of MATH_PATTERNS) {
2992
+ text = text.replace(pattern, replacement);
2993
+ }
2994
+ return text.trim();
2995
+ }
2996
+ function markdownToPlainText(value) {
2997
+ if (!value) return "";
2998
+ const mathChunks = [];
2999
+ let text = value;
3000
+ for (const region of MATH_REGIONS) {
3001
+ text = text.replace(region, (_match, inner) => {
3002
+ mathChunks.push(mathToReadable(inner));
3003
+ return `\uE000MATH${mathChunks.length - 1}\uE001`;
3004
+ });
3005
+ }
3006
+ for (const [pattern, replacement] of INLINE_PATTERNS) {
3007
+ text = text.replace(pattern, replacement);
3008
+ }
3009
+ text = unwrapCodeSpans(text);
3010
+ text = text.replace(
3011
+ /\uE000MATH(\d+)\uE001/g,
3012
+ (_m, index) => mathChunks[Number(index)] ?? ""
3013
+ );
3014
+ return text.replace(/[ \t]{2,}/g, " ").trim();
3015
+ }
3016
+ function unwrapKindEnvelopes(value) {
3017
+ if (!value) return "";
3018
+ if (!value.includes("<artifact")) return value;
3019
+ return tokenizeSource(value).map((block) => {
3020
+ if (block.kind !== "island" || block.islandType !== "xml_attr" && block.islandType !== "xml_container") {
3021
+ return block.raw;
3022
+ }
3023
+ const match = /^\s*<artifact\b[^>]*>([\s\S]*?)<\/artifact>\s*$/.exec(block.raw);
3024
+ return match ? (match[1] ?? "").replace(/^\n/, "").replace(/\n$/, "") : block.raw;
3025
+ }).join("");
3026
+ }
3027
+
3028
+ // source/clean-markdown.ts
3029
+ var cleanMarkdown = (text) => {
3030
+ if (!text || typeof text !== "string") return "";
3031
+ let cleanedText = text;
3032
+ const lines = cleanedText.split("\n");
3033
+ const processedLines = [];
3034
+ for (let line of lines) {
3035
+ let processedLine = line;
3036
+ if (processedLine.trim() === "") {
3037
+ processedLines.push(processedLine);
3038
+ continue;
3039
+ }
3040
+ processedLine = processedLine.replace(/^#{1,6}\s+(.+)$/, "$1");
3041
+ processedLine = processedLine.replace(/(\*\*|__)(.*?)\1/, "$2");
3042
+ processedLine = processedLine.replace(/(\*|_)(.*?)\1/, "$2");
3043
+ processedLine = unwrapCodeSpans(processedLine);
3044
+ processedLine = processedLine.replace(/\[([^\]]+)\]\(([^)]+)\)/, "$1");
3045
+ processedLine = processedLine.replace(/!\[([^\]]*)\]\(([^)]+)\)/, "$1");
3046
+ processedLine = processedLine.replace(/^>\s*(.+)$/, "$1");
3047
+ processedLine = processedLine.replace(/^(\*{3,}|-{3,}|_{3,})$/, "");
3048
+ processedLine = processedLine.replace(/^(\s*[-+*]\s+|\s*\d+\.\s+)(.+)$/, "$2");
3049
+ processedLine = processedLine.replace(/<\/?[^>]+(>|$)/g, "");
3050
+ processedLines.push(processedLine);
3051
+ }
3052
+ cleanedText = processedLines.join("\n");
3053
+ cleanedText = replaceFences(cleanedText, ({ body }) => body);
3054
+ return cleanedText;
3055
+ };
3056
+
3057
+ // source/fence-meta.ts
3058
+ var FENCE_META_KEY = "fenceMeta";
3059
+ function splitFenceInfo(info) {
3060
+ const trimmed = info.trim();
3061
+ if (!trimmed) return {};
3062
+ const firstSpace = trimmed.search(/\s/);
3063
+ let token = firstSpace === -1 ? trimmed : trimmed.slice(0, firstSpace);
3064
+ let rest = firstSpace === -1 ? "" : trimmed.slice(firstSpace).trim();
3065
+ const braceAt = token.indexOf("{");
3066
+ if (braceAt > 0) {
3067
+ rest = `${token.slice(braceAt)} ${rest}`.trim();
3068
+ token = token.slice(0, braceAt);
3069
+ }
3070
+ const colonAt = token.indexOf(":");
3071
+ if (colonAt > 0 && colonAt < token.length - 1) {
3072
+ const filename = token.slice(colonAt + 1);
3073
+ rest = `title="${filename}" ${rest}`.trim();
3074
+ token = token.slice(0, colonAt);
3075
+ }
3076
+ if (token.startsWith("{")) {
3077
+ rest = `${token} ${rest}`.trim();
3078
+ token = "";
3079
+ }
3080
+ const out = {};
3081
+ if (token) out.language = token;
3082
+ if (rest) out.meta = rest;
3083
+ return out;
3084
+ }
3085
+ var TITLE_RE = /(?:^|\s)(?:title|filename|file)=(?:"([^"]*)"|'([^']*)'|(\S+))/i;
3086
+ var RANGES_RE = /(?:^|\s)\{([\d\s,-]+)\}/;
3087
+ var LINE_NUMBERS_RE = /(?:^|\s)showLineNumbers(?:\{(\d+)\})?(?=\s|$)/;
3088
+ var MAX_HIGHLIGHT_LINES = 1e4;
3089
+ function parseFenceMeta(meta) {
3090
+ const result = { highlightLines: [] };
3091
+ if (!meta) return result;
3092
+ const title = TITLE_RE.exec(meta);
3093
+ if (title) {
3094
+ const value = (title[1] ?? title[2] ?? title[3] ?? "").trim();
3095
+ if (value) result.title = value;
3096
+ }
3097
+ const ranges = RANGES_RE.exec(meta);
3098
+ if (ranges) result.highlightLines = parseLineRanges(ranges[1] ?? "");
3099
+ const lineNumbers = LINE_NUMBERS_RE.exec(meta);
3100
+ if (lineNumbers) {
3101
+ result.showLineNumbers = true;
3102
+ if (lineNumbers[1]) {
3103
+ const start = Number.parseInt(lineNumbers[1], 10);
3104
+ if (Number.isFinite(start) && start > 0) result.startLine = start;
3105
+ }
3106
+ }
3107
+ return result;
3108
+ }
3109
+ function parseLineRanges(spec) {
3110
+ const lines = /* @__PURE__ */ new Set();
3111
+ for (const part of spec.split(",")) {
3112
+ const piece = part.trim();
3113
+ if (!piece) continue;
3114
+ const range = /^(\d+)\s*-\s*(\d+)$/.exec(piece);
3115
+ if (range) {
3116
+ const from = Number.parseInt(range[1] ?? "", 10);
3117
+ const to = Number.parseInt(range[2] ?? "", 10);
3118
+ if (from < 1 || to < from) continue;
3119
+ for (let n = from; n <= to && lines.size < MAX_HIGHLIGHT_LINES; n += 1) {
3120
+ lines.add(n);
3121
+ }
3122
+ continue;
3123
+ }
3124
+ if (/^\d+$/.test(piece)) {
3125
+ const n = Number.parseInt(piece, 10);
3126
+ if (n >= 1) lines.add(n);
3127
+ }
3128
+ }
3129
+ return [...lines].sort((a, b) => a - b);
3130
+ }
3131
+
3132
+ // source/directive-container.ts
3133
+ var DIRECTIVE_CONTAINER_OPEN = /^[ \t]{0,3}(:{3,})[A-Za-z][\w-]*/;
3134
+ var CLOSE = /^[ \t]{0,3}(:{3,})[ \t]*$/;
3135
+ var DirectiveContainerTracker = class {
3136
+ stack;
3137
+ fence = null;
3138
+ constructor(openingLine) {
3139
+ const m = DIRECTIVE_CONTAINER_OPEN.exec(openingLine);
3140
+ this.stack = [m ? m[1].length : 3];
3141
+ }
3142
+ /** Feed the next line (after the opener). True once the outermost container has closed on this line. */
3143
+ consume(line) {
3144
+ if (this.fence) {
3145
+ if (this.fence.feed(line)) this.fence = null;
3146
+ return false;
3147
+ }
3148
+ const opener = fenceOpenerOf(line);
3149
+ if (opener) {
3150
+ this.fence = new FenceReader(opener);
3151
+ return false;
3152
+ }
3153
+ const open = DIRECTIVE_CONTAINER_OPEN.exec(line);
3154
+ if (open) {
3155
+ this.stack.push(open[1].length);
3156
+ return false;
3157
+ }
3158
+ const close = CLOSE.exec(line);
3159
+ if (close && close[1].length >= (this.stack[this.stack.length - 1] ?? 3)) {
3160
+ this.stack.pop();
3161
+ return this.stack.length === 0;
3162
+ }
3163
+ return false;
3164
+ }
3165
+ };
3166
+
3167
+ // source/image-figure.ts
3168
+ var TITLED_IMAGE_LINE = /^[ \t]{0,3}!\[[^\]\n]*\]\(\s*<?[^\s)>]+>?\s+(?:"[^"\n]+"|'[^'\n]+')\s*\)[ \t]*$/;
3169
+
3170
+ // source/inline-code-span.ts
3171
+ function isInsideInlineCode(line, at) {
3172
+ let i = 0;
3173
+ while (i <= at && i < line.length) {
3174
+ if (line[i] === "\\") {
3175
+ i += 2;
3176
+ continue;
3177
+ }
3178
+ if (line[i] !== "`") {
3179
+ i += 1;
3180
+ continue;
3181
+ }
3182
+ let run = 0;
3183
+ while (line[i + run] === "`") run += 1;
3184
+ let close = -1;
3185
+ for (let j = i + run; j < line.length; ) {
3186
+ if (line[j] !== "`") {
3187
+ j += 1;
3188
+ continue;
3189
+ }
3190
+ let r = 0;
3191
+ while (line[j + r] === "`") r += 1;
3192
+ if (r === run) {
3193
+ close = j;
3194
+ break;
3195
+ }
3196
+ j += r;
3197
+ }
3198
+ if (close === -1) {
3199
+ i += run;
3200
+ continue;
3201
+ }
3202
+ if (at > i && at < close + run) return true;
3203
+ i = close + run;
3204
+ }
3205
+ return false;
3206
+ }
3207
+ function indexOutsideInlineCode(line, needle, from = 0) {
3208
+ for (let idx = line.indexOf(needle, from); idx !== -1; idx = line.indexOf(needle, idx + 1)) {
3209
+ if (!isInsideInlineCode(line, idx)) return idx;
3210
+ }
3211
+ return -1;
3212
+ }
3213
+ function hasUnclosedBacktickRun(text) {
3214
+ let i = 0;
3215
+ while (i < text.length) {
3216
+ if (text[i] === "\\") {
3217
+ i += 2;
3218
+ continue;
3219
+ }
3220
+ if (text[i] !== "`") {
3221
+ i += 1;
3222
+ continue;
3223
+ }
3224
+ let run = 0;
3225
+ while (text[i + run] === "`") run += 1;
3226
+ let close = -1;
3227
+ for (let j = i + run; j < text.length; ) {
3228
+ if (text[j] !== "`") {
3229
+ j += 1;
3230
+ continue;
3231
+ }
3232
+ let r = 0;
3233
+ while (text[j + r] === "`") r += 1;
3234
+ if (r === run) {
3235
+ close = j;
3236
+ break;
3237
+ }
3238
+ j += r;
3239
+ }
3240
+ if (close === -1) return true;
3241
+ i = close + run;
3242
+ }
3243
+ return false;
3244
+ }
3245
+
3246
+ // source/xml-tag-balance.ts
3247
+ function initialXmlBalance() {
3248
+ return { depth: 1, fence: null };
3249
+ }
3250
+ function escapeRegExp(value) {
3251
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3252
+ }
3253
+ function findBalancedXmlClose(line, tagName, state, { trackFences = true, nest = true } = {}) {
3254
+ if (state.fence) {
3255
+ if (state.fence.feed(line)) state.fence = null;
3256
+ return -1;
3257
+ }
3258
+ const opener = trackFences ? fenceOpenerOf(line) : null;
3259
+ if (opener) {
3260
+ state.fence = new FenceReader(opener);
3261
+ return -1;
3262
+ }
3263
+ const tag = new RegExp(
3264
+ `<(\\/?)${escapeRegExp(tagName)}(?=[\\s>/])[^<>]*?(\\/?)>`,
3265
+ "g"
3266
+ );
3267
+ for (const match of line.matchAll(tag)) {
3268
+ const closing = match[1] === "/";
3269
+ const selfClosing = match[2] === "/";
3270
+ if (closing) {
3271
+ state.depth -= 1;
3272
+ if (state.depth === 0) return match.index ?? -1;
3273
+ } else if (nest && !selfClosing && line.slice(0, match.index).trim() === "") {
3274
+ state.depth += 1;
3275
+ }
3276
+ }
3277
+ return -1;
3278
+ }
3279
+
3280
+ // source/gfm-table-lines.ts
3281
+ function findWholeTableStart(lines, from = 0) {
3282
+ for (let i = Math.max(0, from); i + 1 < lines.length; i += 1) if (tableStartsAt(lines, i)) return i;
3283
+ return -1;
3284
+ }
3285
+ function startsLikeTableRow(line) {
3286
+ return /^\s*\|/.test(line);
3287
+ }
3288
+ function isGrowingDelimiterRow(line) {
3289
+ return /^[\s|:-]*-[\s|:-]*$/.test(line);
3290
+ }
3291
+ function trailingTableStart(lines, end = lines.length) {
3292
+ const isTableLine = (line) => startsLikeTableRow(line) || continuesTable(line.trimStart());
3293
+ let start = end;
3294
+ while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
3295
+ if (start === end && end > 1 && isGrowingDelimiterRow(lines[end - 1] ?? "") && continuesTable((lines[end - 2] ?? "").trimStart())) {
3296
+ start = end - 1;
3297
+ while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
3298
+ }
3299
+ for (let head = start; head < end; head += 1) {
3300
+ if (startsLikeTableRow(lines[head] ?? "")) return head;
3301
+ if (end - head > 1 && isGrowingDelimiterRow(lines[head + 1] ?? "")) return head;
3302
+ }
3303
+ return end;
3304
+ }
3305
+
3306
+ export { AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, DIRECTIVE_CONTAINER_OPEN, DirectiveContainerTracker, FENCE_META_KEY, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, NESTING_FENCE_LANGUAGES, SourceSpliceError, TITLED_IMAGE_LINE, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, cleanMarkdown, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findBalancedXmlClose, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, findWholeTableStart, hasUnclosedBacktickRun, indexOutsideInlineCode, initialXmlBalance, isEscapedBracketMath, isGfmDelimiterRow, isGrowingDelimiterRow, isHtmlBlockTagName, isInsideInlineCode, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, markdownToPlainText, mathToReadable, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceMeta, parseFenceOpener, parseLineRanges, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, removeCodeSpans, replaceFences, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, soleFence, spliceSave, splitFenceInfo, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsLikeTableRow, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trailingTableStart, trimFenceLine, unescapeCellPipes, unwrapCodeSpans, unwrapKindEnvelopes };
2879
3307
  //# sourceMappingURL=source.js.map
2880
3308
  //# sourceMappingURL=source.js.map