Repository navigation
fix(MD034): recognize link definitions whose URL is on the next line - #995
Conversation
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.
|
Thanks @joshka for the fix and regression tests! Merging. |
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.
|
Thanks! The failing Test job was from two existing tests that expected the old behaviour. I've pushed a07cf57 to update them:
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 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. |
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:
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:.mdfiles, 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..mdxfiles, 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 usesctx.reference_definitions()now sees these definitions.<…>.Known gaps
titleis not filled in yet (None). The destination and span are correct.Testing
cargo test --test lib md034andcargo test --lib lint_contextpass.feature-flags.md,widgets.mdx) withreflowon,rumdl checkno longer reports these lines, andrumdl fmtleaves 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.