package tgfmt
import (
"strconv"
"strings"
)
// HTML is an escaped Telegram HTML fragment.
//
// Methods on HTML compose formatting without escaping the fragment again.
type HTML string
// EscapeHTML escapes special characters for Telegram HTML parse mode.
func EscapeHTML(s string) HTML {
s = strings.ReplaceAll(s, "&", "&")
s = strings.ReplaceAll(s, "<", "<")
s = strings.ReplaceAll(s, ">", ">")
s = strings.ReplaceAll(s, `"`, """)
return HTML(s)
}
// Bold returns h wrapped as bold Telegram HTML text.
func (h HTML) Bold() HTML {
return "" + h + ""
}
// Italic returns h wrapped as italic Telegram HTML text.
func (h HTML) Italic() HTML {
return "" + h + ""
}
// Underline returns h wrapped as underlined Telegram HTML text.
func (h HTML) Underline() HTML {
return "" + h + ""
}
// Strikethrough returns h wrapped as strikethrough Telegram HTML text.
func (h HTML) Strikethrough() HTML {
return "" + h + ""
}
// Spoiler returns h wrapped as spoiler Telegram HTML text.
func (h HTML) Spoiler() HTML {
return "" + h + ""
}
// BlockCode returns h wrapped as a Telegram HTML code block.
func (h HTML) BlockCode() HTML {
return "
" + h + "" } // BlockCodeLanguage returns h wrapped as a Telegram HTML code block with language. func (h HTML) BlockCodeLanguage(lang string) HTML { return `
` + h + ""
}
// Quote returns h as a Telegram HTML blockquote.
func (h HTML) Quote() HTML {
return "" + h + "" } // QuoteExpandable returns h as a Telegram HTML expandable blockquote. func (h HTML) QuoteExpandable() HTML { return "
" + h + "" } func escapeHTMLAttr(s string) HTML { return EscapeHTML(s) }