Skip to content

[rustdoc] Feature Request: Allow code wrapping #127334

Closed

Description

@aramrw

Would be nice to have a setting (or just a button) that could have the code wrap, gets tiring if you are reading lots of code on your phone to scroll back and forth.

My bad if this has been requested before, I didn't see it in any issues yet

Activity

  1. syphar commented on Jul 4, 2024

    @syphar
    Member

    Hi,

    thank you for the idea.

    About which code views are you talking? can you provide example URLs?

    I'm asking because there are actually two separate ones:

    • the rustdoc code view, where this issue would have to be moved
    • the docs.rs internal code view
  2. aramrw commented on Jul 4, 2024

    @aramrw
    Author

    Hi,

    thank you for the idea.

    About which code views are you talking? can you provide example URLs?

    I'm asking because there are actually two separate ones:

    • the rustdoc code view, where this issue would have to be moved
    • the docs.rs internal code view

    Like it says Run in the top right, could also have a wrap button there maybe if possible?
    https://doc.rust-lang.org/std/rc/index.html#examples

  3. syphar commented on Jul 4, 2024

    @syphar
    Member

    Ah, that's even option 3),

    not the code views for the crate itself, but code blocks in the docs.

    I'm not sure if this is a rustdoc issue (where we don't have the "run" button yet), or an issue for the stdlib docs.

    @GuillaumeGomez ?

  4. GuillaumeGomez commented on Jul 4, 2024

    @GuillaumeGomez
    Member

    Sorry I still don't understand what's being asked. ^^'

  5. aramrw commented on Jul 4, 2024

    @aramrw
    Author

    Sorry I still don't understand what's being asked. ^^'

    Are you talking to me or...? I mean wrapping the code blocks on the rust docs website. As in not having any overflow-x..? Having the text wrap to the next line, so you don't need to scroll left and right, to read the code block

  6. GuillaumeGomez commented on Jul 4, 2024

    @GuillaumeGomez
    Member

    Oh I see. So a change in rustdoc. Moving the issue to the right repository.

  7. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 4, 2024
  8. changed the title [-]Feature Request: Allow code wrapping[/-] [+][rustdoc] Feature Request: Allow code wrapping[/+] on Jul 4, 2024
  9. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    A-rustdoc-uiArea: Rustdoc UI (generated HTML)
    T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 4, 2024
  10. GuillaumeGomez commented on Jul 4, 2024

    @GuillaumeGomez
    Member

    In case it's not clear for everyone, let me expand a bit (please correct me if I'm wrong @aramrw):

    Currently, the code examples in Rust HTML documentation are scrollable if they are too wide. The idea here would be to add a setting allowing for the code examples to instead wrap to the next line.

    Now for the implementation: we need to be careful how this new setting would interact with the line numbers on the left (if the setting is enabled).

    One thing I'm not clear about: @aramrw, would you want this setting to be applied to both code examples and source code pages or only to code examples?

    I think it's fine to add such a setting. If @rust-lang/rustdoc-frontend agrees, I'll add it.

  11. aramrw commented on Jul 4, 2024

    @aramrw
    Author

    One thing I'm not clear about: @aramrw, would you want this setting to be applied to both code examples and source code pages or only to code examples?

    If it's possible to add it for both the code examples & the source code it would be much appreciated 👍🏼

  12. 4 remaining items

  13. jsha commented on Jul 8, 2024

    @jsha
    Contributor
  14. camelid commented on Jul 8, 2024

    @camelid
    Member

    One idea: instead of having an option for this, maybe just make wrapping the default on mobile devices (i.e., screens that are sufficiently narrow by some heuristic). I'm wary of requiring too much configuration of rustdoc.

  15. GuillaumeGomez commented on Jul 8, 2024

    @GuillaumeGomez
    Member

    #88545 Looks like it was grid layout and 1000 items, maybe?

    I was looking for this discussion, thanks so much! So it was not for tables but for grids, good to know! One less problem to worry about.

    One idea: instead of having an option for this, maybe just make wrapping the default on mobile devices (i.e., screens that are sufficiently narrow by some heuristic). I'm wary of requiring too much configuration of rustdoc.

    We enter in the tricky area of personal taste. It's a case where being able to ask all rust doc users would be super useful.

  16. jsha commented on Jul 8, 2024

    @jsha
    Contributor

    I've been meaning to come here and post exactly what @camelid said. Our default position should be to not introduce new settings but try to just do the best thing. If we put it behind a setting, very few people will actually know about it and use it, but we will still bear the full burden of maintaining both versions.

    In this case, the right thing is clearly to line-wrap on all platforms (not just mobile). Horizontal scrolling is a terrible experience on desktop / wide screens too.

    This page has an example of doing line numbers with wrapping. It uses CSS counters, and seems pretty tidy.

  17. GuillaumeGomez commented on Jul 10, 2024

    @GuillaumeGomez
    Member

    It can work for code examples, but not for source code as we need them to be link. But noted for the horizontal scrolling. Will make our work simpler.

  18. GuillaumeGomez commented on Jul 17, 2024

    @GuillaumeGomez
    Member

    Another issue I didn't think of is that we use style with CSS classes across lines (so if you have a multi-line comment, it's currently only one element). It would greatly increase the size of the DOM. This feature is definitely more tricky than I initially thought...

  19. aramrw commented on Oct 9, 2024

    @aramrw
    Author

    any updates...?

  20. GuillaumeGomez commented on Feb 11, 2025

    @GuillaumeGomez
    Member

    Yep, found an acceptable middle-ground for this feature to be done in #136829. It's just the first step but adding this setting should be pretty easy/quick from there.

  21. added a commit that references this issue on Feb 12, 2025
  22. added a commit that references this issue on Feb 12, 2025
  23. GuillaumeGomez commented on Feb 13, 2025

    @GuillaumeGomez
    Member

    Opened PR to add the feature in #136991.

  24. added 2 commits that reference this issue on Feb 24, 2025
  25. added a commit that references this issue on Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-uiArea: Rustdoc UI (generated HTML)T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.T-rustdoc-frontendRelevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions