附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

trim_html.go 865 B

2 maanden geleden
1234567891011121314151617181920212223242526272829303132333435363738
  1. package utils
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. func TrimHtml(src string) string {
  7. re, _ := regexp.Compile("<[\\S\\s]+?>")
  8. src = re.ReplaceAllStringFunc(src, strings.ToLower)
  9. re, _ = regexp.Compile("<style[\\S\\s]+?</style>")
  10. src = re.ReplaceAllString(src, "")
  11. re, _ = regexp.Compile("<script[\\S\\s]+?</script>")
  12. src = re.ReplaceAllString(src, "")
  13. re, _ = regexp.Compile("<[\\S\\s]+?>")
  14. src = re.ReplaceAllString(src, "\n")
  15. re, _ = regexp.Compile("\\s{2,}")
  16. src = re.ReplaceAllString(src, "\n")
  17. return strings.TrimSpace(src)
  18. }
  19. func TrimScript(src string) string {
  20. re, _ := regexp.Compile("<[\\S\\s]+?>")
  21. src = re.ReplaceAllStringFunc(src, strings.ToLower)
  22. re, _ = regexp.Compile("<script[\\S\\s]+?</script>")
  23. src = re.ReplaceAllString(src, "")
  24. re, _ = regexp.Compile("<script[\\S\\s]+?>")
  25. src = re.ReplaceAllString(src, "")
  26. return src
  27. }