openzca 0.1.38 → 0.1.39
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 +28 -46
- 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,20 @@ function parseTextStyles(input) {
|
|
|
614
612
|
const lines = escapedInput.split("\n");
|
|
615
613
|
const lineStyles = [];
|
|
616
614
|
const processedLines = [];
|
|
615
|
+
const codeBlockLineIndices = /* @__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
|
-
|
|
619
|
+
let baseIndent = 0;
|
|
620
|
+
if (/^```/.test(line)) {
|
|
621
|
+
codeBlockLineIndices.add(lineIndex);
|
|
620
622
|
processedLines.push(line);
|
|
623
|
+
inCodeBlock = !inCodeBlock;
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
if (inCodeBlock) {
|
|
627
|
+
codeBlockLineIndices.add(lineIndex);
|
|
628
|
+
processedLines.push(normalizeCodeBlockLeadingWhitespace(line));
|
|
621
629
|
continue;
|
|
622
630
|
}
|
|
623
631
|
const headingMatch = line.match(/^(#{1,4})\s(.*)$/);
|
|
@@ -634,11 +642,7 @@ function parseTextStyles(input) {
|
|
|
634
642
|
}
|
|
635
643
|
const quoteMatch = line.match(/^(>+)\s?(.*)$/);
|
|
636
644
|
if (quoteMatch) {
|
|
637
|
-
|
|
638
|
-
lineIndex,
|
|
639
|
-
style: TextStyle.Indent,
|
|
640
|
-
indentSize: Math.min(5, quoteMatch[1].length)
|
|
641
|
-
});
|
|
645
|
+
baseIndent = Math.min(5, quoteMatch[1].length);
|
|
642
646
|
line = quoteMatch[2];
|
|
643
647
|
}
|
|
644
648
|
const indentMatch = line.match(/^(\s+)(.*)$/);
|
|
@@ -648,17 +652,18 @@ function parseTextStyles(input) {
|
|
|
648
652
|
indentLevel = clampIndent(indentMatch[1].length);
|
|
649
653
|
content = indentMatch[2];
|
|
650
654
|
}
|
|
655
|
+
const totalIndent = Math.min(5, baseIndent + indentLevel);
|
|
651
656
|
if (/^[-*+]\s\[[ xX]\]\s/.test(content)) {
|
|
652
|
-
if (
|
|
653
|
-
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize:
|
|
657
|
+
if (totalIndent > 0) {
|
|
658
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
654
659
|
}
|
|
655
660
|
processedLines.push(content);
|
|
656
661
|
continue;
|
|
657
662
|
}
|
|
658
663
|
const orderedListMatch = content.match(/^(\d+)\.\s(.*)$/);
|
|
659
664
|
if (orderedListMatch) {
|
|
660
|
-
if (
|
|
661
|
-
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize:
|
|
665
|
+
if (totalIndent > 0) {
|
|
666
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
662
667
|
}
|
|
663
668
|
lineStyles.push({ lineIndex, style: TextStyle.OrderedList });
|
|
664
669
|
processedLines.push(orderedListMatch[2]);
|
|
@@ -666,21 +671,21 @@ function parseTextStyles(input) {
|
|
|
666
671
|
}
|
|
667
672
|
const unorderedListMatch = content.match(/^[-*+]\s(.*)$/);
|
|
668
673
|
if (unorderedListMatch) {
|
|
669
|
-
if (
|
|
670
|
-
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize:
|
|
674
|
+
if (totalIndent > 0) {
|
|
675
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
671
676
|
}
|
|
672
677
|
lineStyles.push({ lineIndex, style: TextStyle.UnorderedList });
|
|
673
678
|
processedLines.push(unorderedListMatch[1]);
|
|
674
679
|
continue;
|
|
675
680
|
}
|
|
676
|
-
if (
|
|
677
|
-
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize:
|
|
681
|
+
if (totalIndent > 0) {
|
|
682
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
678
683
|
processedLines.push(content);
|
|
679
684
|
continue;
|
|
680
685
|
}
|
|
681
686
|
processedLines.push(line);
|
|
682
687
|
}
|
|
683
|
-
for (const codeLineIndex of
|
|
688
|
+
for (const codeLineIndex of codeBlockLineIndices) {
|
|
684
689
|
if (codeLineIndex >= processedLines.length) {
|
|
685
690
|
continue;
|
|
686
691
|
}
|
|
@@ -812,38 +817,15 @@ function parseTextStyles(input) {
|
|
|
812
817
|
}
|
|
813
818
|
return { text: plainText, styles: allStyles };
|
|
814
819
|
}
|
|
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
820
|
function clampIndent(spaceCount) {
|
|
845
821
|
return Math.min(5, Math.max(1, Math.floor(spaceCount / 2)));
|
|
846
822
|
}
|
|
823
|
+
function normalizeCodeBlockLeadingWhitespace(line) {
|
|
824
|
+
return line.replace(
|
|
825
|
+
/^[ \t]+/,
|
|
826
|
+
(leadingWhitespace) => leadingWhitespace.replace(/\t/g, "\xA0\xA0\xA0\xA0").replace(/ /g, "\xA0")
|
|
827
|
+
);
|
|
828
|
+
}
|
|
847
829
|
|
|
848
830
|
// src/cli.ts
|
|
849
831
|
var require2 = createRequire(import.meta.url);
|