Telegram Bot API has several options to format sending messages with a parameter parse_mode. One of them is MarkdownV2.
It has similar syntax to normal markdown, however it can be a problem to convert already existent Markdown text to Telegram MarkdownV2.
- Convert Markdown Bold (
**Bold**
) to Telegram MarkdownV2 Bold (*Bold*
) - Convert Markdown Italic (
*Italic*
or_Italic_
) to Telegram MarkdownV2 Italic (_Italic_
) - Convert Markdown Strikethrough (
~Strikethrough~
) to Telegram MarkdownV2 Italic (~Strikethrough~
) - Parse unwrapped links (
https://example.com
) and wrap them ([https://example.com](https://example.com)
) - Parse Markdown inline code and code blocks and escape special chars inside them for Telegram MarkdownV2.
package main
import (
"github.com/zavitkov/tg-markdown"
"fmt"
)
func main() {
markdown := `This is **bold** *italic* ~strikethrough~ text with [wrapped](https://github.com/zavitkov/tg-markdown) link and unwrapped link: https://github.com/zavitkov/tg-markdown`
tgMarkdownV2 := tg_markdown.ConvertMarkdownToTelegramMarkdownV2(markdown)
fmt.Println(tgMarkdownV2)
//output: This is *bold* _italic_ ~strikethrough~ text with [wrapped](https://github.com/zavitkov/tg-markdown) link and unwrapped link: [https://github\.com/zavitkov/tg\-markdown](https://github.com/zavitkov/tg-markdown)
}