| | | 1 | | namespace TeleFlow.Telegram.Formatting; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Creates safe HTML-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 TelegramHtml |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Creates a builder that renders Telegram-compatible HTML. |
| | | 11 | | /// </summary> |
| | | 12 | | public static TelegramTextBuilder Create() |
| | | 13 | | { |
| | 15 | 14 | | return new TelegramTextBuilder(TelegramHtmlTextRenderer.Instance); |
| | | 15 | | } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Escapes a dynamic value for insertion into reviewed Telegram HTML markup. |
| | | 19 | | /// Quote delimiters are encoded so the value cannot leave a quoted attribute. |
| | | 20 | | /// </summary> |
| | | 21 | | public static string Escape(string text) |
| | | 22 | | { |
| | 4 | 23 | | ArgumentNullException.ThrowIfNull(text); |
| | 4 | 24 | | return TelegramHtmlEscaper.EscapeInterpolation(text); |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Creates an HTML formatted-text value from reviewed static markup. |
| | | 29 | | /// This bypasses escaping and structural validation and must never receive user-controlled input. |
| | | 30 | | /// </summary> |
| | | 31 | | public static TelegramFormattedText UnsafeMarkup(string markup) |
| | | 32 | | { |
| | 5 | 33 | | ArgumentException.ThrowIfNullOrWhiteSpace(markup); |
| | 5 | 34 | | return new TelegramFormattedText(markup, TelegramParseMode.Html); |
| | | 35 | | } |
| | | 36 | | } |