Files
mir-godot/service/framework/utils/markdown.go
MakerYang a902dd3de7 new
2024-08-06 18:30:21 +08:00

35 lines
809 B
Go

/**
#*****************************************************************************
# @author MakerYang
# @site mir2.makeryang.com
#*****************************************************************************
*/
package Utils
import (
"regexp"
"strings"
)
func FilterMarkdown(input string) string {
quoteBlockRegex := regexp.MustCompile(`^\s*>[ \t]*(.*)$`)
lines := strings.Split(input, "\n")
var quoteLines []string
for _, line := range lines {
if quoteBlockRegex.MatchString(line) {
match := quoteBlockRegex.FindStringSubmatch(line)
quoteLines = append(quoteLines, match[1])
}
}
return strings.Join(quoteLines, "")
}
func FilterSummary(input string, maxLength int) string {
text := strings.TrimSpace(input)
if len(text) <= maxLength {
return text
}
return text[:maxLength]
}