openzca 0.1.36 → 0.1.38
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 +268 -223
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
Gender,
|
|
16
16
|
Reactions,
|
|
17
17
|
ReviewPendingMemberRequestStatus,
|
|
18
|
-
TextStyle,
|
|
19
18
|
ThreadType
|
|
20
19
|
} from "zca-js";
|
|
21
20
|
|
|
@@ -579,6 +578,273 @@ async function assertFilesExist(files) {
|
|
|
579
578
|
}
|
|
580
579
|
}
|
|
581
580
|
|
|
581
|
+
// src/lib/text-styles.ts
|
|
582
|
+
import { TextStyle } from "zca-js";
|
|
583
|
+
var TAG_STYLE_MAP = {
|
|
584
|
+
red: TextStyle.Red,
|
|
585
|
+
orange: TextStyle.Orange,
|
|
586
|
+
yellow: TextStyle.Yellow,
|
|
587
|
+
green: TextStyle.Green,
|
|
588
|
+
small: TextStyle.Small,
|
|
589
|
+
big: TextStyle.Big,
|
|
590
|
+
underline: TextStyle.Underline
|
|
591
|
+
};
|
|
592
|
+
var INLINE_MARKERS = [
|
|
593
|
+
{
|
|
594
|
+
pattern: new RegExp(`\\{(${Object.keys(TAG_STYLE_MAP).join("|")})\\}(.+?)\\{/\\1\\}`, "g"),
|
|
595
|
+
style: null
|
|
596
|
+
},
|
|
597
|
+
{ pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold, extraStyles: [TextStyle.Italic] },
|
|
598
|
+
{ pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
|
|
599
|
+
{ pattern: /(?<!\w)__(.+?)__(?!\w)/g, style: TextStyle.Bold },
|
|
600
|
+
{ pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
|
|
601
|
+
{ pattern: /(?<!\w)_(.+?)_(?!\w)/g, style: TextStyle.Italic },
|
|
602
|
+
{ pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
|
|
603
|
+
];
|
|
604
|
+
function parseTextStyles(input) {
|
|
605
|
+
const allStyles = [];
|
|
606
|
+
const codeLineIndices = extractCodeBlockLines(input);
|
|
607
|
+
input = stripCodeFences(input);
|
|
608
|
+
const escapeMap = [];
|
|
609
|
+
const escapedInput = input.replace(/\\([*_~#\\{}>+\-])/g, (_match, ch) => {
|
|
610
|
+
const index = escapeMap.length;
|
|
611
|
+
escapeMap.push(ch);
|
|
612
|
+
return `${index}`;
|
|
613
|
+
});
|
|
614
|
+
const lines = escapedInput.split("\n");
|
|
615
|
+
const lineStyles = [];
|
|
616
|
+
const processedLines = [];
|
|
617
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
|
|
618
|
+
let line = lines[lineIndex];
|
|
619
|
+
if (codeLineIndices.has(lineIndex)) {
|
|
620
|
+
processedLines.push(line);
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
const headingMatch = line.match(/^(#{1,4})\s(.*)$/);
|
|
624
|
+
if (headingMatch) {
|
|
625
|
+
const depth = headingMatch[1].length;
|
|
626
|
+
lineStyles.push({ lineIndex, style: TextStyle.Bold });
|
|
627
|
+
if (depth === 1) {
|
|
628
|
+
lineStyles.push({ lineIndex, style: TextStyle.Big });
|
|
629
|
+
} else if (depth === 3 || depth === 4) {
|
|
630
|
+
lineStyles.push({ lineIndex, style: TextStyle.Small });
|
|
631
|
+
}
|
|
632
|
+
processedLines.push(headingMatch[2]);
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
const quoteMatch = line.match(/^(>+)\s?(.*)$/);
|
|
636
|
+
if (quoteMatch) {
|
|
637
|
+
lineStyles.push({
|
|
638
|
+
lineIndex,
|
|
639
|
+
style: TextStyle.Indent,
|
|
640
|
+
indentSize: Math.min(5, quoteMatch[1].length)
|
|
641
|
+
});
|
|
642
|
+
line = quoteMatch[2];
|
|
643
|
+
}
|
|
644
|
+
const indentMatch = line.match(/^(\s+)(.*)$/);
|
|
645
|
+
let indentLevel = 0;
|
|
646
|
+
let content = line;
|
|
647
|
+
if (indentMatch) {
|
|
648
|
+
indentLevel = clampIndent(indentMatch[1].length);
|
|
649
|
+
content = indentMatch[2];
|
|
650
|
+
}
|
|
651
|
+
if (/^[-*+]\s\[[ xX]\]\s/.test(content)) {
|
|
652
|
+
if (indentLevel > 0) {
|
|
653
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
|
|
654
|
+
}
|
|
655
|
+
processedLines.push(content);
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
const orderedListMatch = content.match(/^(\d+)\.\s(.*)$/);
|
|
659
|
+
if (orderedListMatch) {
|
|
660
|
+
if (indentLevel > 0) {
|
|
661
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
|
|
662
|
+
}
|
|
663
|
+
lineStyles.push({ lineIndex, style: TextStyle.OrderedList });
|
|
664
|
+
processedLines.push(orderedListMatch[2]);
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
const unorderedListMatch = content.match(/^[-*+]\s(.*)$/);
|
|
668
|
+
if (unorderedListMatch) {
|
|
669
|
+
if (indentLevel > 0) {
|
|
670
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
|
|
671
|
+
}
|
|
672
|
+
lineStyles.push({ lineIndex, style: TextStyle.UnorderedList });
|
|
673
|
+
processedLines.push(unorderedListMatch[1]);
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
if (indentLevel > 0) {
|
|
677
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: indentLevel });
|
|
678
|
+
processedLines.push(content);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
processedLines.push(line);
|
|
682
|
+
}
|
|
683
|
+
for (const codeLineIndex of codeLineIndices) {
|
|
684
|
+
if (codeLineIndex >= processedLines.length) {
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
processedLines[codeLineIndex] = processedLines[codeLineIndex].replace(/[*_~{}]/g, (ch) => {
|
|
688
|
+
const index = escapeMap.length;
|
|
689
|
+
escapeMap.push(ch);
|
|
690
|
+
return `${index}`;
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
let segments = [{ text: processedLines.join("\n"), styles: [] }];
|
|
694
|
+
for (const marker of INLINE_MARKERS) {
|
|
695
|
+
const nextSegments = [];
|
|
696
|
+
for (const segment of segments) {
|
|
697
|
+
let lastIndex = 0;
|
|
698
|
+
const regex = new RegExp(marker.pattern.source, marker.pattern.flags);
|
|
699
|
+
let match;
|
|
700
|
+
while ((match = regex.exec(segment.text)) !== null) {
|
|
701
|
+
if (match.index > lastIndex) {
|
|
702
|
+
nextSegments.push({
|
|
703
|
+
text: segment.text.slice(lastIndex, match.index),
|
|
704
|
+
styles: [...segment.styles]
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
const isTagPattern = marker.style === null;
|
|
708
|
+
const innerText = isTagPattern ? match[2] : match[1];
|
|
709
|
+
const resolvedStyle = isTagPattern ? TAG_STYLE_MAP[match[1]] : marker.style;
|
|
710
|
+
const combinedStyles = [...segment.styles];
|
|
711
|
+
if (resolvedStyle) {
|
|
712
|
+
combinedStyles.push(resolvedStyle);
|
|
713
|
+
}
|
|
714
|
+
if (marker.extraStyles) {
|
|
715
|
+
combinedStyles.push(...marker.extraStyles);
|
|
716
|
+
}
|
|
717
|
+
nextSegments.push({
|
|
718
|
+
text: innerText,
|
|
719
|
+
styles: combinedStyles
|
|
720
|
+
});
|
|
721
|
+
lastIndex = regex.lastIndex;
|
|
722
|
+
}
|
|
723
|
+
if (lastIndex < segment.text.length) {
|
|
724
|
+
nextSegments.push({
|
|
725
|
+
text: segment.text.slice(lastIndex),
|
|
726
|
+
styles: [...segment.styles]
|
|
727
|
+
});
|
|
728
|
+
} else if (lastIndex === 0) {
|
|
729
|
+
nextSegments.push(segment);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
segments = nextSegments;
|
|
733
|
+
}
|
|
734
|
+
let plainText = "";
|
|
735
|
+
for (const segment of segments) {
|
|
736
|
+
const start = plainText.length;
|
|
737
|
+
plainText += segment.text;
|
|
738
|
+
for (const style of segment.styles) {
|
|
739
|
+
allStyles.push({ start, len: segment.text.length, st: style });
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
const orphanMatches = [...plainText.matchAll(/\*([^*\n]+?)\*/g)];
|
|
743
|
+
for (let index = orphanMatches.length - 1; index >= 0; index -= 1) {
|
|
744
|
+
const match = orphanMatches[index];
|
|
745
|
+
const openPos = match.index ?? 0;
|
|
746
|
+
const content = match[1];
|
|
747
|
+
const closePos = openPos + content.length + 1;
|
|
748
|
+
allStyles.push({ start: openPos + 1, len: content.length, st: TextStyle.Italic });
|
|
749
|
+
plainText = plainText.slice(0, closePos) + plainText.slice(closePos + 1);
|
|
750
|
+
plainText = plainText.slice(0, openPos) + plainText.slice(openPos + 1);
|
|
751
|
+
for (const style of allStyles) {
|
|
752
|
+
if (style.start > closePos) {
|
|
753
|
+
style.start -= 1;
|
|
754
|
+
} else if (style.start + style.len > closePos) {
|
|
755
|
+
style.len -= 1;
|
|
756
|
+
}
|
|
757
|
+
if (style.start > openPos) {
|
|
758
|
+
style.start -= 1;
|
|
759
|
+
} else if (style.start + style.len > openPos) {
|
|
760
|
+
style.len -= 1;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
if (escapeMap.length > 0) {
|
|
765
|
+
const escapeRegex = /\x01(\d+)\x02/g;
|
|
766
|
+
const shifts = [];
|
|
767
|
+
let cumulativeDelta = 0;
|
|
768
|
+
for (const match of plainText.matchAll(escapeRegex)) {
|
|
769
|
+
const escapeIndex = Number.parseInt(match[1], 10);
|
|
770
|
+
cumulativeDelta += match[0].length - escapeMap[escapeIndex].length;
|
|
771
|
+
shifts.push({ pos: (match.index ?? 0) + match[0].length, delta: cumulativeDelta });
|
|
772
|
+
}
|
|
773
|
+
for (const style of allStyles) {
|
|
774
|
+
let startDelta = 0;
|
|
775
|
+
let endDelta = 0;
|
|
776
|
+
const end = style.start + style.len;
|
|
777
|
+
for (const shift of shifts) {
|
|
778
|
+
if (shift.pos <= style.start) {
|
|
779
|
+
startDelta = shift.delta;
|
|
780
|
+
}
|
|
781
|
+
if (shift.pos <= end) {
|
|
782
|
+
endDelta = shift.delta;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
style.start -= startDelta;
|
|
786
|
+
style.len -= endDelta - startDelta;
|
|
787
|
+
}
|
|
788
|
+
plainText = plainText.replace(escapeRegex, (_match, index) => escapeMap[Number.parseInt(index, 10)]);
|
|
789
|
+
}
|
|
790
|
+
const finalLines = plainText.split("\n");
|
|
791
|
+
let offset = 0;
|
|
792
|
+
for (let lineIndex = 0; lineIndex < finalLines.length; lineIndex += 1) {
|
|
793
|
+
const lineLength = finalLines[lineIndex].length;
|
|
794
|
+
if (lineLength > 0) {
|
|
795
|
+
for (const lineStyle of lineStyles) {
|
|
796
|
+
if (lineStyle.lineIndex !== lineIndex) {
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
if (lineStyle.style === TextStyle.Indent) {
|
|
800
|
+
allStyles.push({
|
|
801
|
+
start: offset,
|
|
802
|
+
len: lineLength,
|
|
803
|
+
st: TextStyle.Indent,
|
|
804
|
+
indentSize: lineStyle.indentSize
|
|
805
|
+
});
|
|
806
|
+
} else {
|
|
807
|
+
allStyles.push({ start: offset, len: lineLength, st: lineStyle.style });
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
offset += lineLength + 1;
|
|
812
|
+
}
|
|
813
|
+
return { text: plainText, styles: allStyles };
|
|
814
|
+
}
|
|
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
|
+
function clampIndent(spaceCount) {
|
|
845
|
+
return Math.min(5, Math.max(1, Math.floor(spaceCount / 2)));
|
|
846
|
+
}
|
|
847
|
+
|
|
582
848
|
// src/cli.ts
|
|
583
849
|
var require2 = createRequire(import.meta.url);
|
|
584
850
|
var { version: PKG_VERSION } = require2("../package.json");
|
|
@@ -705,227 +971,6 @@ function output(value, asJson = false) {
|
|
|
705
971
|
function asThreadType(groupFlag) {
|
|
706
972
|
return groupFlag ? ThreadType.Group : ThreadType.User;
|
|
707
973
|
}
|
|
708
|
-
function parseTextStyles(input) {
|
|
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
|
-
}
|
|
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");
|
|
734
|
-
const lineStyles = [];
|
|
735
|
-
const processedLines = [];
|
|
736
|
-
for (let i = 0; i < lines.length; i++) {
|
|
737
|
-
let line = lines[i];
|
|
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(.*)$/);
|
|
750
|
-
if (headingMatch) {
|
|
751
|
-
const level = headingMatch[1].length;
|
|
752
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.Bold });
|
|
753
|
-
if (level === 1) lineStyles.push({ lineIndex: i, style: TextStyle.Big });
|
|
754
|
-
else if (level === 3 || level === 4) lineStyles.push({ lineIndex: i, style: TextStyle.Small });
|
|
755
|
-
processedLines.push(headingMatch[2]);
|
|
756
|
-
continue;
|
|
757
|
-
}
|
|
758
|
-
const bqMatch = line.match(/^(>+)\s?(.*)$/);
|
|
759
|
-
if (bqMatch) {
|
|
760
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: Math.min(5, bqMatch[1].length) });
|
|
761
|
-
line = bqMatch[2];
|
|
762
|
-
}
|
|
763
|
-
const indentContentMatch = line.match(/^(\s+)(.*)$/);
|
|
764
|
-
let indentLevel = 0;
|
|
765
|
-
let content = line;
|
|
766
|
-
if (indentContentMatch) {
|
|
767
|
-
indentLevel = Math.min(5, Math.max(1, Math.floor(indentContentMatch[1].length / 2)));
|
|
768
|
-
content = indentContentMatch[2];
|
|
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
|
-
}
|
|
777
|
-
const olMatch = content.match(/^(\d+)\.\s(.*)$/);
|
|
778
|
-
if (olMatch) {
|
|
779
|
-
if (indentLevel > 0) {
|
|
780
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
|
|
781
|
-
}
|
|
782
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.OrderedList });
|
|
783
|
-
processedLines.push(olMatch[2]);
|
|
784
|
-
continue;
|
|
785
|
-
}
|
|
786
|
-
const ulMatch = content.match(/^[-*+]\s(.*)$/);
|
|
787
|
-
if (ulMatch) {
|
|
788
|
-
if (indentLevel > 0) {
|
|
789
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
|
|
790
|
-
}
|
|
791
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.UnorderedList });
|
|
792
|
-
processedLines.push(ulMatch[1]);
|
|
793
|
-
continue;
|
|
794
|
-
}
|
|
795
|
-
if (indentLevel > 0) {
|
|
796
|
-
lineStyles.push({ lineIndex: i, style: TextStyle.Indent, indentSize: indentLevel });
|
|
797
|
-
processedLines.push(content);
|
|
798
|
-
continue;
|
|
799
|
-
}
|
|
800
|
-
processedLines.push(line);
|
|
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
|
-
}
|
|
811
|
-
const inlineInput = processedLines.join("\n");
|
|
812
|
-
const colorMap = {
|
|
813
|
-
red: TextStyle.Red,
|
|
814
|
-
orange: TextStyle.Orange,
|
|
815
|
-
yellow: TextStyle.Yellow,
|
|
816
|
-
green: TextStyle.Green,
|
|
817
|
-
small: TextStyle.Small,
|
|
818
|
-
big: TextStyle.Big,
|
|
819
|
-
underline: TextStyle.Underline
|
|
820
|
-
};
|
|
821
|
-
const tagNames = Object.keys(colorMap).join("|");
|
|
822
|
-
const markers = [
|
|
823
|
-
// Tags first so inner markdown markers are preserved for subsequent passes
|
|
824
|
-
{ pattern: new RegExp(`\\{(${tagNames})\\}(.+?)\\{/\\1\\}`, "g"), style: null },
|
|
825
|
-
// *** = bold + italic
|
|
826
|
-
{ pattern: /\*\*\*(.+?)\*\*\*/g, style: TextStyle.Bold, extraStyles: [TextStyle.Italic] },
|
|
827
|
-
// ** and __ = bold (standard markdown; __ requires word boundaries)
|
|
828
|
-
{ pattern: /\*\*(.+?)\*\*/g, style: TextStyle.Bold },
|
|
829
|
-
{ pattern: /(?<!\w)__(.+?)__(?!\w)/g, style: TextStyle.Bold },
|
|
830
|
-
// * and _ = italic (_ requires word boundaries to avoid snake_case)
|
|
831
|
-
{ pattern: /\*(.+?)\*/g, style: TextStyle.Italic },
|
|
832
|
-
{ pattern: /(?<!\w)_(.+?)_(?!\w)/g, style: TextStyle.Italic },
|
|
833
|
-
// ~~ = strikethrough
|
|
834
|
-
{ pattern: /~~(.+?)~~/g, style: TextStyle.StrikeThrough }
|
|
835
|
-
];
|
|
836
|
-
let segments = [{ text: inlineInput, styles: [] }];
|
|
837
|
-
for (const marker of markers) {
|
|
838
|
-
const next = [];
|
|
839
|
-
for (const seg of segments) {
|
|
840
|
-
let lastIndex = 0;
|
|
841
|
-
const regex = new RegExp(marker.pattern.source, marker.pattern.flags);
|
|
842
|
-
let m;
|
|
843
|
-
while ((m = regex.exec(seg.text)) !== null) {
|
|
844
|
-
if (m.index > lastIndex) {
|
|
845
|
-
next.push({ text: seg.text.slice(lastIndex, m.index), styles: [...seg.styles] });
|
|
846
|
-
}
|
|
847
|
-
const isTagPattern = marker.style === null;
|
|
848
|
-
const innerText = isTagPattern ? m[2] : m[1];
|
|
849
|
-
const resolvedStyle = isTagPattern ? colorMap[m[1]] : marker.style;
|
|
850
|
-
const combined = [...seg.styles, resolvedStyle];
|
|
851
|
-
if (marker.extraStyles) {
|
|
852
|
-
combined.push(...marker.extraStyles);
|
|
853
|
-
}
|
|
854
|
-
next.push({ text: innerText, styles: combined });
|
|
855
|
-
lastIndex = regex.lastIndex;
|
|
856
|
-
}
|
|
857
|
-
if (lastIndex < seg.text.length) {
|
|
858
|
-
next.push({ text: seg.text.slice(lastIndex), styles: [...seg.styles] });
|
|
859
|
-
} else if (lastIndex === 0) {
|
|
860
|
-
next.push(seg);
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
segments = next;
|
|
864
|
-
}
|
|
865
|
-
let plainText = "";
|
|
866
|
-
for (const seg of segments) {
|
|
867
|
-
const start = plainText.length;
|
|
868
|
-
plainText += seg.text;
|
|
869
|
-
for (const st of seg.styles) {
|
|
870
|
-
allStyles.push({ start, len: seg.text.length, st });
|
|
871
|
-
}
|
|
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
|
-
}
|
|
890
|
-
if (escapeMap.length > 0) {
|
|
891
|
-
const escRegex = /\x01(\d+)\x02/g;
|
|
892
|
-
const shifts = [];
|
|
893
|
-
let cumDelta = 0;
|
|
894
|
-
for (const m of plainText.matchAll(escRegex)) {
|
|
895
|
-
const idx = parseInt(m[1], 10);
|
|
896
|
-
cumDelta += m[0].length - escapeMap[idx].length;
|
|
897
|
-
shifts.push({ pos: m.index + m[0].length, delta: cumDelta });
|
|
898
|
-
}
|
|
899
|
-
for (const s of allStyles) {
|
|
900
|
-
let startDelta = 0;
|
|
901
|
-
let endDelta = 0;
|
|
902
|
-
const end = s.start + s.len;
|
|
903
|
-
for (const sh of shifts) {
|
|
904
|
-
if (sh.pos <= s.start) startDelta = sh.delta;
|
|
905
|
-
if (sh.pos <= end) endDelta = sh.delta;
|
|
906
|
-
}
|
|
907
|
-
s.start -= startDelta;
|
|
908
|
-
s.len -= endDelta - startDelta;
|
|
909
|
-
}
|
|
910
|
-
plainText = plainText.replace(escRegex, (_m, idxStr) => escapeMap[parseInt(idxStr, 10)]);
|
|
911
|
-
}
|
|
912
|
-
const finalLines = plainText.split("\n");
|
|
913
|
-
let offset = 0;
|
|
914
|
-
for (let i = 0; i < finalLines.length; i++) {
|
|
915
|
-
const lineLen = finalLines[i].length;
|
|
916
|
-
for (const ls of lineStyles) {
|
|
917
|
-
if (ls.lineIndex === i && lineLen > 0) {
|
|
918
|
-
if (ls.style === TextStyle.Indent) {
|
|
919
|
-
allStyles.push({ start: offset, len: lineLen, st: TextStyle.Indent, indentSize: ls.indentSize });
|
|
920
|
-
} else {
|
|
921
|
-
allStyles.push({ start: offset, len: lineLen, st: ls.style });
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
offset += lineLen + 1;
|
|
926
|
-
}
|
|
927
|
-
return { text: plainText, styles: allStyles };
|
|
928
|
-
}
|
|
929
974
|
function parseBooleanFromEnv(name, fallback) {
|
|
930
975
|
const raw = process.env[name]?.trim();
|
|
931
976
|
if (!raw) return fallback;
|
|
@@ -3109,7 +3154,7 @@ auth.command("cache-clear").description("Clear local cache").action(
|
|
|
3109
3154
|
})
|
|
3110
3155
|
);
|
|
3111
3156
|
var msg = program.command("msg").description("Messaging commands");
|
|
3112
|
-
msg.command("send <threadId> <message>").option("-g, --group", "Send to group").option("--raw", "Send raw text without parsing formatting markers").description("Send text message with formatting (**bold** *italic*
|
|
3157
|
+
msg.command("send <threadId> <message>").option("-g, --group", "Send to group").option("--raw", "Send raw text without parsing formatting markers").description("Send text message with formatting (**bold** *italic* __bold__ ~~strike~~ {underline}text{/underline} {red}color{/red} {big}size{/big} lists indents)").action(
|
|
3113
3158
|
wrapAction(async (threadId, message, opts, command) => {
|
|
3114
3159
|
const { api } = await requireApi(command);
|
|
3115
3160
|
if (opts.raw) {
|