mirror of
https://github.com/danog/blackfriday.git
synced 2024-12-02 09:27:49 +01:00
Move html entity regexp to where it's used
And unify regexp variable names.
This commit is contained in:
parent
c207eca993
commit
c26fdef40e
6
html.go
6
html.go
@ -60,9 +60,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// TODO: improve this regexp to catch all possible entities:
|
htmlTagRe = regexp.MustCompile("(?i)^" + HTMLTag)
|
||||||
htmlEntity = regexp.MustCompile(`&[a-z]{2,5};`)
|
|
||||||
reHtmlTag = regexp.MustCompile("(?i)^" + HTMLTag)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HTMLRendererParameters struct {
|
type HTMLRendererParameters struct {
|
||||||
@ -461,7 +459,7 @@ func escCode(text []byte, preserveEntities bool) []byte {
|
|||||||
|
|
||||||
func (r *HTML) out(w io.Writer, text []byte) {
|
func (r *HTML) out(w io.Writer, text []byte) {
|
||||||
if r.disableTags > 0 {
|
if r.disableTags > 0 {
|
||||||
w.Write(reHtmlTag.ReplaceAll(text, []byte{}))
|
w.Write(htmlTagRe.ReplaceAll(text, []byte{}))
|
||||||
} else {
|
} else {
|
||||||
w.Write(text)
|
w.Write(text)
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@ import (
|
|||||||
var (
|
var (
|
||||||
urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+`
|
urlRe = `((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+`
|
||||||
anchorRe = regexp.MustCompile(`^(<a\shref="` + urlRe + `"(\stitle="[^"<>]+")?\s?>` + urlRe + `<\/a>)`)
|
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
|
// 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 {
|
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
|
return entityRanges != nil && entityRanges[len(entityRanges)-1][1] == linkEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user