telega/format
Provides utilities for text formatting in Telegram messages. Supports HTML, Markdown, and MarkdownV2 parse modes.
Quick Start
import telega/format as fmt
// Simple formatting
let text = fmt.bold("Important!") <> " " <> fmt.italic("Read this")
// Complex formatting with builder
let message = fmt.build()
|> fmt.text("Hello ")
|> fmt.bold_text("World")
|> fmt.line_break()
|> fmt.link_text("Click here", "https://example.com")
|> fmt.to_html()
Types
Builder pattern for constructing formatted text
pub opaque type FormatBuilder
Formatted text container
pub opaque type FormattedText
Values
pub fn bold_text(
builder: FormatBuilder,
text: String,
) -> FormatBuilder
Add bold text using builder
pub fn code_text(
builder: FormatBuilder,
text: String,
) -> FormatBuilder
Add inline code using builder
pub fn custom_emoji_text(
builder: FormatBuilder,
emoji: String,
id: String,
) -> FormatBuilder
Add custom emoji using builder
pub fn escape_markdown(text: String) -> String
Escape special characters for Markdown
pub fn escape_markdown_v2(text: String) -> String
Escape special characters for MarkdownV2
pub fn italic_text(
builder: FormatBuilder,
text: String,
) -> FormatBuilder
Add italic text using builder
pub fn link_text(
builder: FormatBuilder,
text: String,
url: String,
) -> FormatBuilder
Add hyperlink using builder
pub fn mention_text(
builder: FormatBuilder,
username: String,
) -> FormatBuilder
Add mention using builder
pub fn parse_mode_to_string(mode: ParseMode) -> String
Convert ParseMode to string for API
pub fn pre(
code: String,
language: option.Option(String),
) -> String
Format text as code block (HTML)
pub fn pre_text(
builder: FormatBuilder,
code: String,
language: option.Option(String),
) -> FormatBuilder
Add code block using builder
pub fn render(formatted: FormattedText) -> #(String, ParseMode)
Render FormattedText to string with parse mode
pub fn spoiler_text(
builder: FormatBuilder,
text: String,
) -> FormatBuilder
Add spoiler text using builder
pub fn strikethrough_text(
builder: FormatBuilder,
text: String,
) -> FormatBuilder
Add strikethrough text using builder
pub fn to_formatted(builder: FormatBuilder) -> FormattedText
Convert to FormattedText for use with reply functions
pub fn to_markdown_v2(builder: FormatBuilder) -> String
Build to MarkdownV2 string
pub fn underline_text(
builder: FormatBuilder,
text: String,
) -> FormatBuilder
Add underlined text using builder
pub fn with_mode(
builder: FormatBuilder,
mode: ParseMode,
) -> FormatBuilder
Set parse mode for builder