openzca 0.1.33 → 0.1.34

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 +63 -12
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -707,36 +707,59 @@ function asThreadType(groupFlag) {
707
707
  }
708
708
  function parseTextStyles(input) {
709
709
  const allStyles = [];
710
- const lines = input.split("\n");
710
+ const escapeMap = [];
711
+ const escaped = input.replace(/\\([*_~#\\{}>+\-])/g, (_match, ch) => {
712
+ const idx = escapeMap.length;
713
+ escapeMap.push(ch);
714
+ return `${idx}`;
715
+ });
716
+ const lines = escaped.split("\n");
711
717
  const lineStyles = [];
712
718
  const processedLines = [];
713
719
  for (let i = 0; i < lines.length; i++) {
714
- const line = lines[i];
715
- const headingMatch = line.match(/^(#{1,3})\s(.*)$/);
720
+ let line = lines[i];
721
+ const headingMatch = line.match(/^(#{1,6})\s(.*)$/);
716
722
  if (headingMatch) {
717
723
  const level = headingMatch[1].length;
718
724
  lineStyles.push({ lineIndex: i, style: TextStyle.Bold });
719
725
  if (level === 1) lineStyles.push({ lineIndex: i, style: TextStyle.Big });
720
- if (level === 3) lineStyles.push({ lineIndex: i, style: TextStyle.Small });
726
+ else if (level >= 3) lineStyles.push({ lineIndex: i, style: TextStyle.Small });
721
727
  processedLines.push(headingMatch[2]);
722
728
  continue;
723
729
  }
724
- const olMatch = line.match(/^(\d+)\.\s(.*)$/);
730
+ const bqMatch = line.match(/^(>+)\s?(.*)$/);
731
+ if (bqMatch) {
732
+ lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: bqMatch[1].length });
733
+ line = bqMatch[2];
734
+ }
735
+ const indentContentMatch = line.match(/^(\s+)(.*)$/);
736
+ let indentLevel = 0;
737
+ let content = line;
738
+ if (indentContentMatch) {
739
+ indentLevel = Math.max(1, Math.floor(indentContentMatch[1].length / 2));
740
+ content = indentContentMatch[2];
741
+ }
742
+ const olMatch = content.match(/^(\d+)\.\s(.*)$/);
725
743
  if (olMatch) {
744
+ if (indentLevel > 0) {
745
+ lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
746
+ }
726
747
  lineStyles.push({ lineIndex: i, style: TextStyle.OrderedList });
727
748
  processedLines.push(olMatch[2]);
728
749
  continue;
729
750
  }
730
- const ulMatch = line.match(/^-\s(.*)$/);
751
+ const ulMatch = content.match(/^[-*+]\s(.*)$/);
731
752
  if (ulMatch) {
753
+ if (indentLevel > 0) {
754
+ lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
755
+ }
732
756
  lineStyles.push({ lineIndex: i, style: TextStyle.UnorderedList });
733
757
  processedLines.push(ulMatch[1]);
734
758
  continue;
735
759
  }
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]);
760
+ if (indentLevel > 0) {
761
+ lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
762
+ processedLines.push(content);
740
763
  continue;
741
764
  }
742
765
  processedLines.push(line);
@@ -748,16 +771,22 @@ function parseTextStyles(input) {
748
771
  yellow: TextStyle.Yellow,
749
772
  green: TextStyle.Green,
750
773
  small: TextStyle.Small,
751
- big: TextStyle.Big
774
+ big: TextStyle.Big,
775
+ underline: TextStyle.Underline
752
776
  };
753
777
  const tagNames = Object.keys(colorMap).join("|");
754
778
  const markers = [
755
779
  // Tags first so inner markdown markers are preserved for subsequent passes
756
780
  { pattern: new RegExp(`\\{(${tagNames})\\}(.+?)\\{/\\1\\}`, "g"), style: null },
781
+ // *** = bold + italic
757
782
  { pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold, extraStyles: [TextStyle.Italic] },
783
+ // ** and __ = bold (standard markdown)
758
784
  { pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
785
+ { pattern: /__(.+?)__/g, style: TextStyle.Bold },
786
+ // * and _ = italic (standard markdown)
759
787
  { pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
760
- { pattern: /__(.+?)__/g, style: TextStyle.Underline },
788
+ { pattern: /_(.+?)_/g, style: TextStyle.Italic },
789
+ // ~~ = strikethrough
761
790
  { pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
762
791
  ];
763
792
  let segments = [{ text: inlineInput, styles: [] }];
@@ -797,6 +826,28 @@ function parseTextStyles(input) {
797
826
  allStyles.push({ start, len: seg.text.length, st });
798
827
  }
799
828
  }
829
+ if (escapeMap.length > 0) {
830
+ const escRegex = /\x01(\d+)\x02/g;
831
+ const shifts = [];
832
+ let cumDelta = 0;
833
+ for (const m of plainText.matchAll(escRegex)) {
834
+ const idx = parseInt(m[1], 10);
835
+ cumDelta += m[0].length - escapeMap[idx].length;
836
+ shifts.push({ pos: m.index + m[0].length, delta: cumDelta });
837
+ }
838
+ for (const s of allStyles) {
839
+ let startDelta = 0;
840
+ let endDelta = 0;
841
+ const end = s.start + s.len;
842
+ for (const sh of shifts) {
843
+ if (sh.pos <= s.start) startDelta = sh.delta;
844
+ if (sh.pos <= end) endDelta = sh.delta;
845
+ }
846
+ s.start -= startDelta;
847
+ s.len -= endDelta - startDelta;
848
+ }
849
+ plainText = plainText.replace(escRegex, (_m, idxStr) => escapeMap[parseInt(idxStr, 10)]);
850
+ }
800
851
  const finalLines = plainText.split("\n");
801
852
  let offset = 0;
802
853
  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.34",
4
4
  "description": "Open-source zca-compatible CLI to integrate Zalo with OpenClaw",
5
5
  "type": "module",
6
6
  "bin": {