From c7ffa6ddda6dda76ec6327788dbb1ef3e17a2122 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 24 Oct 2019 23:38:36 -0400 Subject: [PATCH] reorder link matching to not eat other tags --- markitzero.go | 4 ++-- markitzero_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/markitzero.go b/markitzero.go index d83efbd..8c2ad57 100644 --- a/markitzero.go +++ b/markitzero.go @@ -72,11 +72,11 @@ func markitzero(s string) string { s = string(buf) // mark it zero + s = re_link.ReplaceAllStringFunc(s, linkreplacer) + s = re_zerolink.ReplaceAllString(s, `$1`) s = re_bolder.ReplaceAllString(s, "$1$2$3") s = re_italicer.ReplaceAllString(s, "$1$2$3") s = re_quoter.ReplaceAllString(s, "
$1

") - s = re_link.ReplaceAllStringFunc(s, linkreplacer) - s = re_zerolink.ReplaceAllString(s, `$1`) // restore images s = strings.Replace(s, "<img x>", "", -1) diff --git a/markitzero_test.go b/markitzero_test.go index d5a6b7a..79f5131 100644 --- a/markitzero_test.go +++ b/markitzero_test.go @@ -65,6 +65,19 @@ func TestQuotedlink(t *testing.T) { doonezerotest(t, input, output) } +func TestLinkinQuote(t *testing.T) { + input := `> a quote and https://example.com/link` + output := `

a quote and https://example.com/link

` + doonezerotest(t, input, output) +} + +func TestBoldLink(t *testing.T) { + t.SkipNow() + input := `**b https://example.com/link b**` + output := `b https://example.com/link b` + doonezerotest(t, input, output) +} + func TestHonklink(t *testing.T) { input := `https://en.wikipedia.org/wiki/Honk!` output := `https://en.wikipedia.org/wiki/Honk!`