openzca 0.1.37 → 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 +250 -280
- package/package.json +1 -2
package/dist/cli.js
CHANGED
|
@@ -15,10 +15,8 @@ import {
|
|
|
15
15
|
Gender,
|
|
16
16
|
Reactions,
|
|
17
17
|
ReviewPendingMemberRequestStatus,
|
|
18
|
-
TextStyle,
|
|
19
18
|
ThreadType
|
|
20
19
|
} from "zca-js";
|
|
21
|
-
import { marked } from "marked";
|
|
22
20
|
|
|
23
21
|
// src/lib/store.ts
|
|
24
22
|
import fs from "fs/promises";
|
|
@@ -580,6 +578,255 @@ async function assertFilesExist(files) {
|
|
|
580
578
|
}
|
|
581
579
|
}
|
|
582
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 escapeMap = [];
|
|
607
|
+
const escapedInput = input.replace(/\\([*_~#\\{}>+\-])/g, (_match, ch) => {
|
|
608
|
+
const index = escapeMap.length;
|
|
609
|
+
escapeMap.push(ch);
|
|
610
|
+
return `${index}`;
|
|
611
|
+
});
|
|
612
|
+
const lines = escapedInput.split("\n");
|
|
613
|
+
const lineStyles = [];
|
|
614
|
+
const processedLines = [];
|
|
615
|
+
const codeBlockLineIndices = /* @__PURE__ */ new Set();
|
|
616
|
+
let inCodeBlock = false;
|
|
617
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
|
|
618
|
+
let line = lines[lineIndex];
|
|
619
|
+
let baseIndent = 0;
|
|
620
|
+
if (/^```/.test(line)) {
|
|
621
|
+
codeBlockLineIndices.add(lineIndex);
|
|
622
|
+
processedLines.push(line);
|
|
623
|
+
inCodeBlock = !inCodeBlock;
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
if (inCodeBlock) {
|
|
627
|
+
codeBlockLineIndices.add(lineIndex);
|
|
628
|
+
processedLines.push(normalizeCodeBlockLeadingWhitespace(line));
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
const headingMatch = line.match(/^(#{1,4})\s(.*)$/);
|
|
632
|
+
if (headingMatch) {
|
|
633
|
+
const depth = headingMatch[1].length;
|
|
634
|
+
lineStyles.push({ lineIndex, style: TextStyle.Bold });
|
|
635
|
+
if (depth === 1) {
|
|
636
|
+
lineStyles.push({ lineIndex, style: TextStyle.Big });
|
|
637
|
+
} else if (depth === 3 || depth === 4) {
|
|
638
|
+
lineStyles.push({ lineIndex, style: TextStyle.Small });
|
|
639
|
+
}
|
|
640
|
+
processedLines.push(headingMatch[2]);
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const quoteMatch = line.match(/^(>+)\s?(.*)$/);
|
|
644
|
+
if (quoteMatch) {
|
|
645
|
+
baseIndent = Math.min(5, quoteMatch[1].length);
|
|
646
|
+
line = quoteMatch[2];
|
|
647
|
+
}
|
|
648
|
+
const indentMatch = line.match(/^(\s+)(.*)$/);
|
|
649
|
+
let indentLevel = 0;
|
|
650
|
+
let content = line;
|
|
651
|
+
if (indentMatch) {
|
|
652
|
+
indentLevel = clampIndent(indentMatch[1].length);
|
|
653
|
+
content = indentMatch[2];
|
|
654
|
+
}
|
|
655
|
+
const totalIndent = Math.min(5, baseIndent + indentLevel);
|
|
656
|
+
if (/^[-*+]\s\[[ xX]\]\s/.test(content)) {
|
|
657
|
+
if (totalIndent > 0) {
|
|
658
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
659
|
+
}
|
|
660
|
+
processedLines.push(content);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
const orderedListMatch = content.match(/^(\d+)\.\s(.*)$/);
|
|
664
|
+
if (orderedListMatch) {
|
|
665
|
+
if (totalIndent > 0) {
|
|
666
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
667
|
+
}
|
|
668
|
+
lineStyles.push({ lineIndex, style: TextStyle.OrderedList });
|
|
669
|
+
processedLines.push(orderedListMatch[2]);
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
const unorderedListMatch = content.match(/^[-*+]\s(.*)$/);
|
|
673
|
+
if (unorderedListMatch) {
|
|
674
|
+
if (totalIndent > 0) {
|
|
675
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
676
|
+
}
|
|
677
|
+
lineStyles.push({ lineIndex, style: TextStyle.UnorderedList });
|
|
678
|
+
processedLines.push(unorderedListMatch[1]);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (totalIndent > 0) {
|
|
682
|
+
lineStyles.push({ lineIndex, style: TextStyle.Indent, indentSize: totalIndent });
|
|
683
|
+
processedLines.push(content);
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
processedLines.push(line);
|
|
687
|
+
}
|
|
688
|
+
for (const codeLineIndex of codeBlockLineIndices) {
|
|
689
|
+
if (codeLineIndex >= processedLines.length) {
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
processedLines[codeLineIndex] = processedLines[codeLineIndex].replace(/[*_~{}]/g, (ch) => {
|
|
693
|
+
const index = escapeMap.length;
|
|
694
|
+
escapeMap.push(ch);
|
|
695
|
+
return `${index}`;
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
let segments = [{ text: processedLines.join("\n"), styles: [] }];
|
|
699
|
+
for (const marker of INLINE_MARKERS) {
|
|
700
|
+
const nextSegments = [];
|
|
701
|
+
for (const segment of segments) {
|
|
702
|
+
let lastIndex = 0;
|
|
703
|
+
const regex = new RegExp(marker.pattern.source, marker.pattern.flags);
|
|
704
|
+
let match;
|
|
705
|
+
while ((match = regex.exec(segment.text)) !== null) {
|
|
706
|
+
if (match.index > lastIndex) {
|
|
707
|
+
nextSegments.push({
|
|
708
|
+
text: segment.text.slice(lastIndex, match.index),
|
|
709
|
+
styles: [...segment.styles]
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
const isTagPattern = marker.style === null;
|
|
713
|
+
const innerText = isTagPattern ? match[2] : match[1];
|
|
714
|
+
const resolvedStyle = isTagPattern ? TAG_STYLE_MAP[match[1]] : marker.style;
|
|
715
|
+
const combinedStyles = [...segment.styles];
|
|
716
|
+
if (resolvedStyle) {
|
|
717
|
+
combinedStyles.push(resolvedStyle);
|
|
718
|
+
}
|
|
719
|
+
if (marker.extraStyles) {
|
|
720
|
+
combinedStyles.push(...marker.extraStyles);
|
|
721
|
+
}
|
|
722
|
+
nextSegments.push({
|
|
723
|
+
text: innerText,
|
|
724
|
+
styles: combinedStyles
|
|
725
|
+
});
|
|
726
|
+
lastIndex = regex.lastIndex;
|
|
727
|
+
}
|
|
728
|
+
if (lastIndex < segment.text.length) {
|
|
729
|
+
nextSegments.push({
|
|
730
|
+
text: segment.text.slice(lastIndex),
|
|
731
|
+
styles: [...segment.styles]
|
|
732
|
+
});
|
|
733
|
+
} else if (lastIndex === 0) {
|
|
734
|
+
nextSegments.push(segment);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
segments = nextSegments;
|
|
738
|
+
}
|
|
739
|
+
let plainText = "";
|
|
740
|
+
for (const segment of segments) {
|
|
741
|
+
const start = plainText.length;
|
|
742
|
+
plainText += segment.text;
|
|
743
|
+
for (const style of segment.styles) {
|
|
744
|
+
allStyles.push({ start, len: segment.text.length, st: style });
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
const orphanMatches = [...plainText.matchAll(/\*([^*\n]+?)\*/g)];
|
|
748
|
+
for (let index = orphanMatches.length - 1; index >= 0; index -= 1) {
|
|
749
|
+
const match = orphanMatches[index];
|
|
750
|
+
const openPos = match.index ?? 0;
|
|
751
|
+
const content = match[1];
|
|
752
|
+
const closePos = openPos + content.length + 1;
|
|
753
|
+
allStyles.push({ start: openPos + 1, len: content.length, st: TextStyle.Italic });
|
|
754
|
+
plainText = plainText.slice(0, closePos) + plainText.slice(closePos + 1);
|
|
755
|
+
plainText = plainText.slice(0, openPos) + plainText.slice(openPos + 1);
|
|
756
|
+
for (const style of allStyles) {
|
|
757
|
+
if (style.start > closePos) {
|
|
758
|
+
style.start -= 1;
|
|
759
|
+
} else if (style.start + style.len > closePos) {
|
|
760
|
+
style.len -= 1;
|
|
761
|
+
}
|
|
762
|
+
if (style.start > openPos) {
|
|
763
|
+
style.start -= 1;
|
|
764
|
+
} else if (style.start + style.len > openPos) {
|
|
765
|
+
style.len -= 1;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
if (escapeMap.length > 0) {
|
|
770
|
+
const escapeRegex = /\x01(\d+)\x02/g;
|
|
771
|
+
const shifts = [];
|
|
772
|
+
let cumulativeDelta = 0;
|
|
773
|
+
for (const match of plainText.matchAll(escapeRegex)) {
|
|
774
|
+
const escapeIndex = Number.parseInt(match[1], 10);
|
|
775
|
+
cumulativeDelta += match[0].length - escapeMap[escapeIndex].length;
|
|
776
|
+
shifts.push({ pos: (match.index ?? 0) + match[0].length, delta: cumulativeDelta });
|
|
777
|
+
}
|
|
778
|
+
for (const style of allStyles) {
|
|
779
|
+
let startDelta = 0;
|
|
780
|
+
let endDelta = 0;
|
|
781
|
+
const end = style.start + style.len;
|
|
782
|
+
for (const shift of shifts) {
|
|
783
|
+
if (shift.pos <= style.start) {
|
|
784
|
+
startDelta = shift.delta;
|
|
785
|
+
}
|
|
786
|
+
if (shift.pos <= end) {
|
|
787
|
+
endDelta = shift.delta;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
style.start -= startDelta;
|
|
791
|
+
style.len -= endDelta - startDelta;
|
|
792
|
+
}
|
|
793
|
+
plainText = plainText.replace(escapeRegex, (_match, index) => escapeMap[Number.parseInt(index, 10)]);
|
|
794
|
+
}
|
|
795
|
+
const finalLines = plainText.split("\n");
|
|
796
|
+
let offset = 0;
|
|
797
|
+
for (let lineIndex = 0; lineIndex < finalLines.length; lineIndex += 1) {
|
|
798
|
+
const lineLength = finalLines[lineIndex].length;
|
|
799
|
+
if (lineLength > 0) {
|
|
800
|
+
for (const lineStyle of lineStyles) {
|
|
801
|
+
if (lineStyle.lineIndex !== lineIndex) {
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
if (lineStyle.style === TextStyle.Indent) {
|
|
805
|
+
allStyles.push({
|
|
806
|
+
start: offset,
|
|
807
|
+
len: lineLength,
|
|
808
|
+
st: TextStyle.Indent,
|
|
809
|
+
indentSize: lineStyle.indentSize
|
|
810
|
+
});
|
|
811
|
+
} else {
|
|
812
|
+
allStyles.push({ start: offset, len: lineLength, st: lineStyle.style });
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
offset += lineLength + 1;
|
|
817
|
+
}
|
|
818
|
+
return { text: plainText, styles: allStyles };
|
|
819
|
+
}
|
|
820
|
+
function clampIndent(spaceCount) {
|
|
821
|
+
return Math.min(5, Math.max(1, Math.floor(spaceCount / 2)));
|
|
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
|
+
}
|
|
829
|
+
|
|
583
830
|
// src/cli.ts
|
|
584
831
|
var require2 = createRequire(import.meta.url);
|
|
585
832
|
var { version: PKG_VERSION } = require2("../package.json");
|
|
@@ -706,283 +953,6 @@ function output(value, asJson = false) {
|
|
|
706
953
|
function asThreadType(groupFlag) {
|
|
707
954
|
return groupFlag ? ThreadType.Group : ThreadType.User;
|
|
708
955
|
}
|
|
709
|
-
function parseTextStyles(input) {
|
|
710
|
-
const tagColorMap = {
|
|
711
|
-
red: TextStyle.Red,
|
|
712
|
-
orange: TextStyle.Orange,
|
|
713
|
-
yellow: TextStyle.Yellow,
|
|
714
|
-
green: TextStyle.Green,
|
|
715
|
-
small: TextStyle.Small,
|
|
716
|
-
big: TextStyle.Big,
|
|
717
|
-
underline: TextStyle.Underline
|
|
718
|
-
};
|
|
719
|
-
const tagNames = Object.keys(tagColorMap).join("|");
|
|
720
|
-
const tagRegex = new RegExp(`\\{(${tagNames})\\}([\\s\\S]+?)\\{/\\1\\}`, "g");
|
|
721
|
-
const tagSlots = [];
|
|
722
|
-
const maskedInput = input.replace(tagRegex, (_m, tagName, inner) => {
|
|
723
|
-
const idx = tagSlots.length;
|
|
724
|
-
const placeholder = `TAG${idx}`;
|
|
725
|
-
tagSlots.push({ placeholder, tagName, innerMd: inner });
|
|
726
|
-
return placeholder;
|
|
727
|
-
});
|
|
728
|
-
const tokens = marked.lexer(maskedInput);
|
|
729
|
-
const styles = [];
|
|
730
|
-
let text = "";
|
|
731
|
-
function emitLineStyles(lineStart, lineLen, lineStyles) {
|
|
732
|
-
if (lineLen <= 0) return;
|
|
733
|
-
for (const ls of lineStyles) {
|
|
734
|
-
if (ls.style === TextStyle.Indent) {
|
|
735
|
-
styles.push({ start: lineStart, len: lineLen, st: ls.style, indentSize: ls.indentSize });
|
|
736
|
-
} else {
|
|
737
|
-
styles.push({ start: lineStart, len: lineLen, st: ls.style });
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
function walkInline(tokens2, inheritedStyles) {
|
|
742
|
-
for (const tok of tokens2) {
|
|
743
|
-
switch (tok.type) {
|
|
744
|
-
case "text": {
|
|
745
|
-
const t = tok;
|
|
746
|
-
if (t.tokens && t.tokens.length > 0) {
|
|
747
|
-
walkInline(t.tokens, inheritedStyles);
|
|
748
|
-
} else {
|
|
749
|
-
const start = text.length;
|
|
750
|
-
text += t.text;
|
|
751
|
-
const len = t.text.length;
|
|
752
|
-
if (len > 0) {
|
|
753
|
-
for (const st of inheritedStyles) {
|
|
754
|
-
styles.push({ start, len, st });
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
break;
|
|
759
|
-
}
|
|
760
|
-
case "strong": {
|
|
761
|
-
const t = tok;
|
|
762
|
-
walkInline(t.tokens, [...inheritedStyles, TextStyle.Bold]);
|
|
763
|
-
break;
|
|
764
|
-
}
|
|
765
|
-
case "em": {
|
|
766
|
-
const t = tok;
|
|
767
|
-
walkInline(t.tokens, [...inheritedStyles, TextStyle.Italic]);
|
|
768
|
-
break;
|
|
769
|
-
}
|
|
770
|
-
case "del": {
|
|
771
|
-
const t = tok;
|
|
772
|
-
walkInline(t.tokens, [...inheritedStyles, TextStyle.StrikeThrough]);
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
case "codespan": {
|
|
776
|
-
const t = tok;
|
|
777
|
-
const start = text.length;
|
|
778
|
-
text += t.text;
|
|
779
|
-
const len = t.text.length;
|
|
780
|
-
if (len > 0) {
|
|
781
|
-
for (const st of inheritedStyles) {
|
|
782
|
-
styles.push({ start, len, st });
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
break;
|
|
786
|
-
}
|
|
787
|
-
case "escape": {
|
|
788
|
-
const t = tok;
|
|
789
|
-
const start = text.length;
|
|
790
|
-
text += t.text;
|
|
791
|
-
if (t.text.length > 0) {
|
|
792
|
-
for (const st of inheritedStyles) {
|
|
793
|
-
styles.push({ start, len: t.text.length, st });
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
break;
|
|
797
|
-
}
|
|
798
|
-
case "link": {
|
|
799
|
-
const t = tok;
|
|
800
|
-
walkInline(t.tokens, inheritedStyles);
|
|
801
|
-
break;
|
|
802
|
-
}
|
|
803
|
-
case "image": {
|
|
804
|
-
const t = tok;
|
|
805
|
-
const start = text.length;
|
|
806
|
-
text += t.text;
|
|
807
|
-
if (t.text.length > 0) {
|
|
808
|
-
for (const st of inheritedStyles) {
|
|
809
|
-
styles.push({ start, len: t.text.length, st });
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
break;
|
|
813
|
-
}
|
|
814
|
-
case "br": {
|
|
815
|
-
text += "\n";
|
|
816
|
-
break;
|
|
817
|
-
}
|
|
818
|
-
case "checkbox": {
|
|
819
|
-
const t = tok;
|
|
820
|
-
text += t.checked ? "[x] " : "[ ] ";
|
|
821
|
-
break;
|
|
822
|
-
}
|
|
823
|
-
default: {
|
|
824
|
-
const t = tok;
|
|
825
|
-
if (t.tokens && t.tokens.length > 0) {
|
|
826
|
-
walkInline(t.tokens, inheritedStyles);
|
|
827
|
-
} else if (t.text != null) {
|
|
828
|
-
const start = text.length;
|
|
829
|
-
text += t.text;
|
|
830
|
-
if (t.text.length > 0) {
|
|
831
|
-
for (const st of inheritedStyles) {
|
|
832
|
-
styles.push({ start, len: t.text.length, st });
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
break;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
function walkBlock(tokens2, blockLineStyles, depth) {
|
|
842
|
-
for (let ti = 0; ti < tokens2.length; ti++) {
|
|
843
|
-
const tok = tokens2[ti];
|
|
844
|
-
switch (tok.type) {
|
|
845
|
-
case "heading": {
|
|
846
|
-
const t = tok;
|
|
847
|
-
const headingStyles = [{ style: TextStyle.Bold }];
|
|
848
|
-
if (t.depth === 1) headingStyles.push({ style: TextStyle.Big });
|
|
849
|
-
else if (t.depth === 3 || t.depth === 4) headingStyles.push({ style: TextStyle.Small });
|
|
850
|
-
if (t.depth <= 4) {
|
|
851
|
-
const lineStart = text.length;
|
|
852
|
-
walkInline(t.tokens, []);
|
|
853
|
-
const lineLen = text.length - lineStart;
|
|
854
|
-
emitLineStyles(lineStart, lineLen, [...blockLineStyles, ...headingStyles]);
|
|
855
|
-
text += "\n";
|
|
856
|
-
} else {
|
|
857
|
-
const lineStart = text.length;
|
|
858
|
-
text += "#".repeat(t.depth) + " ";
|
|
859
|
-
walkInline(t.tokens, []);
|
|
860
|
-
const lineLen = text.length - lineStart;
|
|
861
|
-
emitLineStyles(lineStart, lineLen, blockLineStyles);
|
|
862
|
-
text += "\n";
|
|
863
|
-
}
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
case "paragraph": {
|
|
867
|
-
const t = tok;
|
|
868
|
-
const lineStart = text.length;
|
|
869
|
-
walkInline(t.tokens, []);
|
|
870
|
-
const lineLen = text.length - lineStart;
|
|
871
|
-
emitLineStyles(lineStart, lineLen, blockLineStyles);
|
|
872
|
-
text += "\n";
|
|
873
|
-
break;
|
|
874
|
-
}
|
|
875
|
-
case "code": {
|
|
876
|
-
const t = tok;
|
|
877
|
-
text += t.text;
|
|
878
|
-
text += "\n";
|
|
879
|
-
break;
|
|
880
|
-
}
|
|
881
|
-
case "blockquote": {
|
|
882
|
-
const t = tok;
|
|
883
|
-
const bqDepth = depth + 1;
|
|
884
|
-
walkBlock(t.tokens, [...blockLineStyles, { style: TextStyle.Indent, indentSize: Math.min(5, bqDepth) }], bqDepth);
|
|
885
|
-
break;
|
|
886
|
-
}
|
|
887
|
-
case "list": {
|
|
888
|
-
const t = tok;
|
|
889
|
-
const listStyle = t.ordered ? TextStyle.OrderedList : TextStyle.UnorderedList;
|
|
890
|
-
for (const item of t.items) {
|
|
891
|
-
if (item.task) {
|
|
892
|
-
const lineStart = text.length;
|
|
893
|
-
text += item.checked ? "[x] " : "[ ] ";
|
|
894
|
-
const nonCheckboxTokens = item.tokens.filter((t2) => t2.type !== "checkbox");
|
|
895
|
-
walkInline(nonCheckboxTokens, []);
|
|
896
|
-
const lineLen = text.length - lineStart;
|
|
897
|
-
emitLineStyles(lineStart, lineLen, blockLineStyles);
|
|
898
|
-
text += "\n";
|
|
899
|
-
} else {
|
|
900
|
-
const hasSubList = item.tokens.some((t2) => t2.type === "list");
|
|
901
|
-
if (hasSubList) {
|
|
902
|
-
const inlineTokens = item.tokens.filter((t2) => t2.type !== "list");
|
|
903
|
-
const subLists = item.tokens.filter((t2) => t2.type === "list");
|
|
904
|
-
if (inlineTokens.length > 0) {
|
|
905
|
-
const lineStart = text.length;
|
|
906
|
-
walkInline(inlineTokens, []);
|
|
907
|
-
const lineLen = text.length - lineStart;
|
|
908
|
-
emitLineStyles(lineStart, lineLen, [...blockLineStyles, { style: listStyle }]);
|
|
909
|
-
text += "\n";
|
|
910
|
-
}
|
|
911
|
-
const subIndent = Math.min(5, depth + 1);
|
|
912
|
-
walkBlock(subLists, [...blockLineStyles, { style: TextStyle.Indent, indentSize: subIndent }], depth + 1);
|
|
913
|
-
} else {
|
|
914
|
-
const lineStart = text.length;
|
|
915
|
-
walkInline(item.tokens, []);
|
|
916
|
-
const lineLen = text.length - lineStart;
|
|
917
|
-
emitLineStyles(lineStart, lineLen, [...blockLineStyles, { style: listStyle }]);
|
|
918
|
-
text += "\n";
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
break;
|
|
923
|
-
}
|
|
924
|
-
case "hr": {
|
|
925
|
-
text += "---\n";
|
|
926
|
-
break;
|
|
927
|
-
}
|
|
928
|
-
case "html": {
|
|
929
|
-
const t = tok;
|
|
930
|
-
text += t.text;
|
|
931
|
-
break;
|
|
932
|
-
}
|
|
933
|
-
case "text": {
|
|
934
|
-
const t = tok;
|
|
935
|
-
const lineStart = text.length;
|
|
936
|
-
if (t.tokens && t.tokens.length > 0) {
|
|
937
|
-
walkInline(t.tokens, []);
|
|
938
|
-
} else {
|
|
939
|
-
text += t.text;
|
|
940
|
-
}
|
|
941
|
-
const lineLen = text.length - lineStart;
|
|
942
|
-
emitLineStyles(lineStart, lineLen, blockLineStyles);
|
|
943
|
-
text += "\n";
|
|
944
|
-
break;
|
|
945
|
-
}
|
|
946
|
-
case "space": {
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
default: {
|
|
950
|
-
const t = tok;
|
|
951
|
-
if (t.raw) text += t.raw;
|
|
952
|
-
break;
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
walkBlock(tokens, [], 0);
|
|
958
|
-
if (text.endsWith("\n")) {
|
|
959
|
-
text = text.slice(0, -1);
|
|
960
|
-
}
|
|
961
|
-
for (const slot of tagSlots) {
|
|
962
|
-
const phIdx = text.indexOf(slot.placeholder);
|
|
963
|
-
if (phIdx === -1) continue;
|
|
964
|
-
const inner = parseTextStyles(slot.innerMd);
|
|
965
|
-
const replacement = inner.text;
|
|
966
|
-
const phLen = slot.placeholder.length;
|
|
967
|
-
text = text.slice(0, phIdx) + replacement + text.slice(phIdx + phLen);
|
|
968
|
-
const delta = replacement.length - phLen;
|
|
969
|
-
for (const s of styles) {
|
|
970
|
-
if (s.start >= phIdx + phLen) {
|
|
971
|
-
s.start += delta;
|
|
972
|
-
} else if (s.start + s.len > phIdx) {
|
|
973
|
-
s.len += delta;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
const tagStyle = tagColorMap[slot.tagName];
|
|
977
|
-
if (tagStyle) {
|
|
978
|
-
styles.push({ start: phIdx, len: replacement.length, st: tagStyle });
|
|
979
|
-
}
|
|
980
|
-
for (const is of inner.styles) {
|
|
981
|
-
styles.push({ start: phIdx + is.start, len: is.len, st: is.st, ..."indentSize" in is ? { indentSize: is.indentSize } : {} });
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
return { text, styles };
|
|
985
|
-
}
|
|
986
956
|
function parseBooleanFromEnv(name, fallback) {
|
|
987
957
|
const raw = process.env[name]?.trim();
|
|
988
958
|
if (!raw) return fallback;
|
|
@@ -3166,7 +3136,7 @@ auth.command("cache-clear").description("Clear local cache").action(
|
|
|
3166
3136
|
})
|
|
3167
3137
|
);
|
|
3168
3138
|
var msg = program.command("msg").description("Messaging commands");
|
|
3169
|
-
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*
|
|
3139
|
+
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(
|
|
3170
3140
|
wrapAction(async (threadId, message, opts, command) => {
|
|
3171
3141
|
const { api } = await requireApi(command);
|
|
3172
3142
|
if (opts.raw) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openzca",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
4
4
|
"description": "Open-source zca-compatible CLI to integrate Zalo with OpenClaw",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"@types/qrcode-terminal": "^0.12.2",
|
|
45
45
|
"commander": "^14.0.3",
|
|
46
46
|
"image-size": "^2.0.2",
|
|
47
|
-
"marked": "^17.0.4",
|
|
48
47
|
"qrcode-terminal": "^0.12.0",
|
|
49
48
|
"zca-js": "^2.0.4"
|
|
50
49
|
},
|