nechotron/markdown.go

22 lines
489 B
Go
Raw Normal View History

package nechotron
import (
2023-01-24 23:16:58 +03:00
"fmt"
"regexp"
"strings"
2023-01-24 23:16:58 +03:00
"github.com/NicoNex/echotron/v3"
)
var chars = []string{"_", "*", "\\[", "\\]", "\\(", "\\)", "~", "`", ">", "#", "+", "-", "=", "|", "{", "}", ".", "!"}
var r = strings.Join(chars, "")
var reg = regexp.MustCompile("[" + r + "]+")
func EscapeMd2(s string) string {
return reg.ReplaceAllString(s, "\\$0")
}
2023-01-24 23:16:58 +03:00
func UserMention(u *echotron.User) string {
return fmt.Sprintf("[%s](tg://user?id=%d)", EscapeMd2(u.FirstName), u.ID)
}