Skip to content

Commit

Permalink
Don't bother removing trailing newlines in code blocks
Browse files Browse the repository at this point in the history
The code that collects the block bytes has already removed the trialing
newlines, so this heavyweight regexp machinery is actually doing
nothing.
  • Loading branch information
rtfb committed Sep 10, 2016
1 parent 39b8ed1 commit e0fc1a0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const (
var (
reBackslashOrAmp = regexp.MustCompile("[\\&]")
reEntityOrEscapedChar = regexp.MustCompile("(?i)\\\\" + escapable + "|" + charEntity)
reTrailingWhitespace = regexp.MustCompile("(\n *)+$")
)

// Parse block-level data.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

2 comments on commit e0fc1a0

@Ambrevar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in commit message: s/trialing/trailing/

@rtfb
Copy link
Collaborator Author

@rtfb rtfb commented on e0fc1a0 Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll fix it if this branch will end up needing a rebase.

Please sign in to comment.