
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
telegram-markdown-v2
Advanced tools
Convert markdown into Telegram Markdown V2 format with TypeScript support
A lightweight TypeScript library for seamlessly transforming standard Markdown into Telegram's MarkdownV2 format. Built for developers who want reliable Markdown-to-Telegram conversion without the hassle.
Working with Telegram's MarkdownV2 format can be frustrating - special characters need escaping, formatting rules are strict, and one wrong character breaks everything. This library handles all the complexity, letting you focus on your bot's functionality.
bun install telegram-markdown-v2
Or with npm:
npm install telegram-markdown-v2
import { convert } from 'telegram-markdown-v2';
const markdown = `
# Hello World
This is **bold text** and *italic text*.
- List item 1
- List item 2
`;
const telegramMarkdown = convert(markdown);
console.log(telegramMarkdown);
convert(markdown: string, unsupportedTagsStrategy?: UnsupportedTagsStrategy): stringTransforms standard Markdown into Telegram MarkdownV2 format.
Parameters:
markdown: The input Markdown stringunsupportedTagsStrategy: Optional strategy for handling unsupported tags ('keep' | 'escape' | 'remove'). Default: 'keep'Returns: Formatted string ready for Telegram's parse_mode: 'MarkdownV2'
| Element | Input | Telegram Output |
|---|---|---|
| Bold | **text** | *text* |
| Italic | *text* | _text_ |
| Underline | <u>text</u> | __text__ |
~~text~~ | ~text~ | |
| Spoiler | <span class="tg-spoiler">text</span> | ` |
Inline Code | `code` | `code` |
| Links | [text](url) | [text](url) |
| Block Quotes | > quote | Configurable (keep/escape/remove) |
| Code Blocks | lang code | code |
| Lists | - item | • item |
| Headings | # Title | *Title* |
type UnsupportedTagsStrategy = 'escape' | 'remove' | 'keep';
Strategy Options:
'keep' (default): Preserve unsupported elements as-is'escape': Escape special characters in unsupported elements'remove': Remove unsupported elements entirelyimport { convert } from 'telegram-markdown-v2';
const input = "Check out this **amazing** library with *great* features!";
const output = convert(input);
// Result: "Check out this *amazing* library with _great_ features\\!"
const codeExample = `
Here's some JavaScript code:
\`\`\`javascript
function hello() {
console.log("Hello, world!");
}
\`\`\`
`;
const formatted = convert(codeExample);
// Ready to send via Telegram Bot API
const listExample = `
## Todo List
- Create awesome library
- Write documentation
- Publish to npm
Visit [our repo](https://github.com/example/telegram-markdown-v2)
`;
const telegramReady = convert(listExample);
import { convert } from 'telegram-markdown-v2';
// Keep unsupported tags as-is (default)
const keepResult = convert('> This is a blockquote', 'keep');
// Result: "> This is a blockquote\n"
// Escape special characters in unsupported tags
const escapeResult = convert('> This is a blockquote', 'escape');
// Result: "\\> This is a blockquote\n"
// Remove unsupported tags entirely
const removeResult = convert('> This is a blockquote', 'remove');
// Result: ""
// Underline support
const underline = convert('This is <u>underlined</u> text');
// Result: "This is __underlined__ text\n"
// Spoiler support
const spoiler = convert('This is <span class="tg-spoiler">hidden</span> text');
// Result: "This is ||hidden|| text\n"
// Custom emoji and user mentions
const mentions = convert('[John](tg://user?id=123) sent ');
// Result: "[John](tg://user\\?id\\=123) sent [👍](tg://emoji\\?id\\=456)\n"
The library automatically escapes Telegram's special characters: _*[]()~#+-=|{}.!`
Telegram limits messages to 4096 characters. You'll need to implement message splitting in your application.
If your Markdown doesn't render correctly, check for unmatched formatting marks or nested styles.
Elements like tables, blockquotes, and HTML tags can be handled using the unsupportedTagsStrategy parameter.
# Install dependencies
bun install
# Run tests
bun test
# Build for production
bun run build
# Type checking
bun run typecheck
# Linting
bun run lint
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)MIT © 2025
Inspired by the Python telegramify-markdown library, reimagined for the TypeScript ecosystem with modern tooling and better performance.
FAQs
Convert markdown into Telegram Markdown V2 format with TypeScript support
The npm package telegram-markdown-v2 receives a total of 1,804 weekly downloads. As such, telegram-markdown-v2 popularity was classified as popular.
We found that telegram-markdown-v2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.