Skip to content

fix(md030): keep nested content attached when a marker widens#657

Merged
rvben merged 2 commits into
rvben:mainfrom
chandlerc:fixmd030-keep-nested-content-attached-wh/pzqonlvmvoxt
Jun 6, 2026
Merged

fix(md030): keep nested content attached when a marker widens#657
rvben merged 2 commits into
rvben:mainfrom
chandlerc:fixmd030-keep-nested-content-attached-wh/pzqonlvmvoxt

Conversation

@chandlerc
Copy link
Copy Markdown
Contributor

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.

There is a pure refactor commit first to expose needed functionality,
followed by the fix itself.

This also introduces a use of indoc to allow for easier construction of
multi-line test cases with visible indentation structures.

This is a first step towards fixing #644.

@chandlerc
Copy link
Copy Markdown
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.

@chandlerc
Copy link
Copy Markdown
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.)

chandlerc added 2 commits June 6, 2026 13:45
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
@rvben
Copy link
Copy Markdown
Owner

rvben commented Jun 6, 2026

Looks good @chandlerc, nice 👌 I'll merge them in 🚀

@rvben rvben force-pushed the fixmd030-keep-nested-content-attached-wh/pzqonlvmvoxt branch from d728c2b to 594d2b3 Compare June 6, 2026 12:08
@rvben rvben merged commit 3bcc4c4 into rvben:main Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants