FILE / ScuroNeko/Laniakea

tgfmt/utils.go

Исходный файл и его история в репозитории.
FILE 48ddf665401d1581e6362d9fad01db03a359cec3
Files
Laniakea/tgfmt/utils.go
T
ScuroNekoandClaude Fable 5 48ddf66540
Golang lint / lint (push) Successful in 29s
Golang lint / lint (pull_request) Successful in 1m47s
(new): rich messages, tgfmt DSL, Bot API 10.1
(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>
2026-07-08 12:45:47 +03:00

22 lines
554 B
Go

package tgfmt
import "strings"
func escapeHTML(s string) string {
s = strings.ReplaceAll(s, "&", "&amp;")
s = strings.ReplaceAll(s, "<", "&lt;")
s = strings.ReplaceAll(s, ">", "&gt;")
s = strings.ReplaceAll(s, `"`, "&quot;")
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
}