Skip to content
Closed
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
30 changes: 30 additions & 0 deletions crates/bin/docs_rs_web/src/handlers/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,36 @@ mod test {
})
}

#[test]
fn permalink_retains_rustdoc_fragment() {
async_wrapper(|env| async move {
env.fake_release()
.await
.name("testing")
.version("0.1.0")
.rustdoc_file("testing/index.html")
.create()
.await?;

let dom = kuchikiki::parse_html().one(
env.web_app()
.await
.get("/testing/latest/testing/index.html")
.await?
.text()
.await?,
);

let permalink = dom.select_first("#permalink").expect("permalink link");
assert_eq!(
permalink.attributes.borrow().get("data-fragment"),
Some("retain")
);

Ok(())
})
}

#[test]
fn test_repository_link_in_topbar_dropdown_github() {
async_wrapper(|env| async move {
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/docs_rs_web/templates/rustdoc/topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

{%- if metadata.req_version.to_string() == "latest" -%}
<li class="pure-menu-item">
<a href="{% if permalink_path is defined %}{{permalink_path|safe}}{% endif %}" class="pure-menu-link description" id="permalink" title="Get a link to this specific version">
<a href="{% if permalink_path is defined %}{{permalink_path|safe}}{% endif %}" class="pure-menu-link description" id="permalink" data-fragment="retain" title="Get a link to this specific version">
{{- crate::icons::IconLink.render_solid(false, false, "") }} Permalink
</a>
</li>
Expand Down
10 changes: 10 additions & 0 deletions gui-tests/permalink-fragment.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// The permalink link must retain the fragment from the current rustdoc page.
go-to: |DOC_PATH| + "/sysinfo/latest/sysinfo/index.html#section"
wait-for: "#permalink"

@GuillaumeGomez GuillaumeGomez Oct 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wait-for: "#permalink"
assert: "#permalink"

View changes since the review

assert-document-property: ({"URL": "#section"}, ENDS_WITH)

// The fragment is added on mouseover because browsers do not send it to the server.
move-cursor-to: "#permalink"
assert: "#permalink"
click: "#permalink"
assert-document-property: ({"URL": "#section"}, ENDS_WITH)
Loading