openzca 0.1.34 → 0.1.36
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/cli.js +69 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -707,6 +707,23 @@ function asThreadType(groupFlag) {
|
|
|
707
707
|
}
|
|
708
708
|
function parseTextStyles(input) {
|
|
709
709
|
const allStyles = [];
|
|
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
|
+
}
|
|
710
727
|
const escapeMap = [];
|
|
711
728
|
const escaped = input.replace(/\\([*_~#\\{}>+\-])/g, (_match, ch) => {
|
|
712
729
|
const idx = escapeMap.length;
|
|
@@ -718,27 +735,45 @@ function parseTextStyles(input) {
|
|
|
718
735
|
const processedLines = [];
|
|
719
736
|
for (let i = 0; i < lines.length; i++) {
|
|
720
737
|
let line = lines[i];
|
|
721
|
-
|
|
738
|
+
if (codeLineIndices.has(i)) {
|
|
739
|
+
const codeIndentMatch = line.match(/^(\s+)(.*)$/);
|
|
740
|
+
if (codeIndentMatch) {
|
|
741
|
+
const codeIndent = Math.min(5, Math.max(1, Math.floor(codeIndentMatch[1].length / 2)));
|
|
742
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: codeIndent });
|
|
743
|
+
processedLines.push(codeIndentMatch[2]);
|
|
744
|
+
} else {
|
|
745
|
+
processedLines.push(line);
|
|
746
|
+
}
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
const headingMatch = line.match(/^(#{1,4})\s(.*)$/);
|
|
722
750
|
if (headingMatch) {
|
|
723
751
|
const level = headingMatch[1].length;
|
|
724
752
|
lineStyles.push({ lineIndex: i, style: TextStyle.Bold });
|
|
725
753
|
if (level === 1) lineStyles.push({ lineIndex: i, style: TextStyle.Big });
|
|
726
|
-
else if (level
|
|
754
|
+
else if (level === 3 || level === 4) lineStyles.push({ lineIndex: i, style: TextStyle.Small });
|
|
727
755
|
processedLines.push(headingMatch[2]);
|
|
728
756
|
continue;
|
|
729
757
|
}
|
|
730
758
|
const bqMatch = line.match(/^(>+)\s?(.*)$/);
|
|
731
759
|
if (bqMatch) {
|
|
732
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: bqMatch[1].length });
|
|
760
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: Math.min(5, bqMatch[1].length) });
|
|
733
761
|
line = bqMatch[2];
|
|
734
762
|
}
|
|
735
763
|
const indentContentMatch = line.match(/^(\s+)(.*)$/);
|
|
736
764
|
let indentLevel = 0;
|
|
737
765
|
let content = line;
|
|
738
766
|
if (indentContentMatch) {
|
|
739
|
-
indentLevel = Math.max(1, Math.floor(indentContentMatch[1].length / 2));
|
|
767
|
+
indentLevel = Math.min(5, Math.max(1, Math.floor(indentContentMatch[1].length / 2)));
|
|
740
768
|
content = indentContentMatch[2];
|
|
741
769
|
}
|
|
770
|
+
if (/^[-*+]\s\[[ xX]\]\s/.test(content)) {
|
|
771
|
+
if (indentLevel > 0) {
|
|
772
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
|
|
773
|
+
}
|
|
774
|
+
processedLines.push(content);
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
742
777
|
const olMatch = content.match(/^(\d+)\.\s(.*)$/);
|
|
743
778
|
if (olMatch) {
|
|
744
779
|
if (indentLevel > 0) {
|
|
@@ -764,6 +799,15 @@ function parseTextStyles(input) {
|
|
|
764
799
|
}
|
|
765
800
|
processedLines.push(line);
|
|
766
801
|
}
|
|
802
|
+
for (const ci of codeLineIndices) {
|
|
803
|
+
if (ci < processedLines.length) {
|
|
804
|
+
processedLines[ci] = processedLines[ci].replace(/[*_~{}]/g, (ch) => {
|
|
805
|
+
const idx = escapeMap.length;
|
|
806
|
+
escapeMap.push(ch);
|
|
807
|
+
return `${idx}`;
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
}
|
|
767
811
|
const inlineInput = processedLines.join("\n");
|
|
768
812
|
const colorMap = {
|
|
769
813
|
red: TextStyle.Red,
|
|
@@ -780,12 +824,12 @@ function parseTextStyles(input) {
|
|
|
780
824
|
{ pattern: new RegExp(`\\{(${tagNames})\\}(.+?)\\{/\\1\\}`, "g"), style: null },
|
|
781
825
|
// *** = bold + italic
|
|
782
826
|
{ pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold, extraStyles: [TextStyle.Italic] },
|
|
783
|
-
// ** and __ = bold (standard markdown)
|
|
827
|
+
// ** and __ = bold (standard markdown; __ requires word boundaries)
|
|
784
828
|
{ pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
|
|
785
|
-
{ pattern: /__(.+?)__/g, style: TextStyle.Bold },
|
|
786
|
-
// * and _ = italic (
|
|
829
|
+
{ pattern: /(?<!\w)__(.+?)__(?!\w)/g, style: TextStyle.Bold },
|
|
830
|
+
// * and _ = italic (_ requires word boundaries to avoid snake_case)
|
|
787
831
|
{ pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
|
|
788
|
-
{ pattern: /_(.+?)_/g, style: TextStyle.Italic },
|
|
832
|
+
{ pattern: /(?<!\w)_(.+?)_(?!\w)/g, style: TextStyle.Italic },
|
|
789
833
|
// ~~ = strikethrough
|
|
790
834
|
{ pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
|
|
791
835
|
];
|
|
@@ -826,6 +870,23 @@ function parseTextStyles(input) {
|
|
|
826
870
|
allStyles.push({ start, len: seg.text.length, st });
|
|
827
871
|
}
|
|
828
872
|
}
|
|
873
|
+
const orphanRegex = /\*([^*\n]+?)\*/g;
|
|
874
|
+
const orphanMatches = [...plainText.matchAll(orphanRegex)];
|
|
875
|
+
for (let oi = orphanMatches.length - 1; oi >= 0; oi--) {
|
|
876
|
+
const om = orphanMatches[oi];
|
|
877
|
+
const openPos = om.index;
|
|
878
|
+
const content = om[1];
|
|
879
|
+
const closePos = openPos + content.length + 1;
|
|
880
|
+
allStyles.push({ start: openPos + 1, len: content.length, st: TextStyle.Italic });
|
|
881
|
+
plainText = plainText.slice(0, closePos) + plainText.slice(closePos + 1);
|
|
882
|
+
plainText = plainText.slice(0, openPos) + plainText.slice(openPos + 1);
|
|
883
|
+
for (const s of allStyles) {
|
|
884
|
+
if (s.start > closePos) s.start--;
|
|
885
|
+
else if (s.start + s.len > closePos) s.len--;
|
|
886
|
+
if (s.start > openPos) s.start--;
|
|
887
|
+
else if (s.start + s.len > openPos) s.len--;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
829
890
|
if (escapeMap.length > 0) {
|
|
830
891
|
const escRegex = /\x01(\d+)\x02/g;
|
|
831
892
|
const shifts = [];
|