n8n-nodes-zalo-nnt
Version:
Unofficial Zalo integration for n8n - Send messages, manage groups, user operations with QR login. No API key required, works via browser simulation.
130 lines (124 loc) • 4.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.markdownToZaloStyles = markdownToZaloStyles;
exports.getMarkdownSyntaxGuide = getMarkdownSyntaxGuide;
function markdownToZaloStyles(text) {
if (!text || typeof text !== 'string') {
return { plainText: text || '', styles: [] };
}
const styles = [];
let i = 0;
const stack = [];
let cleanedText = '';
const tagPatterns = [
{ open: '[orange]', close: '[/orange]', styleCode: 'c_f27806' },
{ open: '[yellow]', close: '[/yellow]', styleCode: 'c_f7b503' },
{ open: '[green]', close: '[/green]', styleCode: 'c_15a85f' },
{ open: '[small]', close: '[/small]', styleCode: 'f_13' },
{ open: '[red]', close: '[/red]', styleCode: 'c_db342e' },
{ open: '[big]', close: '[/big]', styleCode: 'f_18' },
{ open: '**', close: '**', styleCode: 'b' },
{ open: '~~', close: '~~', styleCode: 's' },
{ open: '__', close: '__', styleCode: 'u' },
{ open: '*', close: '*', styleCode: 'i' },
];
while (i < text.length) {
let matched = false;
for (const pattern of tagPatterns) {
if (text.substring(i, i + pattern.open.length) === pattern.open) {
const existingIndex = stack.findIndex((s) => s.styleCode === pattern.styleCode);
if (pattern.open === pattern.close && existingIndex !== -1) {
const style = stack.splice(existingIndex, 1)[0];
const len = cleanedText.length - style.startPos;
if (len > 0) {
styles.push({
start: style.startPos,
len: len,
st: style.styleCode,
});
}
i += pattern.open.length;
matched = true;
break;
}
else if (pattern.open !== pattern.close) {
stack.push({
startPos: cleanedText.length,
styleCode: pattern.styleCode,
tagLength: pattern.open.length,
});
i += pattern.open.length;
matched = true;
break;
}
else {
stack.push({
startPos: cleanedText.length,
styleCode: pattern.styleCode,
tagLength: pattern.open.length,
});
i += pattern.open.length;
matched = true;
break;
}
}
}
if (matched)
continue;
for (const pattern of tagPatterns) {
if (pattern.open !== pattern.close && text.substring(i, i + pattern.close.length) === pattern.close) {
const pending = stack.findIndex((s) => s.styleCode === pattern.styleCode);
if (pending !== -1) {
const style = stack.splice(pending, 1)[0];
const len = cleanedText.length - style.startPos;
if (len > 0) {
styles.push({
start: style.startPos,
len: len,
st: style.styleCode,
});
}
}
i += pattern.close.length;
matched = true;
break;
}
}
if (matched)
continue;
cleanedText += text[i];
i++;
}
styles.sort((a, b) => a.start - b.start);
return {
plainText: cleanedText,
styles,
};
}
function getMarkdownSyntaxGuide() {
return `
Markdown Syntax Guide:
Text Formatting:
- **bold** → Bold text
- *italic* → Italic text
- __underline__ → Underlined text
- ~~strikethrough~~ → Strikethrough text
Colors:
- [red]text[/red] → Red text
- [orange]text[/orange] → Orange text
- [yellow]text[/yellow] → Yellow text
- [green]text[/green] → Green text
Font Sizes:
- [big]text[/big] → Bigger font (18px)
- [small]text[/small] → Smaller font (13px)
Examples:
**Hello** [red]world[/red]!
→ "Hello" is bold, "world" is red
*Urgent*: ~~old price~~ [green]new price[/green]
→ "Urgent" is italic, "old price" strikethrough, "new price" green
Combine multiple styles:
**[red]Important Alert[/red]**
→ Both bold and red
`.trim();
}
//# sourceMappingURL=markdownToZaloStyles.js.map