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

Rustdoc generates invalid HTML header #113067

Closed
DaniPopes opened this issue Jun 26, 2023 · 2 comments · Fixed by #113094
Closed

Rustdoc generates invalid HTML header #113067

DaniPopes opened this issue Jun 26, 2023 · 2 comments · Fixed by #113094
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@DaniPopes
Copy link
Contributor

The generated page HTML contains a <div> tag in the header, which is not valid as per the HTML spec (which only allows "Metadata content"). This has been the case since #106915, which moved this div from the body to the header.

I believe browsers will open the body if an invalid tag is encountered in the header (which you can see in inspect elements, where every item in between </div> </head> are inside of <body>), or something like that.

This causes at least one bug: the #![doc(html_favicon_url = "...")] attribute, which expands into a <link rel="icon" href="...">, is not displayed on Chrome and Chromium-based browsers.
You can see this in the time crate on docs.rs:

  • Chrome
    chrome
  • Firefox
    firefox

Generated HTML:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    
    <!-- ... -->
    
    <div id="rustdoc-vars"
    
    <!-- ... -->

    <link rel="icon" href="https://avatars0.githubusercontent.com/u/55999857">

    <!-- ... -->
</head>

vs inspect element:

<html lang="en" data-theme="light">

<head>
    <meta charset="utf-8">
    
    <!-- ... -->
</head>
<div style="display: none; position: fixed; width: 100%; height: 100%; z-index: 1;"></div>

<body class="rustdoc-page">
    <div id="rustdoc-vars"

    <!-- ... -->

    <link rel="icon" href="https://avatars0.githubusercontent.com/u/55999857">

    <!-- ... -->
</body>

Manually moving the link tag to the header correctly displays the favicon:

image
2. image

@DaniPopes DaniPopes added the C-bug Category: This is a bug. label Jun 26, 2023
@DaniPopes
Copy link
Contributor Author

@rustbot label A-rustdoc-ui T-rustdoc

@rustbot rustbot added A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jun 26, 2023
@GuillaumeGomez
Copy link
Member

Thanks for the detailed report! Fixing it tomorrow.

TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jun 27, 2023
…-in-head, r=notriddle

Fix invalid HTML DIV tag used in HEAD

Fixes rust-lang#113067.

The issue also nicely explains the whole problem.

r? `@notriddle`
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Jun 27, 2023
…-in-head, r=notriddle

Fix invalid HTML DIV tag used in HEAD

Fixes rust-lang#113067.

The issue also nicely explains the whole problem.

r? ``@notriddle``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 28, 2023
…-in-head, r=notriddle,fmease

Fix invalid HTML DIV tag used in HEAD

Fixes rust-lang#113067.

The issue also nicely explains the whole problem.

r? `@notriddle`
@bors bors closed this as completed in a70842c Jun 28, 2023
RalfJung pushed a commit to RalfJung/miri that referenced this issue Jun 29, 2023
… r=notriddle,fmease

Fix invalid HTML DIV tag used in HEAD

Fixes rust-lang/rust#113067.

The issue also nicely explains the whole problem.

r? ``@notriddle``
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
… r=notriddle,fmease

Fix invalid HTML DIV tag used in HEAD

Fixes rust-lang/rust#113067.

The issue also nicely explains the whole problem.

r? ``@notriddle``
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
… r=notriddle,fmease

Fix invalid HTML DIV tag used in HEAD

Fixes rust-lang/rust#113067.

The issue also nicely explains the whole problem.

r? ``@notriddle``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants