From 6d7f5e1bcab8da61c61f85ae261fca17d3bdc5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Wed, 27 Jul 2016 21:40:45 +0300 Subject: [PATCH] More lint: block.go --- block.go | 23 ++++++++++------------- markdown.go | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/block.go b/block.go index c347965..d78147b 100644 --- a/block.go +++ b/block.go @@ -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) { diff --git a/markdown.go b/markdown.go index 60b6516..9fb4dff 100644 --- a/markdown.go +++ b/markdown.go @@ -492,7 +492,7 @@ func (p *parser) parseRefsToAST() { return } p.tip = p.doc - finalizeHtmlBlock(p.addBlock(HTMLBlock, []byte(`
`))) + finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte(`
`))) 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("
"))) + finalizeHTMLBlock(p.addBlock(HTMLBlock, []byte("
"))) block.Walk(func(node *Node, entering bool) WalkStatus { if node.Type == Paragraph || node.Type == Header { p.currBlock = node