openzca 0.1.38 → 0.1.40

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.
Files changed (2) hide show
  1. package/dist/cli.js +27 -47
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -603,8 +603,6 @@ var INLINE_MARKERS = [
603
603
  ];
604
604
  function parseTextStyles(input) {
605
605
  const allStyles = [];
606
- const codeLineIndices = extractCodeBlockLines(input);
607
- input = stripCodeFences(input);
608
606
  const escapeMap = [];
609
607
  const escapedInput = input.replace(/\\([*_~#\\{}>+\-])/g, (_match, ch) => {
610
608
  const index = escapeMap.length;
@@ -614,10 +612,18 @@ function parseTextStyles(input) {
614
612
  const lines = escapedInput.split("\n");
615
613
  const lineStyles = [];
616
614
  const processedLines = [];
615
+ const codeOutputLineIndices = /* @__PURE__ */ new Set();
616
+ let inCodeBlock = false;
617
617
  for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
618
618
  let line = lines[lineIndex];
619
- if (codeLineIndices.has(lineIndex)) {
620
- processedLines.push(line);
619
+ let baseIndent = 0;
620
+ if (/^```/.test(line)) {
621
+ inCodeBlock = !inCodeBlock;
622
+ continue;
623
+ }
624
+ if (inCodeBlock) {
625
+ codeOutputLineIndices.add(processedLines.length);
626
+ processedLines.push(normalizeCodeBlockLeadingWhitespace(line));
621
627
  continue;
622
628
  }
623
629
  const headingMatch = line.match(/^(#{1,4})\s(.*)$/);
@@ -634,11 +640,7 @@ function parseTextStyles(input) {
634
640
  }
635
641
  const quoteMatch = line.match(/^(>+)\s?(.*)$/);
636
642
  if (quoteMatch) {
637
- lineStyles.push({
638
- lineIndex,
639
- style: TextStyle.Indent,
640
- indentSize: Math.min(5, quoteMatch[1].length)
641
- });
643
+ baseIndent = Math.min(5, quoteMatch[1].length);
642
644
  line = quoteMatch[2];
643
645
  }
644
646
  const indentMatch = line.match(/^(\s+)(.*)$/);
@@ -648,17 +650,18 @@ function parseTextStyles(input) {
648
650
  indentLevel = clampIndent(indentMatch[1].length);
649
651
  content = indentMatch[2];
650
652
  }
653
+ const totalIndent = Math.min(5, baseIndent + indentLevel);
651
654
  if (/^[-*+]\s\[[ xX]\]\s/.test(content)) {
652
- if (indentLevel > 0) {
653
- lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
655
+ if (totalIndent > 0) {
656
+ lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
654
657
  }
655
658
  processedLines.push(content);
656
659
  continue;
657
660
  }
658
661
  const orderedListMatch = content.match(/^(\d+)\.\s(.*)$/);
659
662
  if (orderedListMatch) {
660
- if (indentLevel > 0) {
661
- lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
663
+ if (totalIndent > 0) {
664
+ lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
662
665
  }
663
666
  lineStyles.push({ lineIndex, style: TextStyle.OrderedList });
664
667
  processedLines.push(orderedListMatch[2]);
@@ -666,21 +669,21 @@ function parseTextStyles(input) {
666
669
  }
667
670
  const unorderedListMatch = content.match(/^[-*+]\s(.*)$/);
668
671
  if (unorderedListMatch) {
669
- if (indentLevel > 0) {
670
- lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
672
+ if (totalIndent > 0) {
673
+ lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
671
674
  }
672
675
  lineStyles.push({ lineIndex, style: TextStyle.UnorderedList });
673
676
  processedLines.push(unorderedListMatch[1]);
674
677
  continue;
675
678
  }
676
- if (indentLevel > 0) {
677
- lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
679
+ if (totalIndent > 0) {
680
+ lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
678
681
  processedLines.push(content);
679
682
  continue;
680
683
  }
681
684
  processedLines.push(line);
682
685
  }
683
- for (const codeLineIndex of codeLineIndices) {
686
+ for (const codeLineIndex of codeOutputLineIndices) {
684
687
  if (codeLineIndex >= processedLines.length) {
685
688
  continue;
686
689
  }
@@ -812,38 +815,15 @@ function parseTextStyles(input) {
812
815
  }
813
816
  return { text: plainText, styles: allStyles };
814
817
  }
815
- function extractCodeBlockLines(input) {
816
- const codeLineIndices = /* @__PURE__ */ new Set();
817
- const rawLines = input.split("\n");
818
- let lineIndex = 0;
819
- let inCodeBlock = false;
820
- for (const rawLine of rawLines) {
821
- if (/^```/.test(rawLine)) {
822
- inCodeBlock = !inCodeBlock;
823
- continue;
824
- }
825
- if (inCodeBlock) {
826
- codeLineIndices.add(lineIndex);
827
- }
828
- lineIndex += 1;
829
- }
830
- return codeLineIndices;
831
- }
832
- function stripCodeFences(input) {
833
- const keptLines = [];
834
- let inCodeBlock = false;
835
- for (const rawLine of input.split("\n")) {
836
- if (/^```/.test(rawLine)) {
837
- inCodeBlock = !inCodeBlock;
838
- continue;
839
- }
840
- keptLines.push(rawLine);
841
- }
842
- return keptLines.join("\n");
843
- }
844
818
  function clampIndent(spaceCount) {
845
819
  return Math.min(5, Math.max(1, Math.floor(spaceCount / 2)));
846
820
  }
821
+ function normalizeCodeBlockLeadingWhitespace(line) {
822
+ return line.replace(
823
+ /^[ \t]+/,
824
+ (leadingWhitespace) => leadingWhitespace.replace(/\t/g, "\xA0\xA0\xA0\xA0").replace(/ /g, "\xA0")
825
+ );
826
+ }
847
827
 
848
828
  // src/cli.ts
849
829
  var require2 = createRequire(import.meta.url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openzca",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "Open-source zca-compatible CLI to integrate Zalo with OpenClaw",
5
5
  "type": "module",
6
6
  "bin": {