Skip to content

Allow modifying the text in broken_link_callback #466

Closed

Description

@jyn514

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.

Activity

  1. marcusklaas commented on Aug 21, 2020

    @marcusklaas
    Collaborator

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

  2. marcusklaas commented on Aug 22, 2020

    @marcusklaas
    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?

  3. jyn514 commented on Aug 22, 2020

    @jyn514
    ContributorAuthor

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

  4. marcusklaas commented on Aug 22, 2020

    @marcusklaas
    Collaborator

    Ok, I understand. Thanks.

  5. self-assigned this
    on Aug 22, 2020
  6. marcusklaas commented on Aug 23, 2020

    @marcusklaas
    Collaborator

    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.

  7. jyn514 commented on Aug 23, 2020

    @jyn514
    ContributorAuthor

    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 😆

  8. jyn514 commented on Aug 23, 2020

    @jyn514
    ContributorAuthor

    Thanks for the help!

  9. jyn514 commented on Aug 29, 2020

    @jyn514
    ContributorAuthor

    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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions