I’m building a Python bot for Telegram and having trouble with text formatting. The markdown syntax doesn’t work like I expect it to.
There are two different parsing modes available but neither one gives me the results I want. When I test this sample text:
*Bold text*, _italic text_, *_combined bold italic_*, **extra bold**, __extra italic__, __**all formatting combined**__
Using parse_mode="Markdown"
gives me:
Bold text, italic text, combined bold italic, extra bold, extra italic, all formatting combined
Using parse_mode="MarkdownV2"
produces:
Bold text, italic text, combined bold italic, extra bold, extra italic, all formatting combined
But when I type the same thing directly in Telegram chat I get different results.
Can someone explain how to properly combine bold and italic formatting in bot messages? Are there other formatting options like underline available? I’m confused about which markdown version to use and how the syntax actually works.
Telegram’s markdown is a mess compared to regular markdown. I switched to parse_mode=“HTML” - way more reliable. For bold+italic, just nest the tags: <b><i>your text</i></b>
. Works every time. MarkdownV2’s escaping rules are insane.
The difference in output is mainly due to Telegram’s client using a more lenient markdown parser compared to the bot API. When composing messages directly in the app, the parser is more forgiving. MarkdownV2 does offer improved formatting options, but the need to escape numerous special characters, including periods and brackets, can complicate things significantly. For basic formatting, I prefer using the original Markdown; it may not support all features, but it simplifies the process and mitigates issues with unexpected characters in user-generated content.
You’re hitting Telegram’s annoying markdown parsing quirks. I dealt with this mess for months - MarkdownV2 needs you to escape tons of characters (periods, hyphens, parentheses, etc.) or your messages just won’t send. It’s a nightmare with dynamic content.
What fixed it for me? Ditch markdown and use HTML instead. Set parse_mode="HTML"
and use <b>bold</b>
, <i>italic</i>
, or <b><i>bold italic</i></b>
for combos. Way more reliable than either markdown option.
One heads up - Telegram bots can’t do underline formatting no matter what parsing mode you pick, even though regular chat supports it.