Add optional blank line preservation (MD_FLAG_PRESERVEBLANKLINES) - #385
Merged
mity merged 5 commits intoAug 17, 2026
Merged
Conversation
mity
requested changes
Aug 10, 2026
mity
left a comment
Owner
There was a problem hiding this comment.
Looks as the right approach to me. There are some requested changes though.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #385 +/- ##
==========================================
+ Coverage 78.86% 78.87% +0.01%
==========================================
Files 5 5
Lines 3794 3820 +26
Branches 1271 1279 +8
==========================================
+ Hits 2992 3013 +21
- Misses 297 298 +1
- Partials 505 509 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mity
approved these changes
Aug 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #384.
Motivation
When rendering from the MD4C callback stream (e.g. building a native view tree for a WYSIWYG-like editor), the number of blank lines the author typed between blocks is meaningful. CommonMark collapses any run of blank lines into a single block boundary, and MD4C discards this information in the process so it can't be recovered downstream without pre-processing the source. This adds an opt-in way to get that information from the parser.
What this does
Adds the flag
MD_FLAG_PRESERVEBLANKLINES. When enabled, each run of blank lines separating two blocks is reported as a single new blockMD_BLOCK_BLANK, whose detailMD_BLOCK_BLANK_DETAILcarries the number of blank lines:Following the discussion in #384, the run is coalesced into one block (the count is stored once, not one block per line), and all blank lines are reported - i.e. the arser reports "this block separation is made of N blank lines" and leaves the rendering decision to the application.
With the flag off, behaviour and output are byte-for-byte unchanged.
Semantics
MD_BLOCK_BLANKper run; noMD_TEXTis sent.md2html gains --fpreserve-blank-lines; its renderer emits count non-breaking-space paragraphs so the count is visible/testable.
Note: Blank lines trailing a list's last item (before a dedented paragraph that ends the list) currently attach inside that last
<li>, consistent with the "innermost open container" rule. Happy to tweak those semantics, if you'd prefer. Documented with a test intest/coverage.txtTests & docs
CRLFverified manually but not added as a spec test (the .txt files are LF-only).