|
@@ -55,20 +55,8 @@ WHERE
|
|
|
switch reply_type {
|
|
|
case ReplyContentTEXT:
|
|
|
//编码及换行处理
|
|
|
- title = html.UnescapeString(title)
|
|
|
- title = strings.ReplaceAll(strings.ReplaceAll(title, "<br />", "\n"), "\\n", "\n")
|
|
|
- // 移除a标签中 title
|
|
|
- reTitle, _ := regexp.Compile("title=\"[^\"]*\"")
|
|
|
- title = reTitle.ReplaceAllString(title, "")
|
|
|
- // 使用正则表达式匹配HTML标签
|
|
|
- re, err := regexp.Compile("\\<[^a]+?\\>")
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error compiling regex:", err)
|
|
|
- } else {
|
|
|
- log.Println("---1---:", title)
|
|
|
- // 使用正则表达式的ReplaceAllString函数移除HTML标签
|
|
|
- title = re.ReplaceAllString(title, "")
|
|
|
- log.Println("---2---:", title)
|
|
|
+ title = ClearHtml(title)
|
|
|
+ if title != "" {
|
|
|
err := w.PostText(title)
|
|
|
if err != nil {
|
|
|
log.Println("文字 发送失败", err)
|
|
@@ -123,3 +111,22 @@ WHERE
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
+
|
|
|
+func ClearHtml(text string) string {
|
|
|
+ //编码及换行处理
|
|
|
+ text = html.UnescapeString(text)
|
|
|
+ text = strings.ReplaceAll(strings.ReplaceAll(text, "<br />", "\n"), "\\n", "\n")
|
|
|
+ // 移除a标签中 title
|
|
|
+ reTitle, _ := regexp.Compile("title=\"[^\"]*\"")
|
|
|
+ text = reTitle.ReplaceAllString(text, "")
|
|
|
+ // 使用正则表达式匹配HTML标签
|
|
|
+ re, err := regexp.Compile("\\<[^a]+?\\>")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error compiling regex:", err)
|
|
|
+ return ""
|
|
|
+ } else {
|
|
|
+ // 使用正则表达式的ReplaceAllString函数移除HTML标签
|
|
|
+ text = re.ReplaceAllString(text, "")
|
|
|
+ }
|
|
|
+ return text
|
|
|
+}
|