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

Feature request: inject syntax highlighting for TOML into crate docs #2577

Open
abonander opened this issue Aug 2, 2024 · 5 comments
Open

Comments

@abonander
Copy link

I just ran into this while working on launchbadge/sqlx#3383

It'd be really nice to have syntax highlighting for TOML in crate docs, because I'm including a lot of it.

I found #1047 which was closed already and the upstream issue rust-lang/rust#43165, but the general disposition for the latter seems to be summed up by this comment: rust-lang/rust#43165 (comment)

It doesn't seem likely that rustdoc itself will gain support for this anytime soon.

The reason I'm opening this issue is because this comment points out that TOML syntax highlighting is already available on the details pages for crates. It doesn't seem like it would take much to inject it into the HTML for the docs themselves.

@syphar
Copy link
Member

syphar commented Aug 7, 2024

btw, thanks for your library, I'm currently in the process of migrating docs.rs to it :)

The reason I'm opening this issue is because rust-lang/rust#43165 (comment) points out that TOML syntax highlighting is already available on the details pages for crates. It doesn't seem like it would take much to inject it into the HTML for the docs themselves.

We have some pages where we actually do highlighting, there are:

in both cases we have the actual source and render a highlighted HTML version using comrak.

Now back to your topic. Docs.rs just runs a (relatively) normal cargo doc command and stores the final HTML.
So to add highlighting to these documentation pages we would have to parse the old HTML, find code blocks, and rewrite these with a highlighted version, and all taking into account the styling outside of the code block.

So while we actually could rewrite HTML (we are already rewriting small parts, for example to add the top / bottom bar), the actual correct place would be rustdoc, since then users using docs.rs would see the same docs as users running the doc build locally. Also I believe a well readable doc page without broken styling, across all nightly rustdoc versions would be really hard.

@syphar
Copy link
Member

syphar commented Aug 7, 2024

of course we could also use frontend techniques to do something similar, but with similar issues keeping it stable across versions

@GuillaumeGomez
Copy link
Member

I think we should just add highlightjs at this point and run it by default on all pages.

@syphar
Copy link
Member

syphar commented Aug 13, 2024

I think we should just add highlightjs at this point and run it by default on all pages.

you mean that rustdoc should do this ? or docs.rs?

I don't have much experience with highlight.js, I only know that for the pages we render ourselves (like our source) it was replaced by server side highlighting.

Wouldn't this conflict with the cases where rustdoc is already highlighting, like its own source pages?

@GuillaumeGomez
Copy link
Member

I meant docs.rs. And I can write the JS so highlightjs only takes a look at not highlighted code examples.

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

3 participants