Skip to content

Rustdoc generates invalid HTML header #113067

Closed
@DaniPopes

Description

@DaniPopes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-uiArea: Rustdoc UI (generated HTML)C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions