Skip to content

Commit

Permalink
Merge pull request #73 from go-ego/log-pr
Browse files Browse the repository at this point in the history
add filter html support
  • Loading branch information
vcaesar authored Oct 9, 2020
2 parents 7eb402a + 0a22955 commit ded4872
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,8 @@ func TestStop(t *testing.T) {

s = FilterLang(t1, "Han")
tt.Equal(t, "hibot机器人", s)

t2 := `<p>test: </p> <div> bot 机器人 <<银河系漫游指南>> </div>`
s = FilterHtml(t2)
tt.Equal(t, "test: bot 机器人 <<银河系漫游指南>> ", s)
}
8 changes: 8 additions & 0 deletions trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package gse

import (
"regexp"
"unicode"
"unicode/utf8"
)
Expand Down Expand Up @@ -161,6 +162,13 @@ func FilterSymbol(text string) (new string) {
return
}

// FilterHtml filter the html tag
func FilterHtml(text string) string {
regHtml := regexp.MustCompile(`(?U)\<[^>]*\w+\>`)
text = regHtml.ReplaceAllString(text, "")
return text
}

// FilterLang filter the language
func FilterLang(text, lang string) (new string) {
for _, value := range text {
Expand Down

0 comments on commit ded4872

Please sign in to comment.