-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom link titles authored with []() syntax for doc links are silently ignored #271
Custom link titles authored with []() syntax for doc links are silently ignored #271
Comments
Note: this seems related to #177. |
Please also support this in "## Topics" because often a "big topic page" might be linking to "these are the few very specific functions you should look at" and without curation those might look very out of place. For example: ## Security
...
## Topics
- ``SecuritySettings/tls`` only shows up as:
today which looks very weird, so I'd like to spell it as |
I want to discuss some implementation detail and the potential fix I tried here. The problem is we'll use But for "doc" schema links we'll always use nil for the "overridingTitle" and "overridingTitleInlineContent" (See line 133 below) The simple fix is just using the same logic for doc schema links let linkTitleInlineContent = link.children.reduce(into: [], { result, child in result.append(contentsOf: visit(child))}) as! [RenderInlineContent]
let plainTextLinkTitle = linkTitleInlineContent.plainText
return [RenderInlineContent.reference(identifier: .init(resolved.absoluteString), isActive: true, overridingTitle: overridingTitle, overridingTitleInlineContent: overridingTitleInlineContent)] But this will cause some tests to fail and maybe break some original expected behavior. So we could improve this by adding some checks here: (Set nil if the title is matched) let linkTitleInlineContent = link.children.reduce(into: [], { result, child in result.append(contentsOf: visit(child))}) as! [RenderInlineContent]
let plainTextLinkTitle = linkTitleInlineContent.plainText
let overridingTitle = plainTextLinkTitle == destination ? nil : plainTextLinkTitle
let overridingTitleInlineContent = // Alike logic
return [RenderInlineContent.reference(identifier: .init(resolved.absoluteString), isActive: true, overridingTitle: overridingTitle, overridingTitleInlineContent: overridingTitleInlineContent)] However, after doing so, we will still have one test case fail: And it was because we did some rewrite to link's destination when trying to resolve the link while leaving its other children unchanged. Original link
The actual link we can get in
Since we saw they did not match, we'll set How can we get to know such link actually should also set overrdingTitle to nil? 🤔 A simple solution is to store the original destination in See more info here #376 |
Can you provide more details about how the current behavior is impacted from an end user perspective? Or is the change in behavior not user facing? It would be useful to see what the render JSON would look like for a specific link before and after your change.
From a render JSON perspective, it seems like we should only set an overridingTitle when the Markdown content has a title override, e.g., using |
When we consume the link, we can't get its original presentation (
So if we use Source:
|
Two possible fixes for me:
Update: Or use a tricky way to differentiate it (eg. if link.range is link.firstChild.range +1) But we've lost the range info since we altered the destination on Link when visiting link. Add a PR to persevere such information swiftlang/swift-markdown#82
|
This still needs #376 to land before it's fully fixed; i'll handle merging it. |
Custom link titles for doc links are silently ignored.
If I write a doc link with a title like:
the rendered output is
We should use the user-provided title, per the original Markdown spec.
Checklist
main
branch of this package.Steps to Reproduce
Author a
doc
link to a symbol or article using a custom title, as described above. Build documentation and notice that in the rendered documentation, the custom title isn't used for the link title.Swift-DocC Version Information
Swift-DocC version:
5.6
Swift Compiler version: N/A
Radar: rdar://79992417
The text was updated successfully, but these errors were encountered: