@iletai/nzb 1.4.2 → 1.4.3

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.
@@ -7,7 +7,7 @@ export function escapeHtml(text) {
7
7
  }
8
8
  /**
9
9
  * Split a long message into chunks that fit within Telegram's message limit.
10
- * HTML-aware: if a split falls inside a <pre> block, close and reopen it.
10
+ * HTML-aware: if a split falls inside a <pre> or <blockquote> block, close and reopen it.
11
11
  */
12
12
  export function chunkMessage(text) {
13
13
  if (text.length <= TELEGRAM_MAX_LENGTH) {
@@ -28,14 +28,19 @@ export function chunkMessage(text) {
28
28
  splitAt = CHUNK_TARGET;
29
29
  }
30
30
  const segment = remaining.slice(0, splitAt);
31
- // Count <pre> vs </pre> — mismatch means we're inside a code block
32
- const opens = (segment.match(/<pre/g) || []).length;
33
- const closes = (segment.match(/<\/pre>/g) || []).length;
34
- const insideCodeBlock = opens > closes;
35
- if (insideCodeBlock) {
31
+ // Check for unclosed block-level tags
32
+ const preOpens = (segment.match(/<pre/g) || []).length;
33
+ const preCloses = (segment.match(/<\/pre>/g) || []).length;
34
+ const bqOpens = (segment.match(/<blockquote/g) || []).length;
35
+ const bqCloses = (segment.match(/<\/blockquote>/g) || []).length;
36
+ if (preOpens > preCloses) {
36
37
  chunks.push(segment + "\n</pre>");
37
38
  remaining = "<pre>" + remaining.slice(splitAt).trimStart();
38
39
  }
40
+ else if (bqOpens > bqCloses) {
41
+ chunks.push(segment + "</blockquote>");
42
+ remaining = "<blockquote>" + remaining.slice(splitAt).trimStart();
43
+ }
39
44
  else {
40
45
  chunks.push(segment);
41
46
  remaining = remaining.slice(splitAt).trimStart();
@@ -98,10 +103,10 @@ export function toTelegramHTML(text) {
98
103
  out = out.replace(/^#{1,6}\s+(.+)$/gm, (_m, title) => `**${title.trim()}**`);
99
104
  // 6. Remove horizontal rules
100
105
  out = out.replace(/^[-*_]{3,}\s*$/gm, "");
101
- // 7. Blockquotes <blockquote>
106
+ // 7. Strip blockquote markers but keep content for inline formatting (processed later at step 14b)
102
107
  out = out.replace(/(?:^>\s?(.*)$\n?)+/gm, (block) => {
103
108
  const content = block.replace(/^>\s?/gm, "").trim();
104
- return stashToken(`<blockquote>${escapeHtml(content)}</blockquote>`);
109
+ return `\x00BQ_START\x00${content}\x00BQ_END\x00\n`;
105
110
  });
106
111
  // 8. Unordered lists: - item or * item → • item
107
112
  out = out.replace(/^(\s*)[-*]\s+/gm, "$1• ");
@@ -124,6 +129,13 @@ export function toTelegramHTML(text) {
124
129
  });
125
130
  // 14. Underline __text__ → <u>
126
131
  out = out.replace(/__(.+?)__/g, (_m, inner) => stashToken(`<u>${escapeHtml(inner)}</u>`));
132
+ // 14b. Wrap blockquote markers → <blockquote> (inner content already formatted by steps 10-14)
133
+ out = out.replace(/\x00BQ_START\x00([\s\S]*?)\x00BQ_END\x00/g, (_m, content) => {
134
+ // Escape plain text while preserving stash tokens (same KEEP pattern as bold/italic)
135
+ const escaped = escapeHtml(content.replace(/\x00S\d+\x00/g, (tok) => `\x00KEEP${tok}\x00KEEP`));
136
+ const restored = escaped.replace(/\x00KEEP\x00S(\d+)\x00\x00KEEP/g, (_m2, i) => stash[+i]);
137
+ return stashToken(`<blockquote>${restored}</blockquote>`);
138
+ });
127
139
  // 15. Escape remaining plain text
128
140
  out = escapeHtml(out);
129
141
  // 16. Restore stashed tokens
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iletai/nzb",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "NZB — a personal AI assistant for developers, built on the GitHub Copilot SDK",
5
5
  "bin": {
6
6
  "nzb": "dist/cli.js"