microoptimization to avoid the more expensive regex
Ted Unangst tedu@tedunangst.com
Sat, 25 Jan 2020 19:11:58 -0500
1 files changed,
7 insertions(+),
3 deletions(-)
jump to
M
markitzero.go
→
markitzero.go
@@ -75,10 +75,14 @@ }
s = string(buf) // mark it zero - s = re_link.ReplaceAllStringFunc(s, linkreplacer) + if strings.Contains(s, "http") { + s = re_link.ReplaceAllStringFunc(s, linkreplacer) + } s = re_zerolink.ReplaceAllString(s, `<a href="$2">$1</a>`) - s = re_bolder.ReplaceAllString(s, "$1<b>$2</b>$3") - s = re_italicer.ReplaceAllString(s, "$1<i>$2</i>$3") + if strings.Contains(s, "*") { + 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<br><cite>$3</cite></blockquote><p>") s = re_reciter.ReplaceAllString(s, "$1$2$3") s = strings.Replace(s, "\n---\n", "<hr><p>", -1)