bump slog to v1.0.2

This commit is contained in:
2026-01-29 11:59:38 +03:00
parent 1d636c40a6
commit 6970c37c6b
4 changed files with 11 additions and 66 deletions

View File

@@ -73,57 +73,3 @@ func EscapeMarkdownV2(s string) string {
}
return s
}
func GetUnclosedTag(markdown string) string {
// order is important!
var tags = []string{
"```",
"`",
"*",
"_",
}
var currentTag = ""
markdownRunes := []rune(markdown)
var i = 0
outer:
for i < len(markdownRunes) {
// skip escaped characters (only outside tags)
if markdownRunes[i] == '\\' && currentTag == "" {
i += 2
continue
}
if currentTag != "" {
if strings.HasPrefix(string(markdownRunes[i:]), currentTag) {
// turn a tag off
i += len(currentTag)
currentTag = ""
continue
}
} else {
for _, tag := range tags {
if strings.HasPrefix(string(markdownRunes[i:]), tag) {
// turn a tag on
currentTag = tag
i += len(currentTag)
continue outer
}
}
}
i++
}
return currentTag
}
func IsValid(markdown string) bool {
return GetUnclosedTag(markdown) == ""
}
func FixMarkdown(markdown string) string {
tag := GetUnclosedTag(markdown)
if tag == "" {
return markdown
}
return markdown + tag
}