|
1234567891011121314151617181920212223242526272829303132333435363738 |
- package utils
-
- import (
- "regexp"
- "strings"
- )
-
- func TrimHtml(src string) string {
- re, _ := regexp.Compile("<[\\S\\s]+?>")
- src = re.ReplaceAllStringFunc(src, strings.ToLower)
-
- re, _ = regexp.Compile("<style[\\S\\s]+?</style>")
- src = re.ReplaceAllString(src, "")
-
- re, _ = regexp.Compile("<script[\\S\\s]+?</script>")
- src = re.ReplaceAllString(src, "")
-
- re, _ = regexp.Compile("<[\\S\\s]+?>")
- src = re.ReplaceAllString(src, "\n")
-
- re, _ = regexp.Compile("\\s{2,}")
- src = re.ReplaceAllString(src, "\n")
-
- return strings.TrimSpace(src)
- }
-
- func TrimScript(src string) string {
- re, _ := regexp.Compile("<[\\S\\s]+?>")
- src = re.ReplaceAllStringFunc(src, strings.ToLower)
- re, _ = regexp.Compile("<script[\\S\\s]+?</script>")
- src = re.ReplaceAllString(src, "")
-
- re, _ = regexp.Compile("<script[\\S\\s]+?>")
-
- src = re.ReplaceAllString(src, "")
-
- return src
- }
|