From be5f3db54872196d326cd71b5dda24008790a5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AD=90=E8=B1=AA?= Date: Wed, 3 Mar 2021 23:32:05 +0800 Subject: [PATCH] Update 07.3.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix 通过正则修改内容中的代码未处理HTML转义的问题 --- zh/07.3.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/zh/07.3.md b/zh/07.3.md index 753c28ea..7db76694 100644 --- a/zh/07.3.md +++ b/zh/07.3.md @@ -75,23 +75,29 @@ func main() { src := string(body) //将HTML标签全转换成小写 - re, _ := regexp.Compile("\\<[\\S\\s]+?\\>") + re, _ := regexp.Compile(`<[\S\s]+?>`) src = re.ReplaceAllStringFunc(src, strings.ToLower) //去除STYLE - re, _ = regexp.Compile("\\") + re, _ = regexp.Compile(``) + src = re.ReplaceAllString(src, "") + //去除HTMLUnscape的STYLE + re, _ = regexp.Compile(`<style[\S\s]+?</style>`) src = re.ReplaceAllString(src, "") //去除SCRIPT - re, _ = regexp.Compile("\\") + re, _ = regexp.Compile(``) + src = re.ReplaceAllString(src, "") + //去除HTMLUnsapce的SCRIPT + re, _ = regexp.Compile(`<script[\S\s]+?</script>`) src = re.ReplaceAllString(src, "") //去除所有尖括号内的HTML代码,并换成换行符 - re, _ = regexp.Compile("\\<[\\S\\s]+?\\>") + re, _ = regexp.Compile(`<[\S\s]+?>`) src = re.ReplaceAllString(src, "\n") //去除连续的换行符 - re, _ = regexp.Compile("\\s{2,}") + re, _ = regexp.Compile(`\s{2,}`) src = re.ReplaceAllString(src, "\n") fmt.Println(strings.TrimSpace(src))