FILE / ScuroNeko/Laniakea
tgfmt/utils.go
Исходный файл и его история в репозитории.
(fix): editMessageText rich_message type (tests): rich and API 10.1 coverage (doc): rich godoc, CHANGELOG v1.1.0 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
22 lines
554 B
Go
22 lines
554 B
Go
package tgfmt
|
|
|
|
import "strings"
|
|
|
|
func escapeHTML(s string) string {
|
|
s = strings.ReplaceAll(s, "&", "&")
|
|
s = strings.ReplaceAll(s, "<", "<")
|
|
s = strings.ReplaceAll(s, ">", ">")
|
|
s = strings.ReplaceAll(s, `"`, """)
|
|
return s
|
|
}
|
|
func escapeRich(s string) Rich { return Rich(escapeHTML(s)) }
|
|
|
|
// EscapePunctuation escapes '.', '!' and '-' for MarkdownV2 fragments.
|
|
func EscapePunctuation(s string) string {
|
|
symbols := []string{".", "!", "-"}
|
|
for _, symbol := range symbols {
|
|
s = strings.ReplaceAll(s, symbol, "\\"+symbol)
|
|
}
|
|
return s
|
|
}
|