module

Autobot::Channels::MarkdownToTelegramHTML

Converts Markdown to Telegram-safe HTML.

Telegram supports: , , , , ,

, , 
All <, >, & outside tags must be escaped. Code/pre cannot contain other tags.

Constants

HEADER_REGEX = Regex.new("^\#{1,6}\\s+(.+)$", Regex::Options::MULTILINE)
HR_REGEX = /^[-*_]{3,}\s*$/m
HTML_CODE_CLOSE = "</code></pre>"
HTML_CODE_OPEN = "<pre><code"

Prefix (no closing ">") so it matches both

 and

; the full open tag is recovered later.
HTML_TAG_REGEX = /<(\/?)(b|i|code|pre|a|s|u)(?:\s[^>]*)?>/
INLINE_CODE_PREFIX = "\u0000IC"
INLINE_CODE_REGEX = /`([^`]+)`/
ITALIC_REGEX = /(?<![a-zA-Z0-9])_([^_]+)_(?![a-zA-Z0-9])/
LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/
STRIKETHROUGH_REGEX = /~~(.+?)~~/
STRIP_HTML_REGEX = /<\/?(?:b|i|code|pre|a|s|u)(?:\s[^>]*)?>/
SUFFIX = "\u0000"
TELEGRAM_MAX_LENGTH = 4096
UNDERSCORE_PREFIX = "\u0000US"
UNDERSCORE_RUN_REGEX = /_{3,}/

Class methods

convert(text : String) : String
Source
escape_html(text : String) : String
Source
split_message(text : String) : Array(String)
Source
strip_html(text : String) : String
Source
valid_html?(text : String) : Bool
Source