Skip to content

fix(MD034): recognize link definitions whose URL is on the next line - #995

Merged
rvben merged 2 commits into
rvben:mainfrom
joshka:fix/md034-wrapped-ref-definitions
Nov 12, 2026
Merged

rvben merged 2 commits into
rvben:mainfrom
joshka:fix/md034-wrapped-ref-definitions

Conversation

@joshka

@joshka joshka commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary

I found this while moving ratatui-website from markdownlint to rumdl.

A link reference definition may put its destination on the line after the label (CommonMark allows one line ending there; see example 193). Prettier and markdownlint wrap long definitions this way, and GitHub and VS Code render them correctly:

[feature definitions]:
  https://github.com/ratatui/ratatui/blob/ratatui-v0.30.2/ratatui/Cargo.toml#L23-L115

rumdl matched definitions one line at a time, so it never recognised a line holding only [label]: as a definition. The URL line below it was read as prose, and MD034 (no-bare-urls) "fixed" it:

  • In .md files, the URL was wrapped in <…>. That's still valid, but it's an unrequested change, and Prettier strips the brackets again, so the two tools fight.
  • In .mdx files, the URL was rewritten as [url](url). That breaks the definition, so every reference to it stops resolving.

Changes

  • parse_reference_defs: when a line is only [label]:, take pulldown-cmark's parsed definition at that offset for the destination and the full byte span. Every rule that uses ctx.reference_definitions() now sees these definitions.
  • MD034: skip every line a definition spans, not just its first line.
  • Add a regression test covering indented and unindented destination lines and a title, under the Standard and MDX flavors. A real bare URL in the same document is still flagged.
  • Add a test that the fix leaves a markdownlint/Prettier-style definition (URL indented on the next line) unchanged, under both flavors. Without this change it fails: the URL gets wrapped in <…>.

Known gaps

  • For these definitions, title is not filled in yet (None). The destination and span are correct.
  • MD053 (unused definitions) has its own detection and still misses unused wrapped definitions. That was already true before this change.

Testing

  • cargo test --test lib md034 and cargo test --lib lint_context pass.
  • On real ratatui-website docs (feature-flags.md, widgets.mdx) with reflow on, rumdl check no longer reports these lines, and rumdl fmt leaves the files unchanged.

This change was written with AI assistance (Claude Code). Feel free to modify it and ship it however suits you, or treat it as a bug report rather than an implementation if that helps move this forward.

A link reference definition may put its destination on the line after
the label (CommonMark example 193), as markdownlint and Prettier wrap
long definitions. The line-by-line definition parser never recognized
a line holding only `[label]:`, so MD034 treated the URL below it as
a bare URL: it wrapped it in `<…>` in Markdown and rewrote it as
`[url](url)` in MDX, which broke the definition.

Take the parser's reading of such a definition, and have MD034 skip
every line a definition spans.

rvben commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @joshka for the fix and regression tests! Merging.

rvben
rvben previously approved these changes Nov 12, 2026
Two tests pinned the old behaviour: MD034 rewriting the URL, or an
email in the title, on the line after a definition's label. Those
lines are part of the definition (CommonMark example 193), so the fix
now leaves them as written, matching a definition on one line.
@joshka

joshka commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks! The failing Test job was from two existing tests that expected the old behaviour. I've pushed a07cf57 to update them:

  • format_proof::tests::reference_url_certificates_follow_native_line_and_destination_guards expected MD034 to rewrite [x]:\n https://example.com and [x]: https://example.com\n "[email protected]". Both are definitions (the second has its title on the next line), so the fix now leaves them unchanged, as it already did for the one-line forms. The old fix also turned an email inside a title into "<[email protected]>", putting literal brackets into the title text.
  • cli::silent_format_test::silent_format_keeps_native_urls_in_reference_continuations_and_empty_labels had the same two shapes. CI stopped before reaching it. The ![atom][r] and [atom][r] cases there are still expected to be fixed.

One thing to note: the format proof doesn't establish ahead of time that MD034 leaves these wrapped definitions unchanged, so the rule still runs on them. That's the conservative direction. The updated test checks the fix result and assert_proofs without requiring policy.proven(...). If you'd rather the proof cover these too, I'm happy to look at that or leave it to you.

Locally, the full nextest run passes apart from six code-block-tool and vendor-directory tests that also fail for me in isolation and don't touch this change. CI's code-block tools jobs pass.

Note that I'm less certain of these changes - I'm a bit unfamiliar with this code, and letting my agent fix the CI with what it though was best - happy for you to take the reins on this if you have better ideas on how it should be fixed or if you have objections to AI code like this.

@rvben
rvben merged commit 2db197f into rvben:main Nov 12, 2026
15 checks passed
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