a few more autolink edge cases
This commit is contained in:
parent
b4901ad975
commit
f704326849
|
@ -29,7 +29,7 @@ var re_italicer = regexp.MustCompile(`(^|\W)\*([\w\s,.!?':_-]+)\*($|\W)`)
|
||||||
var re_bigcoder = regexp.MustCompile("```(.*)\n?((?s:.*?))\n?```\n?")
|
var re_bigcoder = regexp.MustCompile("```(.*)\n?((?s:.*?))\n?```\n?")
|
||||||
var re_coder = regexp.MustCompile("`([^`]*)`")
|
var re_coder = regexp.MustCompile("`([^`]*)`")
|
||||||
var re_quoter = regexp.MustCompile(`(?m:^> (.*)\n?)`)
|
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 re_zerolink = regexp.MustCompile(`\[([^]]*)\]\(([^)]*\)?)\)`)
|
||||||
|
|
||||||
var lighter = synlight.New(synlight.Options{Format: synlight.HTML})
|
var lighter = synlight.New(synlight.Options{Format: synlight.HTML})
|
||||||
|
@ -50,8 +50,21 @@ func markitzero(s string) string {
|
||||||
return "`x`"
|
return "`x`"
|
||||||
})
|
})
|
||||||
|
|
||||||
s = html.EscapeString(s)
|
// fewer side effects than html.EscapeString
|
||||||
s = strings.Replace(s, "'", "'", -1) // dammit go
|
buf := make([]byte, 0, len(s))
|
||||||
|
for _, c := range []byte(s) {
|
||||||
|
switch c {
|
||||||
|
case '&':
|
||||||
|
buf = append(buf, []byte("&")...)
|
||||||
|
case '<':
|
||||||
|
buf = append(buf, []byte("<")...)
|
||||||
|
case '>':
|
||||||
|
buf = append(buf, []byte(">")...)
|
||||||
|
default:
|
||||||
|
buf = append(buf, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s = string(buf)
|
||||||
|
|
||||||
// mark it zero
|
// mark it zero
|
||||||
s = re_bolder.ReplaceAllString(s, "$1<b>$2</b>$3")
|
s = re_bolder.ReplaceAllString(s, "$1<b>$2</b>$3")
|
||||||
|
|
|
@ -58,3 +58,16 @@ func TestWikilink(t *testing.T) {
|
||||||
output := `I watched <a class="mention u-url" href="https://en.wikipedia.org/wiki/Hackers_(film)">Hackers</a>`
|
output := `I watched <a class="mention u-url" href="https://en.wikipedia.org/wiki/Hackers_(film)">Hackers</a>`
|
||||||
doonezerotest(t, input, output)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue