markdown.go 588 B

1234567891011121314151617181920
  1. package discord
  2. import "regexp"
  3. var (
  4. boldRegex = regexp.MustCompile(`(?ms)\*\*(.*?)\*\*`)
  5. italicRegex = regexp.MustCompile(`(?ms)\*(.*?)\*`)
  6. underlineRegex = regexp.MustCompile(`(?ms)__(.*?)__`)
  7. strikeThroughRegex = regexp.MustCompile(`(?ms)~~(.*?)~~`)
  8. )
  9. func ParseMarkdown(md string) string {
  10. var res string
  11. res = boldRegex.ReplaceAllString(md, "[::b]$1[::-]")
  12. res = italicRegex.ReplaceAllString(res, "[::i]$1[::-]")
  13. res = underlineRegex.ReplaceAllString(res, "[::u]$1[::-]")
  14. res = strikeThroughRegex.ReplaceAllString(res, "[::s]$1[::-]")
  15. return res
  16. }