@iletai/nzb 1.4.0 → 1.4.1
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/telegram/formatter.js +19 -11
- package/package.json +1 -1
|
@@ -107,19 +107,27 @@ export function toTelegramHTML(text) {
|
|
|
107
107
|
out = out.replace(/^(\s*)[-*]\s+/gm, "$1• ");
|
|
108
108
|
// 9. Ordered lists: keep as-is (1. 2. 3.)
|
|
109
109
|
// 10. Strikethrough ~~text~~ → <s>
|
|
110
|
-
out = out.replace(/~~(.+?)~~/g, (_m, inner) => stashToken(`<s
|
|
111
|
-
// 11. Bold
|
|
112
|
-
out = out.replace(
|
|
113
|
-
// 12.
|
|
114
|
-
out = out.replace(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
out = out.replace(/~~(.+?)~~/g, (_m, inner) => stashToken(`<s>${escapeHtml(inner)}</s>`));
|
|
111
|
+
// 11. Bold+italic ***text*** → <b><i>text</i></b>
|
|
112
|
+
out = out.replace(/\*\*\*(.+?)\*\*\*/g, (_m, inner) => stashToken(`<b><i>${escapeHtml(inner)}</i></b>`));
|
|
113
|
+
// 12. Bold **text** → <b> (inner may contain stash tokens, preserve them)
|
|
114
|
+
out = out.replace(/\*\*(.+?)\*\*/g, (_m, inner) => {
|
|
115
|
+
const escaped = escapeHtml(inner.replace(/\x00S\d+\x00/g, (tok) => `\x00KEEP${tok}\x00KEEP`));
|
|
116
|
+
const restored = escaped.replace(/\x00KEEP\x00S(\d+)\x00\x00KEEP/g, (_m2, i) => stash[+i]);
|
|
117
|
+
return stashToken(`<b>${restored}</b>`);
|
|
118
|
+
});
|
|
119
|
+
// 13. Italic *text* → <i>
|
|
120
|
+
out = out.replace(/\*(.+?)\*/g, (_m, inner) => {
|
|
121
|
+
const escaped = escapeHtml(inner.replace(/\x00S\d+\x00/g, (tok) => `\x00KEEP${tok}\x00KEEP`));
|
|
122
|
+
const restored = escaped.replace(/\x00KEEP\x00S(\d+)\x00\x00KEEP/g, (_m2, i) => stash[+i]);
|
|
123
|
+
return stashToken(`<i>${restored}</i>`);
|
|
124
|
+
});
|
|
125
|
+
// 14. Underline __text__ → <u>
|
|
126
|
+
out = out.replace(/__(.+?)__/g, (_m, inner) => stashToken(`<u>${escapeHtml(inner)}</u>`));
|
|
127
|
+
// 15. Escape remaining plain text
|
|
118
128
|
out = escapeHtml(out);
|
|
119
|
-
//
|
|
129
|
+
// 16. Restore stashed tokens
|
|
120
130
|
out = out.replace(/\x00S(\d+)\x00/g, (_m, i) => stash[+i]);
|
|
121
|
-
// 16. Escape inner text of formatting tags (marked with ESC)
|
|
122
|
-
out = out.replace(/\x00ESC([\s\S]*?)\x00ESC/g, (_m, inner) => escapeHtml(inner));
|
|
123
131
|
// 17. Clean up excessive blank lines
|
|
124
132
|
out = out.replace(/\n{3,}/g, "\n\n");
|
|
125
133
|
return out.trim();
|