markdown.go 592 B

123456789101112131415161718192021222324252627
  1. package Utils
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. func FilterMarkdown(input string) string {
  7. quoteBlockRegex := regexp.MustCompile(`^\s*>[ \t]*(.*)$`)
  8. lines := strings.Split(input, "\n")
  9. var quoteLines []string
  10. for _, line := range lines {
  11. if quoteBlockRegex.MatchString(line) {
  12. match := quoteBlockRegex.FindStringSubmatch(line)
  13. quoteLines = append(quoteLines, match[1])
  14. }
  15. }
  16. return strings.Join(quoteLines, "")
  17. }
  18. func FilterSummary(input string, maxLength int) string {
  19. text := strings.TrimSpace(input)
  20. if len(text) <= maxLength {
  21. return text
  22. }
  23. return text[:maxLength]
  24. }