From e0fc1a0cb129d15ec82c8782d6c9424b1b3aae98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Sat, 10 Sep 2016 12:21:53 +0300 Subject: [PATCH] Don't bother removing trailing newlines in code blocks The code that collects the block bytes has already removed the trialing newlines, so this heavyweight regexp machinery is actually doing nothing. --- block.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block.go b/block.go index 42bed26..d5731d1 100644 --- a/block.go +++ b/block.go @@ -29,7 +29,6 @@ const ( var ( reBackslashOrAmp = regexp.MustCompile("[\\&]") reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + escapable + "|" + charEntity) - reTrailingWhitespace = regexp.MustCompile("(\n *)+$") ) // Parse block-level data. @@ -419,8 +418,8 @@ func (p *parser) html(data []byte, doRender bool) int { } func finalizeHTMLBlock(block *Node) { - block.Literal = reTrailingWhitespace.ReplaceAll(block.content, []byte{}) - block.content = []byte{} + block.Literal = block.content + block.content = nil } // HTML comment, lax form @@ -739,7 +738,7 @@ func finalizeCodeBlock(block *Node) { block.Info = unescapeString(bytes.Trim(firstLine, "\n")) block.Literal = rest } else { - block.Literal = reTrailingWhitespace.ReplaceAll(block.content, []byte{'\n'}) + block.Literal = block.content } block.content = nil }