More lint: block.go

This commit is contained in:
Vytautas Šaltenis 2016-07-27 21:40:45 +03:00
parent cd2f079140
commit 6d7f5e1bca
2 changed files with 12 additions and 15 deletions

View File

@ -22,13 +22,13 @@ import (
)
const (
Entity = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});"
Escapable = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]"
charEntity = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});"
escapable = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]"
)
var (
reBackslashOrAmp = regexp.MustCompile("[\\&]")
reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + Escapable + "|" + Entity)
reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + escapable + "|" + charEntity)
reTrailingWhitespace = regexp.MustCompile("(\n *)+$")
)
@ -279,9 +279,8 @@ func (p *parser) isUnderlinedHeader(data []byte) int {
i = skipChar(data, i, ' ')
if data[i] == '\n' {
return 1
} else {
return 0
}
return 0
}
// test of level 2 header
@ -290,9 +289,8 @@ func (p *parser) isUnderlinedHeader(data []byte) int {
i = skipChar(data, i, ' ')
if data[i] == '\n' {
return 2
} else {
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' {
end--
}
finalizeHtmlBlock(p.addBlock(HTMLBlock, data[:end]))
finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end]))
}
return i
}
func finalizeHtmlBlock(block *Node) {
func finalizeHTMLBlock(block *Node) {
block.Literal = reTrailingWhitespace.ReplaceAll(block.content, []byte{})
block.content = []byte{}
}
@ -438,7 +436,7 @@ func (p *parser) htmlComment(data []byte, doRender bool) int {
end--
}
block := p.addBlock(HTMLBlock, data[:end])
finalizeHtmlBlock(block)
finalizeHTMLBlock(block)
}
return size
}
@ -470,7 +468,7 @@ func (p *parser) htmlHr(data []byte, doRender bool) int {
for end > 0 && data[end-1] == '\n' {
end--
}
finalizeHtmlBlock(p.addBlock(HTMLBlock, data[:end]))
finalizeHTMLBlock(p.addBlock(HTMLBlock, data[:end]))
}
return size
}
@ -729,9 +727,8 @@ func unescapeChar(str []byte) []byte {
func unescapeString(str []byte) []byte {
if reBackslashOrAmp.Match(str) {
return reEntityOrEscapedChar.ReplaceAllFunc(str, unescapeChar)
} else {
return str
}
return str
}
func finalizeCodeBlock(block *Node) {

View File

@ -492,7 +492,7 @@ func (p *parser) parseRefsToAST() {
return
}
p.tip = p.doc
finalizeHtmlBlock(p.addBlock(HTMLBlock, []byte(`<div class="footnotes">`)))
finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte(`<div class="footnotes">`)))
p.addBlock(HorizontalRule, nil)
block := p.addBlock(List, nil)
block.ListFlags = ListTypeOrdered
@ -518,7 +518,7 @@ func (p *parser) parseRefsToAST() {
above := block.Parent
finalizeList(block)
p.tip = above
finalizeHtmlBlock(p.addBlock(HTMLBlock, []byte("</div>")))
finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte("</div>")))
block.Walk(func(node *Node, entering bool) WalkStatus {
if node.Type == Paragraph || node.Type == Header {
p.currBlock = node