fix: fetch excerpt, if contain link, show link name
This commit is contained in:
@@ -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 = " "
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user