Repository navigation
End lists before trailing blank lines in mdast - #269
Open
ChristianMurphy wants to merge 1 commit into
Open
ChristianMurphy wants to merge 1 commit into
ChristianMurphy wants to merge 1 commit into
Conversation
Problem: containers exit after their trailing line endings, so `* a\n\n` ended the list at 5, where mdast-util-from-markdown ends it at 3. Changes: - On exit of a list, list item, or footnote definition, move the end back over trailing line endings and whitespace. A nested container already moved its end, so the walk stops there. - A list test, and one footnote position now matching micromark.
Murderlon
approved these changes
Oct 17, 2026
Murderlon
left a comment
Collaborator
There was a problem hiding this comment.
I authorized Codex to review this PR on my behalf.
No findings.
This branch has not been deployed
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.
Summary
In 1.0.0,
to_mdast("* a\n\n", &Default::default())ends the list and the list item at offset 5, after the blank line. mdast-util-from-markdown ends both at 3. GFM footnote definitions end late the same way.markdown-rs events exit a container after its trailing line endings and blank lines. mdast-util-from-markdown moves those ends back before them, in
prepareListfor list items. This does the same into_mdast, for lists, list items, and footnote definitions: on exit, it walks back over trailing line endings and whitespace. When the last child is a container, it reuses that child's moved end, so each line ending is walked once.Moving the exit events instead, as micromark does, gives the same trees but moves HTML line endings: 5 of 30,000 generated inputs regressed. Block quotes stay as they are: mdast-util-from-markdown keeps trailing
>lines inside the quote. HTML doesn't change.Performance
Callgrind, with one codegen unit, against 1.0.0 built the same way, across 7 option sets. On small documents, instructions change by −0.6% to +0.3%, within the noise of this method.
Tests
* a\n\nasserts the exact tree. One footnote definition intests/gfm_footnote.rsnow ends at offset 10, where mdast-util-from-markdown ends it.As of 2026-09-29, CI on
mainfails for two reasons unrelated to this change. One is a new clippy lint on Rust 1.98, and the other is the swc/serde build break. #230 fixes both.Claude, an AI assistant, helped me build this, and I reviewed it.