Repository navigation
Close open blocks of the last list item and footnote at end of input - #160
Merged
Merged
Conversation
At the end of the document, end_doc drops the empty line that ends an unclosed fenced code or HTML block, but only for blocks at the top level or in block quotes. In the last item of a list or in a footnote the block kept it: "- ```\n a\n" rendered as <pre><code>a\n\n</code></pre>. end_doc now also processes the blocks of the last list item and of footnotes.
This was referenced Oct 1, 2026
At the end of input, end_doc dropped the last line of an unclosed fenced
code or HTML block whenever its content span was empty, to remove the
empty line that follows a final newline. A last line that is blank only
after removing container markers or indentation ("- ```\n a\n ",
"> ```\n> a\n>", " ```\n a\n ") was dropped too, although it is
content. Only drop the line if its raw line is empty.
Found by Codex review.
end_doc now also visits the blocks of the last list item and of
footnotes, which may be closed fenced code blocks. Their last line can
be an empty line before the closing fence ("- ```\n a\n\n ```" without
a final newline), which was dropped as if it were the empty line after
a final newline. The same happened at the top level on main
("```\na\n\n```"). Only drop it from unclosed fenced code and HTML
blocks.
Found by Codex review.
Review feedback from Codex: the end-of-input tests only covered fenced code blocks.
Contributor
Author
|
Automated review: Codex CLI (
Codex could not run |
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.
Split out of #152.
Bug: at the end of the document,
end_docdrops the empty line that ends an unclosed fenced code block (or HTML block), but only for blocks at the top level or in block quotes. In the last item of a list or in a footnote, the block kept that line.Repro:
rendered
<pre><code>a\n\n</code></pre>. Expected<pre><code>a\n</code></pre>. Same in nested lists and footnotes.Fix:
end_docalso processes the blocks of the last list item and of footnotes before closing them.Second commit, from the Codex review: a last line is now dropped only if its raw line is empty, which is the line after a final newline. Before, any last line whose content span was empty was dropped. That included a line that is blank only after removing container markers or indentation, which is real content:
"- ```\n a\n ","> ```\n> a\n>"and" ```\n a\n "(no final newline) now keep it as an empty code line, as commonmark.js does. The block quote and indented-fence cases were already wrong onmain.Third commit, from the second Codex round: the line is dropped only from blocks that are still open (no closing fence, HTML end condition pending). Before, a closed fence's genuinely empty last line could be dropped:
"- ```\n a\n\n ```"and, already onmain,"```\na\n\n```"(no final newline) lost the empty line before the closing fence.Spec examples: none (the spec suite passes either way).
Tests:
src/cmark_html/unclosed_fence_in_container_test.mbt. It also checks that the list stays tight covers blank last lines without a final newline, and covers closed fences at the end of input.Depends on: nothing, independent of the other PRs.