Telegram MarkdownV2 parser
npm install @vlad-yakovlev/telegram-mdTelegram MarkdownV2 formatter
!GitHub CI


telegram-md is a powerful TypesScript library designed to simplify the formatting of text messages in Telegram MarkdownV2 format. It provides a range of methods for applying markdown formatting, such as bold, italic, and links, making it easier to create richly formatted messages programmatically.
1. How to Install
2. Usage Examples
3. API Documentation
``sh`
npm install @vlad-yakovlev/telegram-md
`ts
import { md } from '@vlad-yakovlev/telegram-md'
// Simple message formatting
const message = mdHello, ${md.bold('World')}!
api.sendMessage(chatId, md.build(message))
// Using different formatting styles
const complexMessage = md
This is an ${md.italic('italic')}
and ${md.bold('bold')} text
with a ${md.link('link', 'http://example.com')}!`
api.sendMessage(chatId, md.build(complexMessage))
Every method escapes all unescaped input. Input is assumed to be escaped only when it's an instance of Markdown.
Stores the result of executing md methods. Used to differentiate between normal strings and escaped strings.
Template tag which can be used to build markdown formatted messages.
`tsHello, ${md.bold('World')}!
md // => Markdown with value 'Hello, World\\!'`
Returns message text that cat be safely sent to telegram API.
`tsHello, ${md.bold('World')}!
md.build(md) // => 'Hello, World\\!'`
md.build('Hello, World!') // => 'Hello, World\\!'
`ts`
md.bold('bold text') // => Markdown with value 'bold \text'
`ts`
md.italic('italic text') // => Markdown with value '_italic \text_'
`ts`
md.underline('underline') // => Markdown with value '__underline__'
`ts`
md.strikethrough('strikethrough') // => Markdown with value '~strikethrough~'
`ts`
md.spoiler('spoiler') // => Markdown with value '||spoiler||'
`ts`
md.link('inline URL', 'http://www.example.com/') // => Markdown with value 'inline URL'
md.link('inline mention of a user', 'tg://user?id=123456789') // => Markdown with value 'inline mention of a user'
`tsinline fixed\\-width code
md.inlineCode('inline fixed-width code') // => Markdown with value ''`
`ts`
md.blockquote('blockquote') // => Markdown with value '>blockquote'
``ts`
md.code(
'pre-formatted fixed-width code block',
) // => Markdown with value`
pre\\-formatted fixed\\-width code block``
``ts`
md.code(
'pre-formatted fixed-width code block written in the Python',
'python',
) // => Markdown with valuepython`
pre\\-formatted fixed\\-width code block written in the Python```