@ai-matrx/content-ir 0.15.0 → 0.15.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.d.cts CHANGED
@@ -425,8 +425,13 @@ declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nest
425
425
  * a lone `$$` (a stray closer, or an opener that never closed) never locks
426
426
  * anything. Linear time: one regex pass per code shape, one sweep.
427
427
  */
428
- /** The guard's `looksLikeMath`, verbatim. */
429
- declare function looksLikeDisplayMath(inner: string): boolean;
428
+ /**
429
+ * The guard's `looksLikeMath`. `flow` = the opener is alone on its line: a
430
+ * flow block may span blank lines (like a fence); a `$$` with text beside it
431
+ * never crosses one — TeX's rule, and what keeps a stray prose `$$` from
432
+ * pairing with the next paragraph's formula.
433
+ */
434
+ declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
430
435
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
431
436
  declare function pairDisplayMath(text: string): Map<number, number>;
432
437
 
package/dist/source.d.ts CHANGED
@@ -425,8 +425,13 @@ declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nest
425
425
  * a lone `$$` (a stray closer, or an opener that never closed) never locks
426
426
  * anything. Linear time: one regex pass per code shape, one sweep.
427
427
  */
428
- /** The guard's `looksLikeMath`, verbatim. */
429
- declare function looksLikeDisplayMath(inner: string): boolean;
428
+ /**
429
+ * The guard's `looksLikeMath`. `flow` = the opener is alone on its line: a
430
+ * flow block may span blank lines (like a fence); a `$$` with text beside it
431
+ * never crosses one — TeX's rule, and what keeps a stray prose `$$` from
432
+ * pairing with the next paragraph's formula.
433
+ */
434
+ declare function looksLikeDisplayMath(inner: string, flow?: boolean): boolean;
430
435
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
431
436
  declare function pairDisplayMath(text: string): Map<number, number>;
432
437
 
package/dist/source.js CHANGED
@@ -319,15 +319,20 @@ var STRUCTURAL_MARKDOWN = /\]\(|https?:\/\/|\*\*|(?:^|\n)[ \t]{0,3}#{1,6}[ \t]|(
319
319
  var LATEX_COMMAND = /\\[a-zA-Z]/;
320
320
  var PROSE_WORD = /[A-Za-z]{3,}/g;
321
321
  var PROSE_WORD_LIMIT = 6;
322
- function looksLikeDisplayMath(inner) {
322
+ function opensFlowBlock(text, open) {
323
+ for (let k = open - 1; k >= 0 && text[k] !== "\n"; k--) if (text[k] !== " " && text[k] !== " ") return false;
324
+ for (let k = open + 2; k < text.length && text[k] !== "\n"; k++) if (text[k] !== " " && text[k] !== " " && text[k] !== "\r") return false;
325
+ return true;
326
+ }
327
+ function looksLikeDisplayMath(inner, flow = false) {
323
328
  const s = inner.trim();
324
329
  if (!s) return false;
325
330
  if (STRUCTURAL_MARKDOWN.test(s)) return false;
326
331
  if (s.length > MAX_MATH_SPAN) return false;
332
+ if (!flow && /\n[ \t]*\n/.test(inner)) return false;
327
333
  if (LATEX_COMMAND.test(s)) {
328
334
  return (s.match(PROSE_WORD) ?? []).length < PROSE_WORD_LIMIT * 3;
329
335
  }
330
- if (/\n[ \t]*\n/.test(s)) return false;
331
336
  return (s.match(PROSE_WORD) ?? []).length < PROSE_WORD_LIMIT;
332
337
  }
333
338
  function codeRanges(text) {
@@ -361,7 +366,7 @@ function pairDisplayMath(text) {
361
366
  const open = tokens[j];
362
367
  const close = tokens[j + 1];
363
368
  if (close === void 0) break;
364
- if (looksLikeDisplayMath(text.slice(open + 2, close))) {
369
+ if (looksLikeDisplayMath(text.slice(open + 2, close), opensFlowBlock(text, open))) {
365
370
  pairs.set(open, close);
366
371
  j += 2;
367
372
  continue;