all repos — honk @ 73ad26f01d1da2b0c0d5745294b003ef9e2eac0d

my fork of honk

a few more autolink edge cases
Ted Unangst tedu@tedunangst.com
Mon, 21 Oct 2019 23:43:15 -0400
commit

73ad26f01d1da2b0c0d5745294b003ef9e2eac0d

parent

7d74b2c01be0a603994d5b1c43ce4f2db479b30f

2 files changed, 29 insertions(+), 3 deletions(-)

jump to
M markitzero.gomarkitzero.go

@@ -29,7 +29,7 @@ var re_italicer = regexp.MustCompile(`(^|\W)\*([\w\s,.!?':_-]+)\*($|\W)`)

var re_bigcoder = regexp.MustCompile("```(.*)\n?((?s:.*?))\n?```\n?") var re_coder = regexp.MustCompile("`([^`]*)`") var re_quoter = regexp.MustCompile(`(?m:^> (.*)\n?)`) -var re_link = regexp.MustCompile(`.?.?https?://[^\s"]+[\w/)]`) +var re_link = regexp.MustCompile(`.?.?https?://[^\s"]+[\w/)!]`) var re_zerolink = regexp.MustCompile(`\[([^]]*)\]\(([^)]*\)?)\)`) var lighter = synlight.New(synlight.Options{Format: synlight.HTML})

@@ -50,8 +50,21 @@ lilcodes = append(lilcodes, code)

return "`x`" }) - s = html.EscapeString(s) - s = strings.Replace(s, "&#39;", "'", -1) // dammit go + // fewer side effects than html.EscapeString + buf := make([]byte, 0, len(s)) + for _, c := range []byte(s) { + switch c { + case '&': + buf = append(buf, []byte("&amp;")...) + case '<': + buf = append(buf, []byte("&lt;")...) + case '>': + buf = append(buf, []byte("&gt;")...) + default: + buf = append(buf, c) + } + } + s = string(buf) // mark it zero s = re_bolder.ReplaceAllString(s, "$1<b>$2</b>$3")
M markitzero_test.gomarkitzero_test.go

@@ -58,3 +58,16 @@ input := "I watched [Hackers](https://en.wikipedia.org/wiki/Hackers_(film))"

output := `I watched <a class="mention u-url" href="https://en.wikipedia.org/wiki/Hackers_(film)">Hackers</a>` doonezerotest(t, input, output) } + +func TestQuotedlink(t *testing.T) { + input := `quoted "https://example.com/link" here` + output := `quoted "<a class="mention u-url" href="https://example.com/link">https://example.com/link</a>" here` + 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>` + doonezerotest(t, input, output) +} +