mirror of
https://github.com/danog/blackfriday.git
synced 2025-01-23 05:41:27 +01:00
More lint: block.go
This commit is contained in:
parent
cd2f079140
commit
6d7f5e1bca
23
block.go
23
block.go
@ -22,13 +22,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Entity = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});"
|
charEntity = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});"
|
||||||
Escapable = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]"
|
escapable = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
reBackslashOrAmp = regexp.MustCompile("[\\&]")
|
reBackslashOrAmp = regexp.MustCompile("[\\&]")
|
||||||
reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + Escapable + "|" + Entity)
|
reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + escapable + "|" + charEntity)
|
||||||
reTrailingWhitespace = regexp.MustCompile("(\n *)+$")
|
reTrailingWhitespace = regexp.MustCompile("(\n *)+$")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -279,9 +279,8 @@ func (p *parser) isUnderlinedHeader(data []byte) int {
|
|||||||
i = skipChar(data, i, ' ')
|
i = skipChar(data, i, ' ')
|
||||||
if data[i] == '\n' {
|
if data[i] == '\n' {
|
||||||
return 1
|
return 1
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// test of level 2 header
|
// test of level 2 header
|
||||||
@ -290,9 +289,8 @@ func (p *parser) isUnderlinedHeader(data []byte) int {
|
|||||||
i = skipChar(data, i, ' ')
|
i = skipChar(data, i, ' ')
|
||||||
if data[i] == '\n' {
|
if data[i] == '\n' {
|
||||||
return 2
|
return 2
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -414,13 +412,13 @@ func (p *parser) html(data []byte, doRender bool) int {
|
|||||||
for end > 0 && data[end-1] == '\n' {
|
for end > 0 && data[end-1] == '\n' {
|
||||||
end--
|
end--
|
||||||
}
|
}
|
||||||
finalizeHtmlBlock(p.addBlock(HTMLBlock, data[:end]))
|
finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end]))
|
||||||
}
|
}
|
||||||
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func finalizeHtmlBlock(block *Node) {
|
func finalizeHTMLBlock(block *Node) {
|
||||||
block.Literal = reTrailingWhitespace.ReplaceAll(block.content, []byte{})
|
block.Literal = reTrailingWhitespace.ReplaceAll(block.content, []byte{})
|
||||||
block.content = []byte{}
|
block.content = []byte{}
|
||||||
}
|
}
|
||||||
@ -438,7 +436,7 @@ func (p *parser) htmlComment(data []byte, doRender bool) int {
|
|||||||
end--
|
end--
|
||||||
}
|
}
|
||||||
block := p.addBlock(HTMLBlock, data[:end])
|
block := p.addBlock(HTMLBlock, data[:end])
|
||||||
finalizeHtmlBlock(block)
|
finalizeHTMLBlock(block)
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
@ -470,7 +468,7 @@ func (p *parser) htmlHr(data []byte, doRender bool) int {
|
|||||||
for end > 0 && data[end-1] == '\n' {
|
for end > 0 && data[end-1] == '\n' {
|
||||||
end--
|
end--
|
||||||
}
|
}
|
||||||
finalizeHtmlBlock(p.addBlock(HTMLBlock, data[:end]))
|
finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end]))
|
||||||
}
|
}
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
@ -729,9 +727,8 @@ func unescapeChar(str []byte) []byte {
|
|||||||
func unescapeString(str []byte) []byte {
|
func unescapeString(str []byte) []byte {
|
||||||
if reBackslashOrAmp.Match(str) {
|
if reBackslashOrAmp.Match(str) {
|
||||||
return reEntityOrEscapedChar.ReplaceAllFunc(str, unescapeChar)
|
return reEntityOrEscapedChar.ReplaceAllFunc(str, unescapeChar)
|
||||||
} else {
|
|
||||||
return str
|
|
||||||
}
|
}
|
||||||
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
func finalizeCodeBlock(block *Node) {
|
func finalizeCodeBlock(block *Node) {
|
||||||
|
@ -492,7 +492,7 @@ func (p *parser) parseRefsToAST() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.tip = p.doc
|
p.tip = p.doc
|
||||||
finalizeHtmlBlock(p.addBlock(HTMLBlock, []byte(`<div class="footnotes">`)))
|
finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte(`<div class="footnotes">`)))
|
||||||
p.addBlock(HorizontalRule, nil)
|
p.addBlock(HorizontalRule, nil)
|
||||||
block := p.addBlock(List, nil)
|
block := p.addBlock(List, nil)
|
||||||
block.ListFlags = ListTypeOrdered
|
block.ListFlags = ListTypeOrdered
|
||||||
@ -518,7 +518,7 @@ func (p *parser) parseRefsToAST() {
|
|||||||
above := block.Parent
|
above := block.Parent
|
||||||
finalizeList(block)
|
finalizeList(block)
|
||||||
p.tip = above
|
p.tip = above
|
||||||
finalizeHtmlBlock(p.addBlock(HTMLBlock, []byte("</div>")))
|
finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte("</div>")))
|
||||||
block.Walk(func(node *Node, entering bool) WalkStatus {
|
block.Walk(func(node *Node, entering bool) WalkStatus {
|
||||||
if node.Type == Paragraph || node.Type == Header {
|
if node.Type == Paragraph || node.Type == Header {
|
||||||
p.currBlock = node
|
p.currBlock = node
|
||||||
|
Loading…
x
Reference in New Issue
Block a user