Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

rustdoc_to_markdown: Strip "Copy item path to clipboard" button (#12490)

Marshall Bowers39a2cdb13fa1
diff --git a/crates/rustdoc_to_markdown/src/markdown_writer.rs b/crates/rustdoc_to_markdown/src/markdown_writer.rs
index 1aea134f123..cd530b0a4db 100644
--- a/crates/rustdoc_to_markdown/src/markdown_writer.rs
+++ b/crates/rustdoc_to_markdown/src/markdown_writer.rs
@@ -204,6 +204,13 @@ impl MarkdownWriter {
return StartTagOutcome::Skip;
}
}
+ "button" => {
+ if tag.attrs.borrow().iter().any(|attr| {
+ attr.name.local.to_string() == "id" && attr.value.to_string() == "copy-path"
+ }) {
+ return StartTagOutcome::Skip;
+ }
+ }
"div" | "span" => {
let classes_to_skip = ["nav-container", "sidebar-elems", "out-of-band"];
diff --git a/crates/rustdoc_to_markdown/src/rustdoc_to_markdown.rs b/crates/rustdoc_to_markdown/src/rustdoc_to_markdown.rs
index dd791545686..c4743c00b89 100644
--- a/crates/rustdoc_to_markdown/src/rustdoc_to_markdown.rs
+++ b/crates/rustdoc_to_markdown/src/rustdoc_to_markdown.rs
@@ -44,6 +44,27 @@ mod tests {
use super::*;
+ #[test]
+ fn test_main_heading_buttons_get_removed() {
+ let html = indoc! {r##"
+ <div class="main-heading">
+ <h1>Crate <a class="mod" href="#">serde</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1>
+ <span class="out-of-band">
+ <a class="src" href="../src/serde/lib.rs.html#1-340">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button>
+ </span>
+ </div>
+ "##};
+ let expected = indoc! {"
+ # Crate serde
+ "}
+ .trim();
+
+ assert_eq!(
+ convert_rustdoc_to_markdown(html.as_bytes()).unwrap(),
+ expected
+ )
+ }
+
#[test]
fn test_rust_code_block() {
let html = indoc! {r#"