@@ -75,23 +75,29 @@ func main() {
75
75
src := string (body)
76
76
77
77
// 将HTML标签全转换成小写
78
- re , _ := regexp.Compile (" \\ <[\\ S \\ s]+?\\ > " )
78
+ re , _ := regexp.Compile (` <[\S\ s]+?> ` )
79
79
src = re.ReplaceAllStringFunc (src, strings.ToLower )
80
80
81
81
// 去除STYLE
82
- re, _ = regexp.Compile (" \\ <style[\\ S\\ s]+?\\ </style\\ >" )
82
+ re, _ = regexp.Compile (` <style[\S\s]+?</style>` )
83
+ src = re.ReplaceAllString (src, " " )
84
+ // 去除HTMLUnscape的STYLE
85
+ re, _ = regexp.Compile (` <style[\S\s]+?</style>` )
83
86
src = re.ReplaceAllString (src, " " )
84
87
85
88
// 去除SCRIPT
86
- re, _ = regexp.Compile (" \\ <script[\\ S\\ s]+?\\ </script\\ >" )
89
+ re, _ = regexp.Compile (` <script[\S\s]+?</script>` )
90
+ src = re.ReplaceAllString (src, " " )
91
+ // 去除HTMLUnsapce的SCRIPT
92
+ re, _ = regexp.Compile (` <script[\S\s]+?</script>` )
87
93
src = re.ReplaceAllString (src, " " )
88
94
89
95
// 去除所有尖括号内的HTML代码,并换成换行符
90
- re, _ = regexp.Compile (" \\ <[\\ S \\ s]+?\\ > " )
96
+ re, _ = regexp.Compile (` <[\S\ s]+?> ` )
91
97
src = re.ReplaceAllString (src, " \n " )
92
98
93
99
// 去除连续的换行符
94
- re, _ = regexp.Compile (" \\ s{2,}" )
100
+ re, _ = regexp.Compile (` \ s{2,}` )
95
101
src = re.ReplaceAllString (src, " \n " )
96
102
97
103
fmt.Println (strings.TrimSpace (src))
0 commit comments