discordo/internal/markdown/markdown.go
cyberme0w c8b6e7f183
Replace user IDs with usernames in Mentions (#356)
Co-authored-by: Ayyan <119342035+ayn2op@users.noreply.github.com>
2024-03-17 16:23:37 +05:30

22 lines
706 B
Go

package markdown
import (
"regexp"
)
var (
boldRe = regexp.MustCompile(`(?ms)\*\*(.*?)\*\*`)
italicRe = regexp.MustCompile(`(?ms)\*(.*?)\*`)
underlineRe = regexp.MustCompile(`(?ms)__(.*?)__`)
strikethroughRe = regexp.MustCompile(`(?ms)~~(.*?)~~`)
codeblockRe = regexp.MustCompile("(?ms)`" + `([^` + "`" + `\n]+)` + "`")
)
func Parse(input string) string {
input = boldRe.ReplaceAllString(input, "[::b]$1[::B]")
input = italicRe.ReplaceAllString(input, "[::i]$1[::I]")
input = underlineRe.ReplaceAllString(input, "[::u]$1[::U]")
input = strikethroughRe.ReplaceAllString(input, "[::s]$1[::S]")
input = codeblockRe.ReplaceAllString(input, "[::r]$1[::R]")
return input
}