@ai-matrx/content-ir 0.18.1 → 0.18.3

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.cjs CHANGED
@@ -515,16 +515,27 @@ var BacktickRuns = class {
515
515
  }
516
516
  };
517
517
  function codeSpans(text, from, to, out) {
518
- const runs = new BacktickRuns(text, from, to);
519
- for (let r = 0; r < runs.all.length; ) {
520
- const [start, n] = runs.all[r];
521
- const close = runs.next(n, start + n);
518
+ let runs = null;
519
+ for (let i = from; i < to; ) {
520
+ const ch = text.charCodeAt(i);
521
+ if (ch === 92) {
522
+ i += 2;
523
+ continue;
524
+ }
525
+ if (ch !== 96) {
526
+ i++;
527
+ continue;
528
+ }
529
+ const n = backtickRunLength(text, i);
530
+ const len = Math.min(n, to - i);
531
+ runs ??= new BacktickRuns(text, from, to);
532
+ const close = runs.next(len, i + len);
522
533
  if (close === -1) {
523
- r++;
534
+ i += len;
524
535
  continue;
525
536
  }
526
- out.push({ start, end: close + n, kind: "span" });
527
- r = runs.index(close) + 1;
537
+ out.push({ start: i, end: close + len, kind: "span" });
538
+ i = close + len;
528
539
  }
529
540
  }
530
541
  function findCodeRanges(text) {
@@ -533,6 +544,33 @@ function findCodeRanges(text) {
533
544
  for (const [from, to] of s.paragraphs) codeSpans(text, from, to, ranges);
534
545
  return ranges.sort((a, b) => a.start - b.start);
535
546
  }
547
+ function mapCodeRanges(text, fn) {
548
+ let out = "";
549
+ let at = 0;
550
+ for (const r of findCodeRanges(text)) {
551
+ if (r.start < at) continue;
552
+ out += text.slice(at, r.start) + fn(r, text.slice(r.start, r.end));
553
+ at = r.end;
554
+ }
555
+ return out + text.slice(at);
556
+ }
557
+ function codeSpanText(raw) {
558
+ const ticks = backtickRunLength(raw, 0);
559
+ const inner = raw.slice(ticks, raw.length - ticks);
560
+ return inner.length >= 2 && inner.startsWith(" ") && inner.endsWith(" ") && inner.trim() !== "" ? inner.slice(1, -1) : inner;
561
+ }
562
+ function fenceParts(raw) {
563
+ const lines = raw.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
564
+ const { offset } = quotePrefix(lines[0] ?? "");
565
+ const opener = fenceOpenerOf((lines[0] ?? "").slice(offset).replace(/^ *(?:[-*+]|\d{1,9}[.)])(?= |\t|$) ?/, ""));
566
+ if (!opener) return null;
567
+ const rest = lines.slice(1);
568
+ const closed = rest.length > 0 && new FenceReader(opener, { nesting: false }).feed(rest[rest.length - 1]);
569
+ if (!closed) return { opener, body: rest.join("\n"), closed };
570
+ const last = rest[rest.length - 1];
571
+ const before = trimFenceLine(last).startsWith("```") ? "" : last.slice(0, last.indexOf("```"));
572
+ return { opener, body: [...rest.slice(0, -1), ...before.trim() ? [before] : []].join("\n"), closed };
573
+ }
536
574
  function fenceLineKinds(text) {
537
575
  const s = scan(text);
538
576
  let count = 1;
@@ -2360,9 +2398,11 @@ exports.blockRangeEdit = blockRangeEdit;
2360
2398
  exports.buildCodePointIndex = buildCodePointIndex;
2361
2399
  exports.classifyInnerFenceLine = classifyInnerFenceLine;
2362
2400
  exports.closeFence = closeFence;
2401
+ exports.codeSpanText = codeSpanText;
2363
2402
  exports.fenceLineKinds = fenceLineKinds;
2364
2403
  exports.fenceNestsInnerFences = fenceNestsInnerFences;
2365
2404
  exports.fenceOpenerOf = fenceOpenerOf;
2405
+ exports.fenceParts = fenceParts;
2366
2406
  exports.findCodeRanges = findCodeRanges;
2367
2407
  exports.isMathPlaceholder = isMathPlaceholder;
2368
2408
  exports.isSingleDollarMath = isSingleDollarMath;
@@ -2371,6 +2411,7 @@ exports.joinSource = joinSource;
2371
2411
  exports.listIslands = listIslands;
2372
2412
  exports.looksLikeDisplayMath = looksLikeDisplayMath;
2373
2413
  exports.looksLikeOpenInlineMath = looksLikeOpenInlineMath;
2414
+ exports.mapCodeRanges = mapCodeRanges;
2374
2415
  exports.mapPosition = mapPosition;
2375
2416
  exports.mapRange = mapRange;
2376
2417
  exports.pairDisplayMath = pairDisplayMath;