openzca 0.1.35 → 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 +40 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -736,7 +736,14 @@ function parseTextStyles(input) {
|
|
|
736
736
|
for (let i = 0; i < lines.length; i++) {
|
|
737
737
|
let line = lines[i];
|
|
738
738
|
if (codeLineIndices.has(i)) {
|
|
739
|
-
|
|
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
|
+
}
|
|
740
747
|
continue;
|
|
741
748
|
}
|
|
742
749
|
const headingMatch = line.match(/^(#{1,4})\s(.*)$/);
|
|
@@ -750,18 +757,21 @@ function parseTextStyles(input) {
|
|
|
750
757
|
}
|
|
751
758
|
const bqMatch = line.match(/^(>+)\s?(.*)$/);
|
|
752
759
|
if (bqMatch) {
|
|
753
|
-
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) });
|
|
754
761
|
line = bqMatch[2];
|
|
755
762
|
}
|
|
756
763
|
const indentContentMatch = line.match(/^(\s+)(.*)$/);
|
|
757
764
|
let indentLevel = 0;
|
|
758
765
|
let content = line;
|
|
759
766
|
if (indentContentMatch) {
|
|
760
|
-
indentLevel = Math.max(1, Math.floor(indentContentMatch[1].length / 2));
|
|
767
|
+
indentLevel = Math.min(5, Math.max(1, Math.floor(indentContentMatch[1].length / 2)));
|
|
761
768
|
content = indentContentMatch[2];
|
|
762
769
|
}
|
|
763
770
|
if (/^[-*+]\s\[[ xX]\]\s/.test(content)) {
|
|
764
|
-
|
|
771
|
+
if (indentLevel > 0) {
|
|
772
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
|
|
773
|
+
}
|
|
774
|
+
processedLines.push(content);
|
|
765
775
|
continue;
|
|
766
776
|
}
|
|
767
777
|
const olMatch = content.match(/^(\d+)\.\s(.*)$/);
|
|
@@ -782,6 +792,11 @@ function parseTextStyles(input) {
|
|
|
782
792
|
processedLines.push(ulMatch[1]);
|
|
783
793
|
continue;
|
|
784
794
|
}
|
|
795
|
+
if (indentLevel > 0) {
|
|
796
|
+
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
|
|
797
|
+
processedLines.push(content);
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
785
800
|
processedLines.push(line);
|
|
786
801
|
}
|
|
787
802
|
for (const ci of codeLineIndices) {
|
|
@@ -809,12 +824,12 @@ function parseTextStyles(input) {
|
|
|
809
824
|
{ pattern: new RegExp(`\\{(${tagNames})\\}(.+?)\\{/\\1\\}`, "g"), style: null },
|
|
810
825
|
// *** = bold + italic
|
|
811
826
|
{ pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold, extraStyles: [TextStyle.Italic] },
|
|
812
|
-
// ** and __ = bold (standard markdown)
|
|
827
|
+
// ** and __ = bold (standard markdown; __ requires word boundaries)
|
|
813
828
|
{ pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
|
|
814
|
-
{ pattern: /__(.+?)__/g, style: TextStyle.Bold },
|
|
815
|
-
// * and _ = italic (
|
|
829
|
+
{ pattern: /(?<!\w)__(.+?)__(?!\w)/g, style: TextStyle.Bold },
|
|
830
|
+
// * and _ = italic (_ requires word boundaries to avoid snake_case)
|
|
816
831
|
{ pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
|
|
817
|
-
{ pattern: /_(.+?)_/g, style: TextStyle.Italic },
|
|
832
|
+
{ pattern: /(?<!\w)_(.+?)_(?!\w)/g, style: TextStyle.Italic },
|
|
818
833
|
// ~~ = strikethrough
|
|
819
834
|
{ pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
|
|
820
835
|
];
|
|
@@ -855,6 +870,23 @@ function parseTextStyles(input) {
|
|
|
855
870
|
allStyles.push({ start, len: seg.text.length, st });
|
|
856
871
|
}
|
|
857
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
|
+
}
|
|
858
890
|
if (escapeMap.length > 0) {
|
|
859
891
|
const escRegex = /\x01(\d+)\x02/g;
|
|
860
892
|
const shifts = [];
|