(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
+12
-41
@@ -2,7 +2,6 @@ package tgfmt
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HTML is an escaped Telegram HTML fragment.
|
||||
@@ -11,43 +10,25 @@ import (
|
||||
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)
|
||||
}
|
||||
func EscapeHTML(s string) HTML { return HTML(escapeHTML(s)) }
|
||||
|
||||
// Bold returns h wrapped as bold Telegram HTML text.
|
||||
func (h HTML) Bold() HTML {
|
||||
return "<b>" + h + "</b>"
|
||||
}
|
||||
func (h HTML) Bold() HTML { return "<b>" + h + "</b>" }
|
||||
|
||||
// Italic returns h wrapped as italic Telegram HTML text.
|
||||
func (h HTML) Italic() HTML {
|
||||
return "<i>" + h + "</i>"
|
||||
}
|
||||
func (h HTML) Italic() HTML { return "<i>" + h + "</i>" }
|
||||
|
||||
// Underline returns h wrapped as underlined Telegram HTML text.
|
||||
func (h HTML) Underline() HTML {
|
||||
return "<u>" + h + "</u>"
|
||||
}
|
||||
func (h HTML) Underline() HTML { return "<u>" + h + "</u>" }
|
||||
|
||||
// Strikethrough returns h wrapped as strikethrough Telegram HTML text.
|
||||
func (h HTML) Strikethrough() HTML {
|
||||
return "<s>" + h + "</s>"
|
||||
}
|
||||
func (h HTML) Strikethrough() HTML { return "<s>" + h + "</s>" }
|
||||
|
||||
// Spoiler returns h wrapped as spoiler Telegram HTML text.
|
||||
func (h HTML) Spoiler() HTML {
|
||||
return "<tg-spoiler>" + h + "</tg-spoiler>"
|
||||
}
|
||||
func (h HTML) Spoiler() HTML { return "<tg-spoiler>" + h + "</tg-spoiler>" }
|
||||
|
||||
// Link returns h as a Telegram HTML text link.
|
||||
func (h HTML) Link(url string) HTML {
|
||||
return `<a href="` + escapeHTMLAttr(url) + `">` + h + "</a>"
|
||||
}
|
||||
func (h HTML) Link(url string) HTML { return `<a href="` + escapeHTMLAttr(url) + `">` + h + "</a>" }
|
||||
|
||||
// Mention returns h as a Telegram HTML user mention.
|
||||
func (h HTML) Mention(userID int64) HTML {
|
||||
@@ -70,14 +51,10 @@ func (h HTML) TimeFormat(unix int64, format string) HTML {
|
||||
}
|
||||
|
||||
// InlineCode returns h wrapped as inline code Telegram HTML text.
|
||||
func (h HTML) InlineCode() HTML {
|
||||
return "<code>" + h + "</code>"
|
||||
}
|
||||
func (h HTML) InlineCode() HTML { return "<code>" + h + "</code>" }
|
||||
|
||||
// BlockCode returns h wrapped as a Telegram HTML code block.
|
||||
func (h HTML) BlockCode() HTML {
|
||||
return "<pre>" + h + "</pre>"
|
||||
}
|
||||
func (h HTML) BlockCode() HTML { return "<pre>" + h + "</pre>" }
|
||||
|
||||
// BlockCodeLanguage returns h wrapped as a Telegram HTML code block with language.
|
||||
func (h HTML) BlockCodeLanguage(lang string) HTML {
|
||||
@@ -85,15 +62,9 @@ func (h HTML) BlockCodeLanguage(lang string) HTML {
|
||||
}
|
||||
|
||||
// Quote returns h as a Telegram HTML blockquote.
|
||||
func (h HTML) Quote() HTML {
|
||||
return "<blockquote>" + h + "</blockquote>"
|
||||
}
|
||||
func (h HTML) Quote() HTML { return "<blockquote>" + h + "</blockquote>" }
|
||||
|
||||
// QuoteExpandable returns h as a Telegram HTML expandable blockquote.
|
||||
func (h HTML) QuoteExpandable() HTML {
|
||||
return "<blockquote expandable>" + h + "</blockquote>"
|
||||
}
|
||||
func (h HTML) QuoteExpandable() HTML { return "<blockquote expandable>" + h + "</blockquote>" }
|
||||
|
||||
func escapeHTMLAttr(s string) HTML {
|
||||
return EscapeHTML(s)
|
||||
}
|
||||
func escapeHTMLAttr(s string) HTML { return HTML(escapeHTML(s)) }
|
||||
|
||||
Reference in New Issue
Block a user