some fixes

This commit is contained in:
2026-01-14 12:07:05 +03:00
parent 0cc146edd9
commit b88715d6d3
3 changed files with 135 additions and 21 deletions

View File

@@ -1,6 +1,10 @@
package laniakea
import "encoding/json"
import (
"encoding/json"
"fmt"
"strings"
)
func MapToStruct(m map[string]interface{}, s interface{}) error {
data, err := json.Marshal(m)
@@ -33,3 +37,18 @@ func Map[T, V any](ts []T, fn func(T) V) []V {
}
return result
}
func EscapeMarkdown(s string) string {
s = strings.ReplaceAll(s, "_", "\\_")
s = strings.ReplaceAll(s, "*", "\\*")
s = strings.ReplaceAll(s, "[", "\\[")
return strings.ReplaceAll(s, "`", "\\`")
}
func EscapeMarkdownV2(s string) string {
symbols := []string{"_", "*", "[", "]", "(", ")", "~", "`", ">", "#", "+", "-", "=", "|", "{", "}", ".", "!"}
for _, symbol := range symbols {
s = strings.ReplaceAll(s, symbol, fmt.Sprintf("\\%s", symbol))
}
return s
}