@iletai/nzb 1.4.2 → 1.4.4

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();
@@ -92,16 +97,18 @@ export function toTelegramHTML(text) {
92
97
  out = out.replace(/`([^`\n]+)`/g, (_m, code) => stashToken(`<code>${escapeHtml(code)}</code>`));
93
98
  // 3. Stash markdown links → <a href>
94
99
  out = out.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, linkText, url) => stashToken(`<a href="${escapeHtml(url)}">${escapeHtml(linkText)}</a>`));
100
+ // 3a. Stash spoiler ||text|| → <tg-spoiler> (before tables, since || resembles table syntax)
101
+ out = out.replace(/\|\|(.+?)\|\|/g, (_m, inner) => stashToken(`<tg-spoiler>${escapeHtml(inner)}</tg-spoiler>`));
95
102
  // 4. Convert tables
96
103
  out = out.replace(/(?:^\|.+\|[ \t]*$\n?)+/gm, (table) => stashToken(convertTable(table) + "\n"));
97
104
  // 5. Convert headers → bold
98
105
  out = out.replace(/^#{1,6}\s+(.+)$/gm, (_m, title) => `**${title.trim()}**`);
99
106
  // 6. Remove horizontal rules
100
107
  out = out.replace(/^[-*_]{3,}\s*$/gm, "");
101
- // 7. Blockquotes <blockquote>
108
+ // 7. Strip blockquote markers but keep content for inline formatting (processed later at step 14b)
102
109
  out = out.replace(/(?:^>\s?(.*)$\n?)+/gm, (block) => {
103
110
  const content = block.replace(/^>\s?/gm, "").trim();
104
- return stashToken(`<blockquote>${escapeHtml(content)}</blockquote>`);
111
+ return `\x00BQ_START\x00${content}\x00BQ_END\x00\n`;
105
112
  });
106
113
  // 8. Unordered lists: - item or * item → • item
107
114
  out = out.replace(/^(\s*)[-*]\s+/gm, "$1• ");
@@ -124,6 +131,13 @@ export function toTelegramHTML(text) {
124
131
  });
125
132
  // 14. Underline __text__ → <u>
126
133
  out = out.replace(/__(.+?)__/g, (_m, inner) => stashToken(`<u>${escapeHtml(inner)}</u>`));
134
+ // 14b. Wrap blockquote markers → <blockquote> (inner content already formatted by steps 10-14)
135
+ out = out.replace(/\x00BQ_START\x00([\s\S]*?)\x00BQ_END\x00/g, (_m, content) => {
136
+ // Escape plain text while preserving stash tokens (same KEEP pattern as bold/italic)
137
+ const escaped = escapeHtml(content.replace(/\x00S\d+\x00/g, (tok) => `\x00KEEP${tok}\x00KEEP`));
138
+ const restored = escaped.replace(/\x00KEEP\x00S(\d+)\x00\x00KEEP/g, (_m2, i) => stash[+i]);
139
+ return stashToken(`<blockquote>${restored}</blockquote>`);
140
+ });
127
141
  // 15. Escape remaining plain text
128
142
  out = escapeHtml(out);
129
143
  // 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.4",
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"
@@ -16,6 +16,8 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "tsc",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest",
19
21
  "postinstall": "node scripts/fix-esm-imports.cjs",
20
22
  "daemon": "tsx src/daemon.ts",
21
23
  "tui": "tsx src/tui/index.ts",
@@ -61,6 +63,7 @@
61
63
  "@types/node": "^25.3.0",
62
64
  "prettier": "^3.8.1",
63
65
  "tsx": "^4.21.0",
64
- "typescript": "^5.9.3"
66
+ "typescript": "^5.9.3",
67
+ "vitest": "^4.1.0"
65
68
  }
66
69
  }