fix(md030): keep nested content attached when a marker widens#657
Merged
rvben merged 2 commits intoJun 6, 2026
Merged
Conversation
Contributor
Author
|
Let me know if you'd like these changes re-organized in any way, or if there is a better way to do this. One thing that I did consider but ended up not doing is merging MD077's logic into MD030, so that a single pass of logic can both indent and outdent as needed. But it seemed better to not disturb the structure of the different checks. |
Contributor
Author
|
(Also, just to be clear, I'm still a Rust novice, so many apologies if any of this is totally wrong or not using the right idioms.) |
Pull the inline "does this following line continue the item?" logic out of `is_multi_line_list_item` into a reusable classifier: a `Continuation` enum (`Belongs`/`Skip`/`Ends`), `continuation_params` (an item's marker column and blockquote-aware indent threshold), and `classify_continuation` (the per-line decision). `is_multi_line_list_item` becomes a small loop over the classifier. Pure refactoring with no behavior change. The richer three-state API is what later work uses to enumerate an item's continuation lines, not just test whether any exist. Assisted-by: Claude
MD030 fixes the spaces after a list marker, but when that fix *widens* a multi-line item's marker indent, it only moved the content on the same line as the marker, leaving the continuation content behind. For a nested list that detaches it: the child marker ends up left of the parent's content column and flattens into a sibling. With a configured `ol-multi`/`ul-multi` greater than the current spacing, `--fix` could therefore corrupt the document, and no other rule recovers it. Track the open list items on a stack, each carrying its cumulative indent shift (its own marker re-spacing plus every ancestor's), and re-indent continuation and nested lines to follow a widened marker. The shifts accumulate across nesting levels in a single pass. An inline nested bullet that shares the marker's line (`- x` in `1. - x`) is spaced and shifted like a sibling bullet. Re-indent only when content must move *right*. Narrowing leaves content over-indented but still attached, which MD077 (list continuation indentation) tightens, so MD030 leaves that to it. The idea is that MD030 owns under-indent, MD077 owns over-indent. The whole mechanism is skipped unless a configured spacing exceeds 1, so the default configuration is unaffected. Assisted-by: Claude
Owner
|
Looks good @chandlerc, nice 👌 I'll merge them in 🚀 |
d728c2b to
594d2b3
Compare
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.
MD030 fixes the spaces after a list marker, but when that fix widens a
multi-line item's marker indent, it only moved the content on the same line as
the marker, leaving the continuation content behind. For a nested list that
detaches it: the child marker ends up left of the parent's content column and
flattens into a sibling. With a configured
ol-multi/ul-multigreater thanthe current spacing,
--fixcould therefore corrupt the document, and no otherrule recovers it.
Track the open list items on a stack, each carrying its cumulative indent shift
(its own marker re-spacing plus every ancestor's), and re-indent continuation
and nested lines to follow a widened marker. The shifts accumulate across
nesting levels in a single pass. An inline nested bullet that shares the
marker's line (
- xin1. - x) is spaced and shifted like a sibling bullet.Re-indent only when content must move right. Narrowing leaves content
over-indented but still attached, which MD077 (list continuation
indentation) tightens, so MD030 leaves that to it. The idea is that
MD030 owns under-indent, MD077 owns over-indent.
The whole mechanism is skipped unless a configured spacing exceeds 1, so
the default configuration is unaffected.
There is a pure refactor commit first to expose needed functionality,
followed by the fix itself.
This also introduces a use of
indocto allow for easier construction ofmulti-line test cases with visible indentation structures.
This is a first step towards fixing #644.