Repository navigation
Fix #4207: Preserve display text for reference-style documentation links - #4226
Open
NamanGoyalK wants to merge 3 commits into
Open
NamanGoyalK wants to merge 3 commits into
NamanGoyalK wants to merge 3 commits into
Conversation
kevmoo
reviewed
Mar 7, 2026
Member
|
You sent a PR with TESTS. I gotta help you out. @srawlins is likely the person who will need to review, though. |
Member
|
I'll certainly take a look, but I believe @szakarias is the primary owner of Dartdoc. |
srawlins
approved these changes
Mar 8, 2026
srawlins
left a comment
Member
There was a problem hiding this comment.
This looks good to me. The parser work is a little dicey, but I don't know of a way around it (I think maybe that's just par-for-the-course for parser work 😅 ).
Contributor
Author
|
Thanks for the review and the approval, @srawlins! Completely agree on the parser work, it was a bit of a puzzle to find a localized way to handle it without over-engineering the core resolver. Standing by for whenever @szakarias has a moment for the final look! |
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.
Fixes #4207
Description
This PR fixes an issue where Dartdoc ignores the custom text provided in a Markdown reference-style link (
[text][target]) and instead aggressively overwrites it with the target's element name.With this fix, writing
[Platform.current][Platform.nativePlatform]will correctly link toPlatform.nativePlatformwhile displayingPlatform.currentas the link text.Implementation Details
Instead of heavily refactoring Dartdoc's core link resolver (
_makeLinkNode/getMatchingLinkElement), which handles complex edge cases like callable hints, shadowing, and inherited documentation, this fix introduces a localized, safe AST interception viapackage:markdown._LinkSyntaxWithPreservedReferenceTextwhich extendsmd.LinkSyntax.close()method.linkResolverhas overwritten the text to match the target label, it safely swaps themd.Textchild back to the user's intendedreferenceText._parseFullReferenceLabelto safely extract the target label while accounting for escaped characters and ignoring collapsed links ([text][]).This approach guarantees that standard Markdown links remain unaffected while accurately restoring the text for Dartdoc-resolved elements.
Testing
Added comprehensive tests in
test/reference_style_links_test.dart:[text][target]correctly falls back to Dartdoc link resolution.text) is successfully preserved in the generated HTML and the fallback target label is not displayed.Checklist
dart test).