openzca 0.1.33 → 0.1.35

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 +94 -14
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -707,40 +707,92 @@ function asThreadType(groupFlag) {
707
707
  }
708
708
  function parseTextStyles(input) {
709
709
  const allStyles = [];
710
- const lines = input.split("\n");
710
+ const codeLineIndices = /* @__PURE__ */ new Set();
711
+ {
712
+ const rawLines = input.split("\n");
713
+ const kept = [];
714
+ let inCode = false;
715
+ for (const rawLine of rawLines) {
716
+ if (/^```/.test(rawLine)) {
717
+ inCode = !inCode;
718
+ continue;
719
+ }
720
+ if (inCode) {
721
+ codeLineIndices.add(kept.length);
722
+ }
723
+ kept.push(rawLine);
724
+ }
725
+ input = kept.join("\n");
726
+ }
727
+ const escapeMap = [];
728
+ const escaped = input.replace(/\\([*_~#\\{}>+\-])/g, (_match, ch) => {
729
+ const idx = escapeMap.length;
730
+ escapeMap.push(ch);
731
+ return `${idx}`;
732
+ });
733
+ const lines = escaped.split("\n");
711
734
  const lineStyles = [];
712
735
  const processedLines = [];
713
736
  for (let i = 0; i < lines.length; i++) {
714
- const line = lines[i];
715
- const headingMatch = line.match(/^(#{1,3})\s(.*)$/);
737
+ let line = lines[i];
738
+ if (codeLineIndices.has(i)) {
739
+ processedLines.push(line);
740
+ continue;
741
+ }
742
+ const headingMatch = line.match(/^(#{1,4})\s(.*)$/);
716
743
  if (headingMatch) {
717
744
  const level = headingMatch[1].length;
718
745
  lineStyles.push({ lineIndex: i, style: TextStyle.Bold });
719
746
  if (level === 1) lineStyles.push({ lineIndex: i, style: TextStyle.Big });
720
- if (level === 3) lineStyles.push({ lineIndex: i, style: TextStyle.Small });
747
+ else if (level === 3 || level === 4) lineStyles.push({ lineIndex: i, style: TextStyle.Small });
721
748
  processedLines.push(headingMatch[2]);
722
749
  continue;
723
750
  }
724
- const olMatch = line.match(/^(\d+)\.\s(.*)$/);
751
+ const bqMatch = line.match(/^(>+)\s?(.*)$/);
752
+ if (bqMatch) {
753
+ lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: bqMatch[1].length });
754
+ line = bqMatch[2];
755
+ }
756
+ const indentContentMatch = line.match(/^(\s+)(.*)$/);
757
+ let indentLevel = 0;
758
+ let content = line;
759
+ if (indentContentMatch) {
760
+ indentLevel = Math.max(1, Math.floor(indentContentMatch[1].length / 2));
761
+ content = indentContentMatch[2];
762
+ }
763
+ if (/^[-*+]\s\[[ xX]\]\s/.test(content)) {
764
+ processedLines.push(line);
765
+ continue;
766
+ }
767
+ const olMatch = content.match(/^(\d+)\.\s(.*)$/);
725
768
  if (olMatch) {
769
+ if (indentLevel > 0) {
770
+ lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
771
+ }
726
772
  lineStyles.push({ lineIndex: i, style: TextStyle.OrderedList });
727
773
  processedLines.push(olMatch[2]);
728
774
  continue;
729
775
  }
730
- const ulMatch = line.match(/^-\s(.*)$/);
776
+ const ulMatch = content.match(/^[-*+]\s(.*)$/);
731
777
  if (ulMatch) {
778
+ if (indentLevel > 0) {
779
+ lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
780
+ }
732
781
  lineStyles.push({ lineIndex: i, style: TextStyle.UnorderedList });
733
782
  processedLines.push(ulMatch[1]);
734
783
  continue;
735
784
  }
736
- const indentMatch = line.match(/^(>+)\s?(.*)$/);
737
- if (indentMatch) {
738
- lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentMatch[1].length });
739
- processedLines.push(indentMatch[2]);
740
- continue;
741
- }
742
785
  processedLines.push(line);
743
786
  }
787
+ for (const ci of codeLineIndices) {
788
+ if (ci < processedLines.length) {
789
+ processedLines[ci] = processedLines[ci].replace(/[*_~{}]/g, (ch) => {
790
+ const idx = escapeMap.length;
791
+ escapeMap.push(ch);
792
+ return `${idx}`;
793
+ });
794
+ }
795
+ }
744
796
  const inlineInput = processedLines.join("\n");
745
797
  const colorMap = {
746
798
  red: TextStyle.Red,
@@ -748,16 +800,22 @@ function parseTextStyles(input) {
748
800
  yellow: TextStyle.Yellow,
749
801
  green: TextStyle.Green,
750
802
  small: TextStyle.Small,
751
- big: TextStyle.Big
803
+ big: TextStyle.Big,
804
+ underline: TextStyle.Underline
752
805
  };
753
806
  const tagNames = Object.keys(colorMap).join("|");
754
807
  const markers = [
755
808
  // Tags first so inner markdown markers are preserved for subsequent passes
756
809
  { pattern: new RegExp(`\\{(${tagNames})\\}(.+?)\\{/\\1\\}`, "g"), style: null },
810
+ // *** = bold + italic
757
811
  { pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold, extraStyles: [TextStyle.Italic] },
812
+ // ** and __ = bold (standard markdown)
758
813
  { pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
814
+ { pattern: /__(.+?)__/g, style: TextStyle.Bold },
815
+ // * and _ = italic (standard markdown)
759
816
  { pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
760
- { pattern: /__(.+?)__/g, style: TextStyle.Underline },
817
+ { pattern: /_(.+?)_/g, style: TextStyle.Italic },
818
+ // ~~ = strikethrough
761
819
  { pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
762
820
  ];
763
821
  let segments = [{ text: inlineInput, styles: [] }];
@@ -797,6 +855,28 @@ function parseTextStyles(input) {
797
855
  allStyles.push({ start, len: seg.text.length, st });
798
856
  }
799
857
  }
858
+ if (escapeMap.length > 0) {
859
+ const escRegex = /\x01(\d+)\x02/g;
860
+ const shifts = [];
861
+ let cumDelta = 0;
862
+ for (const m of plainText.matchAll(escRegex)) {
863
+ const idx = parseInt(m[1], 10);
864
+ cumDelta += m[0].length - escapeMap[idx].length;
865
+ shifts.push({ pos: m.index + m[0].length, delta: cumDelta });
866
+ }
867
+ for (const s of allStyles) {
868
+ let startDelta = 0;
869
+ let endDelta = 0;
870
+ const end = s.start + s.len;
871
+ for (const sh of shifts) {
872
+ if (sh.pos <= s.start) startDelta = sh.delta;
873
+ if (sh.pos <= end) endDelta = sh.delta;
874
+ }
875
+ s.start -= startDelta;
876
+ s.len -= endDelta - startDelta;
877
+ }
878
+ plainText = plainText.replace(escRegex, (_m, idxStr) => escapeMap[parseInt(idxStr, 10)]);
879
+ }
800
880
  const finalLines = plainText.split("\n");
801
881
  let offset = 0;
802
882
  for (let i = 0; i < finalLines.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openzca",
3
- "version": "0.1.33",
3
+ "version": "0.1.35",
4
4
  "description": "Open-source zca-compatible CLI to integrate Zalo with OpenClaw",
5
5
  "type": "module",
6
6
  "bin": {