reorder link matching to not eat other tags
Ted Unangst tedu@tedunangst.com
Thu, 24 Oct 2019 23:38:36 -0400
2 files changed,
15 insertions(+),
2 deletions(-)
M
markitzero.go
→
markitzero.go
@@ -72,11 +72,11 @@ }
s = string(buf) // 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_italicer.ReplaceAllString(s, "$1<i>$2</i>$3") 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 s = strings.Replace(s, "<img x>", "<img x>", -1)
M
markitzero_test.go
→
markitzero_test.go
@@ -65,6 +65,19 @@ output := `quoted "<a class="mention u-url" href="https://example.com/link">https://example.com/link</a>" here`
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) { 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>`