all repos — grayfriday @ c26fdef40e09685eebc206d07bbbea9ddfc3c177

blackfriday fork with a few changes

Move html entity regexp to where it's used

And unify regexp variable names.
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 11 Apr 2016 11:28:05 +0300
commit

c26fdef40e09685eebc206d07bbbea9ddfc3c177

parent

c207eca993c2bdbe6130ac017352ea5614eb2bbe

2 files changed, 6 insertions(+), 5 deletions(-)

jump to
M html.gohtml.go

@@ -60,9 +60,7 @@ ProcessingInstruction + "|" + Declaration + "|" + CDATA + ")"

) 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 (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) }
M inline.goinline.go

@@ -22,6 +22,9 @@

var ( urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+` anchorRe = regexp.MustCompile(`^(<a\shref="` + urlRe + `"(\stitle="[^"<>]+")?\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 @@ return end

} 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 }