(new): rich message support
Golang lint / lint (pull_request) Successful in 1m20s
Golang lint / lint (push) Successful in 4m8s

(fix): runtime reliability
(tests): regression coverage
(doc): v1.1 release notes
This commit is contained in:
2026-08-12 16:34:44 +03:00
parent 48ddf66540
commit f03a081ed6
83 changed files with 6122 additions and 1925 deletions
+18 -2
View File
@@ -1,6 +1,8 @@
package tgfmt
import "strings"
import (
"strings"
)
func escapeHTML(s string) string {
s = strings.ReplaceAll(s, "&", "&")
@@ -9,7 +11,21 @@ func escapeHTML(s string) string {
s = strings.ReplaceAll(s, `"`, """)
return s
}
func escapeRich(s string) Rich { return Rich(escapeHTML(s)) }
func escapeMD(s string) string {
s = strings.ReplaceAll(s, "_", `\_`)
s = strings.ReplaceAll(s, "*", `\*`)
s = strings.ReplaceAll(s, "[", `\[`)
s = strings.ReplaceAll(s, "`", "\\`")
return s
}
func escapeMDv2(s string) string {
symbols := []string{"\\", "_", "*", "[", "]", "(", ")", "~", "`", ">", "#", "+", "-", "=", "|", "{", "}", ".", "!"}
for _, symbol := range symbols {
s = strings.ReplaceAll(s, symbol, "\\"+symbol)
}
return s
}
// EscapePunctuation escapes '.', '!' and '-' for MarkdownV2 fragments.
func EscapePunctuation(s string) string {