Files
MakerYang a902dd3de7 new
2024-08-06 18:30:21 +08:00

39 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
#*****************************************************************************
# @author MakerYang
# @site mir2.makeryang.com
#*****************************************************************************
*/
package Utils
import (
"github.com/russross/blackfriday"
"regexp"
"strings"
)
func TrimHtml(html string) string {
//将HTML标签全转换成小写
re, _ := regexp.Compile("<[\\S\\s]+?>")
html = re.ReplaceAllStringFunc(html, strings.ToLower)
//去除STYLE
re, _ = regexp.Compile("<style[\\S\\s]+?</style>")
html = re.ReplaceAllString(html, "")
//去除SCRIPT
re, _ = regexp.Compile("<script[\\S\\s]+?</script>")
html = re.ReplaceAllString(html, "")
//去除所有尖括号内的HTML代码并换成换行符
re, _ = regexp.Compile("<[\\S\\s]+?>")
html = re.ReplaceAllString(html, "\n")
//去除连续的换行符
re, _ = regexp.Compile("\\s{2,}")
html = re.ReplaceAllString(html, "\n")
return strings.TrimSpace(html)
}
func Markdown2Html(markdown string) string {
html := blackfriday.MarkdownCommon([]byte(markdown))
return string(html)
}