Skip to content

Question: An extra blank line at the end of the code block #685

Answered by colinodell
ngmy asked this question in Q&A
Discussion options

You must be logged in to vote

Good question! The CommonMark spec says:

The content of a code fence is treated as literal text

Because hogehoge is followed by a newline character before the final fence, that newline gets included.

There is no built-in way to remove that trailing newline character, but you could implement a custom event listener that listens for the DocumentParsedEvent, walks the AST looking for FencedCode notes, and then perform an rtrim() on the contents. Unfortunately, 1.x doesn't provide functionality to modify those contents, but 2.0 will! For 1.x you'd instead need to implement a custom renderer for FencedCode objects and strip the trailing newline that way.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ngmy
Comment options

Answer selected by ngmy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants