You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(markdown): add Telegram MarkdownV2 support and fallbacks
Improve cross-platform markdown compatibility by adding Telegram-specific escaping and graceful fallbacks for unsupported tags while refining CommonMark text handling; includes docs/tests updates and bumps package version to 5.3.0.
Copy file name to clipboardExpand all lines: README.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ If you have used and benefitted from this library. Please feel free to sponsor m
17
17
**Markdown flavors**
18
18
- GitHub Flavoured Markdown conversion for br, pre, tasklists, and table. Use `var config = new ReverseMarkdown.Config(githubFlavoured:true);`. By default the table will always be converted to Github flavored markdown immaterial of this flag
19
19
- Slack Flavoured Markdown conversion. Use `var config = new ReverseMarkdown.Config { SlackFlavored = true };`
20
+
- Telegram MarkdownV2 conversion. Use `var config = new ReverseMarkdown.Config { TelegramMarkdownV2 = true };`
20
21
- CommonMark-focused output with opt-in flags to preserve compatibility. Use `var config = new ReverseMarkdown.Config { CommonMark = true };` This mode may emit inline HTML for tricky emphasis/link cases unless you disable `CommonMarkUseHtmlInlineTags`.
21
22
22
23
**Tables**
@@ -101,18 +102,42 @@ If you need to preserve markdown-like text as literal content (for example `# He
varhtml="This is <strong>bold</strong>, <em>italic</em>, <del>strikethrough</del> and <a href=\"https://example.com/path_(one)?q=1)2\">a_b[c]</a>";
123
+
varresult=converter.Convert(html);
124
+
// This is *bold*, _italic_, ~strikethrough~ and [a\_b\[c\]](https://example.com/path_(one\)?q=1\)2)
125
+
```
126
+
127
+
Notes:
128
+
129
+
- Text and link labels escape Telegram-reserved characters.
130
+
- Ordered and unordered list markers are escaped (`1\.` and `\-`).
131
+
-`<img>` falls back to a link label (for example `[Image: alt](url)`).
132
+
-`<table>` falls back to a preformatted code block representation.
133
+
-`<sup>` falls back to caret notation (for example `x^2`).
134
+
111
135
## Configuration options
112
136
113
137
*`DefaultCodeBlockLanguage` - Option to set the default code block language for Github style markdown if class based language markers are not available
114
138
*`GithubFlavored` - Github style markdown for br, pre and table. Default is false
115
139
*`SlackFlavored` - Slack style markdown formatting. When enabled, uses `*` for bold, `_` for italic, `~` for strikethrough, and `•` for list bullets. Default is false
140
+
*`TelegramMarkdownV2` - Telegram MarkdownV2 formatting and escaping rules. When enabled, output escapes Telegram-reserved characters and uses Telegram-compatible emphasis and link syntax. For unsupported Telegram constructs, ReverseMarkdown falls back to readable text (`<img>` to link label, `<table>` to preformatted block, `<sup>` to caret notation).
116
141
*`CommonMark` - Enable CommonMark-focused output rules. Default is false
117
142
*`CommonMarkUseHtmlInlineTags` - When CommonMark is enabled, emit HTML for inline tags (`em`, `strong`, `a`, `img`) to avoid delimiter edge cases. Default is true
118
143
*`CommonMarkIntrawordEmphasisSpacing` - When CommonMark is enabled, insert spaces to avoid intraword emphasis. Default is false
0 commit comments