You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow modifying the text in broken_link_callback #466
Use case: rustdoc wants to turn [type@char] into <a href="https://doc.rust-lang.org/std/primitive.char.html>char</a>. But the broken_link_callback API doesn't allow for changing the text of a link, only the title that shows up when you hover.
I'm currently working on the redesign, and wondered why you couldn't just set the title itself here. Wouldn't [char][type@char] produce the result you're after with the current style of callbacks?
After some more exploration, I've found that this would be pretty tough to implement in the parser. The main complication is that link contents can be an arbitrary tree of inline nodes, including images. So we cannot just pass along a mutable reference to a text buffer for the callback to edit.
One solution would be to specialize for the case where the content is just text, but that seems like too much complexity to push onto other users just to support this use-case.
Luckily, I believe there is another solution which doesn't require changes in the parser. You can create a custom iterator over the events that filters link events that were inserted by the callback (you can recognize these by their ...Unknown link types), push your replacement link content event after it and then skip all the other events until you get a link close event. This is similar to the solution to this issue.
Please ket me know whether this would solve your problem. I can flesh out the implementation a bit more if that would help.
Activity
marcusklaas commentedon Aug 21, 2020
The callback functionality is due for an overhaul. We'll take this use-case into consideration for the new design!
marcusklaas commentedon Aug 22, 2020
I'm currently working on the redesign, and wondered why you couldn't just set the title itself here. Wouldn't
[char][type@char]produce the result you're after with the current style of callbacks?jyn514 commentedon Aug 22, 2020
Right, but that requires action from the user, rustdoc can't do it itself.
marcusklaas commentedon Aug 22, 2020
Ok, I understand. Thanks.
marcusklaas commentedon Aug 23, 2020
After some more exploration, I've found that this would be pretty tough to implement in the parser. The main complication is that link contents can be an arbitrary tree of inline nodes, including images. So we cannot just pass along a mutable reference to a text buffer for the callback to edit.
One solution would be to specialize for the case where the content is just text, but that seems like too much complexity to push onto other users just to support this use-case.
Luckily, I believe there is another solution which doesn't require changes in the parser. You can create a custom iterator over the events that filters link events that were inserted by the callback (you can recognize these by their
...Unknownlink types), push your replacement link content event after it and then skip all the other events until you get a link close event. This is similar to the solution to this issue.Please ket me know whether this would solve your problem. I can flesh out the implementation a bit more if that would help.
jyn514 commentedon Aug 23, 2020
Interesting, that seems like it might work. Actually a lot of the issues marked as 'S-blocked' on pulldown would probably be solved by a similar strategy.
I'll close this since now I just have to figure out how to implement it in rustdoc 😆
jyn514 commentedon Aug 23, 2020
Thanks for the help!
jyn514 commentedon Aug 29, 2020
Figured it out :) rust-lang/rust#76078 Thanks again!