Skip to content

Fix --extend-css option #110235

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

Merged
merged 3 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,8 @@ impl Step for RustdocGUI {
cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
} else if entry.file_name() == "scrape_examples" {
cargo.arg("-Zrustdoc-scrape-examples");
} else if entry.file_name() == "extend_css" {
cargo.env("RUSTDOCFLAGS", &format!("--extend-css extra.css"));
}
builder.run(&mut cargo);
}
Expand Down
5 changes: 1 addition & 4 deletions src/doc/rustdoc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,7 @@ $ rustdoc src/lib.rs --extend-css extra.css
```

With this flag, the contents of the files you pass are included at the bottom
of Rustdoc's `theme.css` file.

While this flag is stable, the contents of `theme.css` are not, so be careful!
Updates may break your theme extensions.
of the `theme.css` file.

## `--sysroot`: override the system root

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</noscript> {# #}
{% if layout.css_file_extension.is_some() %}
<link rel="stylesheet" {#+ #}
href="{{static_root_path|safe}}theme{{page.resource_suffix}}.css"> {# #}
href="{{page.root_path|safe}}theme{{page.resource_suffix}}.css"> {# #}
{% endif %}
{% if !layout.favicon.is_empty() %}
<link rel="icon" href="{{layout.favicon}}"> {# #}
Expand Down
5 changes: 5 additions & 0 deletions tests/rustdoc-gui/extend-css.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test to ensure that the `--extend-css` option is working as expected.
go-to: "file://" + |DOC_PATH| + "/extend_css/index.html"
show-text: true
// The text from the `.extend` element should be red.
assert-css: (".extend", {"color": "rgb(255, 0, 0)"})
2 changes: 2 additions & 0 deletions tests/rustdoc-gui/search-filter.goml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ press-key: "ArrowDown"
press-key: "ArrowDown"
press-key: "ArrowDown"
press-key: "ArrowDown"
press-key: "ArrowDown"
press-key: "Enter"
// Waiting for the search results to appear...
wait-for: "#search-tabs"
Expand All @@ -41,6 +42,7 @@ press-key: "ArrowUp"
press-key: "ArrowUp"
press-key: "ArrowUp"
press-key: "ArrowUp"
press-key: "ArrowUp"
press-key: "Enter"
// Waiting for the search results to appear...
wait-for: "#search-tabs"
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-gui/sidebar-source-code.goml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
// Only "another_folder" should be "open" in "lib2".
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
// All other trees should be collapsed.
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 8)
assert-count: ("//*[@id='source-sidebar']/details[not(text()='lib2') and not(@open)]", 9)

// We now switch to mobile mode.
set-window-size: (600, 600)
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-gui/source-code-page.goml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ assert: ".source-sidebar-expanded"

// We check that the first entry of the sidebar is collapsed
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
assert-text: ("#source-sidebar details:first-of-type > summary", "http")
assert-text: ("#source-sidebar details:first-of-type > summary", "extend_css")
// We now click on it.
click: "#source-sidebar details:first-of-type > summary"
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})
Expand Down
7 changes: 7 additions & 0 deletions tests/rustdoc-gui/src/extend_css/Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "extend_css"
version = "0.1.0"
7 changes: 7 additions & 0 deletions tests/rustdoc-gui/src/extend_css/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "extend_css"
version = "0.1.0"
edition = "2018"

[lib]
path = "lib.rs"
3 changes: 3 additions & 0 deletions tests/rustdoc-gui/src/extend_css/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.extend {
color: red !important;
}
1 change: 1 addition & 0 deletions tests/rustdoc-gui/src/extend_css/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//! <div class="extend">text in red</div>