tellegram 1.1.12 → 1.1.13

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/lib/tellegram.mjs CHANGED
@@ -5,6 +5,8 @@ import { toMarkdown as gfmTableToMarkdown } from 'mdast-util-gfm-table';
5
5
  import { wrap, isURL, escapeSymbols, processUnsupportedTags } from './utils.mjs';
6
6
  import tableToList from './table-to-list.mjs';
7
7
 
8
+ const isSafeCodeLanguage = language => /^[A-Za-z0-9_+-]+$/.test(language);
9
+
8
10
  /**
9
11
  * Creates custom `mdast-util-to-markdown` handlers that tailor the output for
10
12
  * Telegram Markdown.
@@ -66,7 +68,8 @@ const createHandlers = (definitions, unsupportedTagsStrategy, options) => ({
66
68
  const content = node.value.replace(/^#![a-z]+\n/, ''); // ```\n#!javascript\ncode block\n```
67
69
  exit();
68
70
 
69
- const language = node.lang || '';
71
+ const rawLanguage = node.lang || '';
72
+ const language = isSafeCodeLanguage(rawLanguage) ? rawLanguage : '';
70
73
  return `\`\`\`${language}\n${escapeSymbols(content, 'code')}\n\`\`\``;
71
74
  },
72
75
 
@@ -77,7 +80,7 @@ const createHandlers = (definitions, unsupportedTagsStrategy, options) => ({
77
80
 
78
81
  // Telegram MarkdownV2 inline code is sensitive to embedded backticks.
79
82
  // Fallback to escaped plain text to avoid broken entities.
80
- if (content.includes('`')) {
83
+ if (content.includes('`') || content.includes('\n') || content.includes('\r')) {
81
84
  return escapeSymbols(content);
82
85
  }
83
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tellegram",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Convert LLM-generated markdown into Telegram-specific markdown (MarkdownV2)",
5
5
  "type": "module",
6
6
  "main": "index.mjs",