Skip to content

Commit aef68ff

Browse files
committed
Fix rustdoc styles for very old docs
Previously this used the selector `link[type='text/css'][href*='normalize']` to inject the vendored HTML. Unfortunately, this selector did not exist in very old versions of rustdoc. Instead, this now adds the `vendored.css` stylesheet at the start of the `<head>` tag.
1 parent 8fecbb4 commit aef68ff

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/utils/html.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ pub(crate) fn rewrite_lol(
1919

2020
let templates = templates.templates.load();
2121
let tera_head = templates.render("rustdoc/head.html", &ctx).unwrap();
22-
let tera_vendored_css = templates.render("rustdoc/vendored.html", &ctx).unwrap();
22+
let tera_vendored = templates.render("rustdoc/vendored.html", &ctx).unwrap();
2323
let tera_body = templates.render("rustdoc/body.html", &ctx).unwrap();
2424
let tera_rustdoc_header = templates.render("rustdoc/header.html", &ctx).unwrap();
2525

2626
// Append `style.css` stylesheet after all head elements.
2727
let head_handler = |head: &mut Element| {
28+
head.prepend(&tera_vendored, ContentType::Html);
2829
head.append(&tera_head, ContentType::Html);
2930

3031
Ok(())
@@ -64,18 +65,7 @@ pub(crate) fn rewrite_lol(
6465
Ok(())
6566
};
6667

67-
// Append `vendored.css` before the first stylesheet (rustdoc's first stylesheet is `normalize.css`).
68-
let first_stylesheet_handler = |head: &mut Element| {
69-
head.before(&tera_vendored_css, ContentType::Html);
70-
71-
Ok(())
72-
};
73-
74-
let (head_selector, body_selector, first_stylesheet_selector) = (
75-
"head".parse().unwrap(),
76-
"body".parse().unwrap(),
77-
"link[type='text/css'][href*='normalize']".parse().unwrap(),
78-
);
68+
let (head_selector, body_selector) = ("head".parse().unwrap(), "body".parse().unwrap());
7969
let element_content_handlers = vec![
8070
(
8171
&head_selector,
@@ -85,10 +75,6 @@ pub(crate) fn rewrite_lol(
8575
&body_selector,
8676
ElementContentHandlers::default().element(body_handler),
8777
),
88-
(
89-
&first_stylesheet_selector,
90-
ElementContentHandlers::default().element(first_stylesheet_handler),
91-
),
9278
];
9379
let settings = Settings {
9480
element_content_handlers,

0 commit comments

Comments
 (0)