From c26fdef40e09685eebc206d07bbbea9ddfc3c177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Mon, 11 Apr 2016 11:28:05 +0300 Subject: [PATCH] Move html entity regexp to where it's used And unify regexp variable names. --- html.go | 6 ++---- inline.go | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/html.go b/html.go index e344f91..a8fb6cd 100644 --- a/html.go +++ b/html.go @@ -60,9 +60,7 @@ const ( ) var ( - // TODO: improve this regexp to catch all possible entities: - htmlEntity = regexp.MustCompile(`&[a-z]{2,5};`) - reHtmlTag = regexp.MustCompile("(?i)^" + HTMLTag) + htmlTagRe = regexp.MustCompile("(?i)^" + HTMLTag) ) type HTMLRendererParameters struct { @@ -461,7 +459,7 @@ func escCode(text []byte, preserveEntities bool) []byte { func (r *HTML) out(w io.Writer, text []byte) { if r.disableTags > 0 { - w.Write(reHtmlTag.ReplaceAll(text, []byte{})) + w.Write(htmlTagRe.ReplaceAll(text, []byte{})) } else { w.Write(text) } diff --git a/inline.go b/inline.go index 6ca741a..2428876 100644 --- a/inline.go +++ b/inline.go @@ -22,6 +22,9 @@ import ( var ( urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+` anchorRe = regexp.MustCompile(`^(]+")?\s?>` + urlRe + `<\/a>)`) + + // TODO: improve this regexp to catch all possible entities: + htmlEntityRe = regexp.MustCompile(`&[a-z]{2,5};`) ) // Functions to parse text within a block @@ -742,7 +745,7 @@ func entity(p *parser, data []byte, offset int) int { } func linkEndsWithEntity(data []byte, linkEnd int) bool { - entityRanges := htmlEntity.FindAllIndex(data[:linkEnd], -1) + entityRanges := htmlEntityRe.FindAllIndex(data[:linkEnd], -1) return entityRanges != nil && entityRanges[len(entityRanges)-1][1] == linkEnd }