Registry / messaging / telegram-markdown-formatter

telegram-markdown-formatter

JSON →
library0.1.2jsnpmunverified

A TypeScript library that converts ChatGPT-style Markdown into HTML compatible with the Telegram Bot API. It supports bold, italic, underline, strikethrough, spoiler, headings, lists, links, inline code, code blocks with language hints, blockquotes, and expandable blockquotes. Version 0.1.2, works with Node >=18, includes a CLI tool, and can split long messages into Telegram-safe chunks (≤4096 characters). Originally a port of a Python module, it provides strong typing via TypeScript.

npm install telegram-markdown-formatter
INSTALL
IMPORT
SIG · TELEGRAM-MARKDOWN-
T
telegram-markdown-formatter
messagingjavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

telegramFormat
import { telegramFormat } from 'telegram-markdown-formatter'
const telegramFormat = require('telegram-markdown-formatter')
Package is ESM-only (Node >=18). Named export, not default.
splitHtmlForTelegram
import { splitHtmlForTelegram } from 'telegram-markdown-formatter'
const splitHtmlForTelegram = require('telegram-markdown-formatter').splitHtmlForTelegram
Named export for splitting HTML into chunks ≤4096 characters.

Converts a Markdown string (including headings, bold, italic, code block, blockquote, list, link) to Telegram-compatible HTML.

import { telegramFormat } from 'telegram-markdown-formatter'; const markdown = `# Title This is **bold** and _italic_ text. \`\`\`javascript\nconsole.log('Hello!');\n\`\`\` > Quote - Item 1 - Item 2 [Link](https://example.com)`; const html = telegramFormat(markdown); console.log(html); // Expected: <b>Title</b>\nThis is <b>bold</b> and <i>italic</i> text.\n<pre><code class="language-javascript">console.log('Hello!');</code></pre>\n<blockquote>Quote</blockquote>\n• Item 1\n• Item 2\n<a href="https://example.com">Link</a>
Debug
Known issues
gotchaThe library does not escape user-supplied text in code blocks or inline code. If the code contains text like </code>, it can break HTML.
fix
Sanitize input or wrap output in a CDATA section if necessary.
affects: >=0.0.0
gotchaHeadings are converted to <b> tags, not <h1>-<h6>, because Telegram HTML only supports <b> for bold.
fix
Use **text** for bold/highlights in plain text instead of headings.
affects: >=0.0.0
gotchaThe library does not handle nested Markdown syntax (e.g., **bold _italic_**). Nesting may produce invalid or unexpected HTML.
fix
Flatten or manually nest by combining HTML tags directly.
affects: >=0.0.0
gotchaThe package is ESM-only (Node >=18). It cannot be required() in CommonJS.
fix
Use dynamic import() in CommonJS: import('telegram-markdown-formatter').then(m => m.telegramFormat(text)).
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/telegram-markdown-formatter/dist/index.js from /path/to/file.js not supported.
The package is ESM-only and does not provide a CommonJS entry point.
fix
Use import syntax or dynamic import() instead of require().
telegramFormat is not a function
Incorrect import (default import instead of named import).
fix
Use `import { telegramFormat } from 'telegram-markdown-formatter'`.
The requested module 'telegram-markdown-formatter' does not provide an export named 'default'
Attempting to import a default export that doesn't exist.
fix
Use named import: `import { telegramFormat } from 'telegram-markdown-formatter'`.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
23
OpenAI (training)
2
Resources
telegram-markdown-formatter — npm install telegram-markdown-formatter · libregistry