工具包
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.

39 line
876 B

  1. package zhios_tool_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. }