Skip to content
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

Allow modifying the text in broken_link_callback #466

Closed
jyn514 opened this issue Aug 19, 2020 · 8 comments
Closed

Allow modifying the text in broken_link_callback #466

jyn514 opened this issue Aug 19, 2020 · 8 comments
Assignees

Comments

@jyn514
Copy link
Contributor

jyn514 commented Aug 19, 2020

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.

See also rust-lang/rust#65354, especially my comments around rust-lang/rust#65354 (comment).

I'd try to implement this myself, but my last try went ... poorly.

@marcusklaas
Copy link
Collaborator

The callback functionality is due for an overhaul. We'll take this use-case into consideration for the new design!

@marcusklaas
Copy link
Collaborator

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
Copy link
Contributor Author

jyn514 commented Aug 22, 2020

Right, but that requires action from the user, rustdoc can't do it itself.

@marcusklaas
Copy link
Collaborator

Ok, I understand. Thanks.

@marcusklaas marcusklaas self-assigned this Aug 22, 2020
@marcusklaas
Copy link
Collaborator

marcusklaas commented 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 ...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.

@jyn514
Copy link
Contributor Author

jyn514 commented 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
Copy link
Contributor Author

jyn514 commented Aug 23, 2020

Thanks for the help!

@jyn514
Copy link
Contributor Author

jyn514 commented Aug 29, 2020

Figured it out :) rust-lang/rust#76078 Thanks again!

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

No branches or pull requests

2 participants