| | | 1 | | namespace TeleFlow.Telegram.Formatting; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Creates safe MarkdownV2-formatted Telegram text for normal Bot API messages. |
| | | 5 | | /// Plain values passed to the returned builder are escaped automatically. |
| | | 6 | | /// </summary> |
| | | 7 | | public static class TelegramMarkdownV2 |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Creates a builder that renders Telegram-compatible MarkdownV2. |
| | | 11 | | /// </summary> |
| | | 12 | | public static TelegramTextBuilder Create() |
| | | 13 | | { |
| | 7 | 14 | | return new TelegramTextBuilder(TelegramMarkdownV2TextRenderer.Instance); |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Escapes plain dynamic text for safe insertion into reviewed Telegram MarkdownV2 markup. |
| | | 19 | | /// </summary> |
| | | 20 | | public static string Escape(string text) |
| | | 21 | | { |
| | 2 | 22 | | ArgumentNullException.ThrowIfNull(text); |
| | 2 | 23 | | return TelegramMarkdownV2TextRenderer.Instance.EscapeText(text); |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Creates a MarkdownV2 formatted-text value from reviewed static markup. |
| | | 28 | | /// This bypasses escaping and structural validation and must never receive user-controlled input. |
| | | 29 | | /// </summary> |
| | | 30 | | public static TelegramFormattedText UnsafeMarkup(string markup) |
| | | 31 | | { |
| | 2 | 32 | | ArgumentException.ThrowIfNullOrWhiteSpace(markup); |
| | 2 | 33 | | return new TelegramFormattedText(markup, TelegramParseMode.MarkdownV2); |
| | | 34 | | } |
| | | 35 | | } |