Merge branch 'feat/cut-text' into 'test'

Feat/cut text

See merge request opensource/answer!215
This commit is contained in:
杨光富 2022-11-10 03:32:16 +00:00
commit 5c90f99397
2 changed files with 4 additions and 4 deletions

View File

@ -17,8 +17,8 @@ func ClearText(html string) (text string) {
re *regexp.Regexp
codeReg = `(?ism)<(pre)>.*<\/pre>`
codeRepl = "{code...}"
linkReg = `(?ism)<a.*?[^<]>.*?<\/a>`
linkRepl = "[link]"
linkReg = `(?ism)<a.*?[^<]>(.*)?<\/a>`
linkRepl = " [$1] "
spaceReg = ` +`
spaceRepl = " "
)

View File

@ -17,8 +17,8 @@ func TestClearText(t *testing.T) {
assert.Equal(t, expected, clearedText)
// test link clear text
expected = "hello[link]"
clearedText = ClearText("<p>hello<a href=\"http://example.com/\">example.com</a></p>")
expected = "hello [example.com]"
clearedText = ClearText("<p>hello <a href=\"http://example.com/\">example.com</a></p>")
assert.Equal(t, expected, clearedText)
clearedText = ClearText("<p>hello<a href=\"https://example.com/\">example.com</a></p>")
assert.Equal(t, expected, clearedText)