reorder link matching to not eat other tags
This commit is contained in:
parent
8b80cdab6e
commit
c7ffa6ddda
|
@ -72,11 +72,11 @@ func markitzero(s string) string {
|
||||||
s = string(buf)
|
s = string(buf)
|
||||||
|
|
||||||
// mark it zero
|
// mark it zero
|
||||||
|
s = re_link.ReplaceAllStringFunc(s, linkreplacer)
|
||||||
|
s = re_zerolink.ReplaceAllString(s, `<a class="mention u-url" href="$2">$1</a>`)
|
||||||
s = re_bolder.ReplaceAllString(s, "$1<b>$2</b>$3")
|
s = re_bolder.ReplaceAllString(s, "$1<b>$2</b>$3")
|
||||||
s = re_italicer.ReplaceAllString(s, "$1<i>$2</i>$3")
|
s = re_italicer.ReplaceAllString(s, "$1<i>$2</i>$3")
|
||||||
s = re_quoter.ReplaceAllString(s, "<blockquote>$1</blockquote><p>")
|
s = re_quoter.ReplaceAllString(s, "<blockquote>$1</blockquote><p>")
|
||||||
s = re_link.ReplaceAllStringFunc(s, linkreplacer)
|
|
||||||
s = re_zerolink.ReplaceAllString(s, `<a class="mention u-url" href="$2">$1</a>`)
|
|
||||||
|
|
||||||
// restore images
|
// restore images
|
||||||
s = strings.Replace(s, "<img x>", "<img x>", -1)
|
s = strings.Replace(s, "<img x>", "<img x>", -1)
|
||||||
|
|
|
@ -65,6 +65,19 @@ func TestQuotedlink(t *testing.T) {
|
||||||
doonezerotest(t, input, output)
|
doonezerotest(t, input, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLinkinQuote(t *testing.T) {
|
||||||
|
input := `> a quote and https://example.com/link`
|
||||||
|
output := `<blockquote>a quote and <a class="mention u-url" href="https://example.com/link">https://example.com/link</a></blockquote><p>`
|
||||||
|
doonezerotest(t, input, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBoldLink(t *testing.T) {
|
||||||
|
t.SkipNow()
|
||||||
|
input := `**b https://example.com/link b**`
|
||||||
|
output := `<b>b <a class="mention u-url" href="https://example.com/link">https://example.com/link</a> b</b>`
|
||||||
|
doonezerotest(t, input, output)
|
||||||
|
}
|
||||||
|
|
||||||
func TestHonklink(t *testing.T) {
|
func TestHonklink(t *testing.T) {
|
||||||
input := `https://en.wikipedia.org/wiki/Honk!`
|
input := `https://en.wikipedia.org/wiki/Honk!`
|
||||||
output := `<a class="mention u-url" href="https://en.wikipedia.org/wiki/Honk!">https://en.wikipedia.org/wiki/Honk!</a>`
|
output := `<a class="mention u-url" href="https://en.wikipedia.org/wiki/Honk!">https://en.wikipedia.org/wiki/Honk!</a>`
|
||||||
|
|
Loading…
Reference in New Issue