fix: fetch excerpt, if contain link, show link name

This commit is contained in:
kumfo
2022-11-10 11:23:07 +08:00
parent 7817b8e25a
commit 42f3154233
2 changed files with 4 additions and 4 deletions
+2 -2
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 = " "
)
+2 -2
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)