@ai-matrx/content-ir 0.21.0 → 0.21.2

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.d.cts CHANGED
@@ -535,20 +535,8 @@ interface FenceEnd {
535
535
  line: number;
536
536
  closed: boolean;
537
537
  }
538
- /**
539
- * THE closer rule, read line by line — the one implementation behind
540
- * `closeFence` and every streaming walker. Feed each following line
541
- * (container prefixes removed); `feed` returns true on the line that closes
542
- * the fence. A backtick fence closes by the nested-fence rule or the
543
- * renderer's line-end closer (`code````), and inside ```json a backtick run in
544
- * a JSON string is text; a tilde fence closes on `~~~` (≥ its length, ≤ 3
545
- * spaces). `nesting: false` forces strict CommonMark (the retry `closeFence`
546
- * makes when a nested fence is left open at the end; a streaming reader
547
- * cannot look ahead, so it reads with nesting and never retries).
548
- */
549
538
  declare class FenceReader {
550
539
  readonly opener: FenceOpener;
551
- private state;
552
540
  private depth;
553
541
  /** A nested fence was opened at some point. */
554
542
  sawNested: boolean;
package/dist/source.d.ts CHANGED
@@ -535,20 +535,8 @@ interface FenceEnd {
535
535
  line: number;
536
536
  closed: boolean;
537
537
  }
538
- /**
539
- * THE closer rule, read line by line — the one implementation behind
540
- * `closeFence` and every streaming walker. Feed each following line
541
- * (container prefixes removed); `feed` returns true on the line that closes
542
- * the fence. A backtick fence closes by the nested-fence rule or the
543
- * renderer's line-end closer (`code````), and inside ```json a backtick run in
544
- * a JSON string is text; a tilde fence closes on `~~~` (≥ its length, ≤ 3
545
- * spaces). `nesting: false` forces strict CommonMark (the retry `closeFence`
546
- * makes when a nested fence is left open at the end; a streaming reader
547
- * cannot look ahead, so it reads with nesting and never retries).
548
- */
549
538
  declare class FenceReader {
550
539
  readonly opener: FenceOpener;
551
- private state;
552
540
  private depth;
553
541
  /** A nested fence was opened at some point. */
554
542
  sawNested: boolean;
package/dist/source.js CHANGED
@@ -275,9 +275,9 @@ function fenceOpenerOf(content) {
275
275
  function opensStrictFence(line) {
276
276
  return fenceOpenerOf(line) !== null;
277
277
  }
278
+ var LINE_START = { inString: false, escaped: false };
278
279
  var FenceReader = class {
279
280
  opener;
280
- state = { inString: false, escaped: false };
281
281
  depth = 0;
282
282
  /** A nested fence was opened at some point. */
283
283
  sawNested = false;
@@ -298,17 +298,8 @@ var FenceReader = class {
298
298
  if (this.tildeCloser) return this.tildeCloser.test(line);
299
299
  const trimmedLine = trimFenceLine(line);
300
300
  const at = line.indexOf("```");
301
- if (at === -1) {
302
- if (this.isJson) this.state = jsonStringState(line, 0, line.length, this.state);
303
- return false;
304
- }
305
- if (this.isJson) {
306
- const probe = jsonStringState(line, 0, at, this.state);
307
- if (probe.inString) {
308
- this.state = jsonStringState(line, at, line.length, probe);
309
- return false;
310
- }
311
- }
301
+ if (at === -1) return false;
302
+ if (this.isJson && jsonStringState(line, 0, at, LINE_START).inString) return false;
312
303
  if (trimmedLine.startsWith("```")) {
313
304
  const kind = classifyInnerFenceLine(trimmedLine, this.opener.ticks, this.nesting, this.depth);
314
305
  if (kind === "close-outer") return true;
@@ -322,7 +313,6 @@ var FenceReader = class {
322
313
  const after = trimFenceLine(line.slice(at + closeTicks));
323
314
  if (closeTicks >= this.opener.ticks && after === "" && this.depth === 0) return true;
324
315
  }
325
- if (this.isJson) this.state = jsonStringState(line, 0, line.length, this.state);
326
316
  return false;
327
317
  }
328
318
  };
@@ -1206,6 +1196,8 @@ function findTableEnd(lines, start) {
1206
1196
  }
1207
1197
 
1208
1198
  // source/tokenize.ts
1199
+ var QUOTE_PREFIX = /^ {0,3}>(?: ?>)* ?/;
1200
+ var QUOTED_JSON_FENCE_LANGS = /* @__PURE__ */ new Set(["", "json", "jsonc", "json5"]);
1209
1201
  var NOT_WHITESPACE = /\S/;
1210
1202
  var DIRECTIVE_OPEN = /^(:{2,})([A-Za-z][\w-]*)/;
1211
1203
  var MKDOCS_OPEN = /^(!!!|\?\?\?\+?)[ \t]+([A-Za-z][\w-]*)/;
@@ -1695,6 +1687,8 @@ var Tokenizer = class {
1695
1687
  if (indent <= 3 && !listNested && t.startsWith(">")) {
1696
1688
  const callout = this.callout(p, li, t);
1697
1689
  if (callout) return callout;
1690
+ const lifted = this.quotedJsonFence(p, li, seg);
1691
+ if (lifted) return lifted;
1698
1692
  }
1699
1693
  if (atParaStart && indent <= 3 && t.startsWith("[^")) {
1700
1694
  const footnote = this.footnoteDefinition(p, li, t);
@@ -1890,6 +1884,42 @@ var Tokenizer = class {
1890
1884
  streaming: this.streaming
1891
1885
  };
1892
1886
  }
1887
+ /**
1888
+ * A JSON-family fence (unlabelled, json, jsonc, json5) opening on a quoted line. The renderer LIFTS it out
1889
+ * of the quote (matrx-frontend V1, never-raw law): the quote prefix is removed from every line of the
1890
+ * region, so the region is an ordinary top-level fence — drawn as code up to its own closer, which may sit on
1891
+ * a line that carries no `>` at all. The editor must lock at least what the renderer draws, so the island
1892
+ * runs from the quoted opener line to that closer (found on the lines with their quote prefix removed).
1893
+ */
1894
+ quotedJsonFence(p, li, seg) {
1895
+ const m = QUOTE_PREFIX.exec(seg);
1896
+ if (!m) return null;
1897
+ const opener = fenceOpenerOf(seg.slice(m[0].length));
1898
+ if (!opener || opener.char !== "`" || !QUOTED_JSON_FENCE_LANGS.has(opener.lang.toLowerCase())) return null;
1899
+ const base = this.fenceLines;
1900
+ const lines = {
1901
+ ...base,
1902
+ line: (k) => {
1903
+ const text = base.line(k);
1904
+ if (text === null) return null;
1905
+ const q = QUOTE_PREFIX.exec(text);
1906
+ return q ? text.slice(q[0].length) : text;
1907
+ }
1908
+ };
1909
+ let first = li;
1910
+ while (first > 0 && li - first < 400 && QUOTE_PREFIX.test(this.lineText(first - 1))) first--;
1911
+ for (let k = first; k < li; k++) {
1912
+ const o = fenceOpenerOf(lines.line(k) ?? "");
1913
+ if (!o || o.char !== "`" || QUOTED_JSON_FENCE_LANGS.has(o.lang.toLowerCase())) continue;
1914
+ const c = closeFence(lines, k, o);
1915
+ if (!c.closed || c.line >= li) return null;
1916
+ k = c.line;
1917
+ }
1918
+ const end = closeFence(lines, li, opener);
1919
+ const meta = { fence: "`", ticks: opener.ticks, lang: opener.lang };
1920
+ if (end.closed) return this.island("fence", p, this.contentEnds[end.line], true, meta);
1921
+ return this.island("fence", p, this.n, false, meta);
1922
+ }
1893
1923
  /**
1894
1924
  * Backtick fence — THE one closer (`closeFence`, source/code-ranges.ts): the
1895
1925
  * nested-fence rule for markdown fences with the strict-CommonMark retry, the
@@ -1922,44 +1952,14 @@ var Tokenizer = class {
1922
1952
  if (normalized && SPECIAL_CODE_LANGUAGES.has(normalized)) meta.special = normalized;
1923
1953
  const close = closeFence(this.fenceLines, li, opener);
1924
1954
  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);
1955
+ return this.island("fence", p, this.contentEnds[close.line], true, meta);
1928
1956
  }
1929
1957
  return this.island("fence", p, this.n, false, meta);
1930
1958
  }
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
- }
1959
+ // A tilde island ends at its closer. The renderer's splitter treats `~~~` as a real fence since
1960
+ // matrx-frontend A4 (2026-09-30): the lines inside are code, so nothing that starts inside one runs
1961
+ // past the closer (the 0.14.2 "overflow" assumed the renderer did not know ~~~ and, kept, swallowed the
1962
+ // next fence's opener into the tilde island: a ````md block after a ~~~ block was left unlocked).
1963
1963
  /**
1964
1964
  * A line-leading `$$` that OPENS a math pair (source/math-pairs.ts — the
1965
1965
  * core's rule). A closer, an unpaired `$$`, or a prose pair is never a block: