
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
telegram-md2html
Advanced tools
A smart and efficient TypeScript/JavaScript library for converting Telegram-style Markdown to Telegram-compatible HTML. Perfect for Telegram bots, chat applications, and content processing.
npm install telegram-md2html
# or
yarn add telegram-md2html
# or
pnpm add telegram-md2html
// CommonJS
const { markdownToHtml } = require('telegram-md2html');
// ES Modules
import { markdownToHtml } from 'telegram-md2html';
// Convert Telegram markdown to HTML
const html = markdownToHtml('**Hello** *World*!');
console.log(html);
// Output: <b>Hello</b> <i>World</i>!
import { markdownToHtml } from 'telegram-md2html';
const markdown = `
# Welcome to Telegram Bot
**Bold text** and *italic text*
__Underlined__ and ~~strikethrough~~
||Spoiler text||
\`inline code\`
[Visit Google](https://google.com)
> This is a quote
**> Expandable quote
\`\`\`javascript
console.log("Hello World");
\`\`\`
`;
const html = markdownToHtml(markdown);
console.log(html);
import { createConverter } from 'telegram-md2html';
// Create a converter with custom options
const converter = createConverter({
escapeHtml: true,
autoCloseCodeBlocks: true,
linkProcessor: (url, text) =>
`<a href="${url}" target="_blank" rel="noopener">${text}</a>`,
codeBlockProcessor: (code, language) =>
`<pre><code class="language-${language || 'text'}">${code}</code></pre>`
});
const html = converter.convert('**[Important Link](https://example.com)**');
| Markdown | HTML Output | Description |
|---|---|---|
**text** | <b>text</b> | Bold text |
*text* or _text_ | <i>text</i> | Italic text |
__text__ | <u>text</u> | Underlined text |
~~text~~ | <s>text</s> | Strikethrough text |
||text|| | <span class="tg-spoiler">text</span> | Spoiler text |
`code` | <code>code</code> | Inline code |
```language\ncode\n``` | <pre><code class="language-xxx">code</code></pre> | Code block |
[text](url) | <a href="url">text</a> | Link |
> text | <blockquote>text</blockquote> | Blockquote |
**> text | <blockquote expandable>text</blockquote> | Expandable blockquote |
markdownToHtml(text: string, options?: ConvertOptions): stringMain conversion function that converts Telegram-style markdown to HTML.
Parameters:
text: The markdown text to convertoptions: Optional conversion optionsReturns: Telegram-compatible HTML string
createConverter(options?: ConvertOptions): MarkdownConverterCreates a converter instance with custom options for reuse.
interface ConvertOptions {
/** Whether to escape HTML special characters (default: true) */
escapeHtml?: boolean;
/** Whether to auto-close unclosed code blocks (default: true) */
autoCloseCodeBlocks?: boolean;
/** Custom link processor function */
linkProcessor?: (url: string, text: string) => string;
/** Custom code block processor function */
codeBlockProcessor?: (code: string, language?: string) => string;
}
The library includes full TypeScript definitions. Just import and use:
import { markdownToHtml, ConvertOptions } from 'telegram-md2html';
const options: ConvertOptions = {
escapeHtml: false,
linkProcessor: (url: string, text: string): string => {
return `<a href="${url}" class="custom-link">${text}</a>`;
}
};
const html: string = markdownToHtml('**TypeScript** works!', options);
The library can be used in modern browsers:
<script type="module">
import { markdownToHtml } from 'https://cdn.jsdelivr.net/npm/telegram-md2html/dist/index.mjs';
const html = markdownToHtml('**Hello** from browser!');
document.getElementById('output').innerHTML = html;
</script>
<script type="module">
import { markdownToHtml } from 'https://cdn.jsdelivr.net/gh/Soumyadeep765/telegram-md2html@main/dist/index.mjs';
const html = markdownToHtml('**Hello** World');
document.getElementById('output').innerHTML = html;
</script>
<script src="https://cdn.jsdelivr.net/npm/telegram-md2html/dist/index.js"></script>
<script>
// Available as window.telegramMd2Html
const html = telegramMd2Html.markdownToHtml('**CDN** Example');
document.getElementById('output').innerHTML = html;
</script>
const result = markdownToHtml(`
**Welcome to our bot!**
Features:
• *Easy formatting*
• __Multiple styles__
• ~~Clean output~~
\`\`\`python
def greet():
print("Hello from Python!")
\`\`\`
> Remember: **Formatting** makes messages _better_
**> Click to expand details
`);
console.log(result);
The library handles edge cases gracefully:
The library is optimized for performance:
Contributions are welcome! Here's how you can help:
git checkout -b feature-namenpm testgit commit -am 'Add feature'git push origin feature-name# Clone the repository
git clone https://github.com/Soumyadeep765/telegram-md2html.git
cd telegram-md2html
# Install dependencies
npm install
# Build the library
npm run build
# Run tests
npm test
# Watch mode for development
npm run dev
The library includes comprehensive tests:
# Run all tests
npm test
# Run tests with coverage
npm test -- --coverage
This project is licensed under the MIT License
If you find this library useful, please consider:
Soumyadeep Das
Note: This library is not affiliated with or endorsed by Telegram.
FAQs
A smart converter for Telegram-style Markdown to Telegram-compatible HTML
The npm package telegram-md2html receives a total of 2 weekly downloads. As such, telegram-md2html popularity was classified as not popular.
We found that telegram-md2html 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.