Skip to content

Commit bdbbbe6

Browse files
authored
Rollup merge of rust-lang#101062 - notriddle:notriddle/text-javascript, r=GuillaumeGomez
rustdoc: remove empty extern_crates and type="text/javascript" on script Like rust-lang#101023, this removes an attribute with a default value.
2 parents aa6b750 + 52582d3 commit bdbbbe6

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/librustdoc/html/render/print_item.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
997997
// So C's HTML will have something like this:
998998
//
999999
// ```html
1000-
// <script type="text/javascript" src="/implementors/A/trait.Foo.js"
1000+
// <script src="/implementors/A/trait.Foo.js"
10011001
// data-ignore-extern-crates="A,B" async></script>
10021002
// ```
10031003
//
@@ -1023,9 +1023,11 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
10231023
.map(|cnum| cx.shared.tcx.crate_name(cnum).to_string())
10241024
.collect::<Vec<_>>()
10251025
.join(",");
1026+
let (extern_before, extern_after) =
1027+
if extern_crates.is_empty() { ("", "") } else { (" data-ignore-extern-crates=\"", "\"") };
10261028
write!(
10271029
w,
1028-
"<script type=\"text/javascript\" src=\"{src}\" data-ignore-extern-crates=\"{extern_crates}\" async></script>",
1030+
"<script src=\"{src}\"{extern_before}{extern_crates}{extern_after} async></script>",
10291031
src = js_src_path.finish(),
10301032
);
10311033
}

src/librustdoc/html/static/js/main.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ function loadCss(cssFileName) {
528528
// We don't want to include impls from this JS file, when the HTML already has them.
529529
// The current crate should always be ignored. Other crates that should also be
530530
// ignored are included in the attribute `data-ignore-extern-crates`.
531-
const ignoreExternCrates = document
532-
.querySelector("script[data-ignore-extern-crates]")
533-
.getAttribute("data-ignore-extern-crates");
531+
const script = document
532+
.querySelector("script[data-ignore-extern-crates]");
533+
const ignoreExternCrates = script ? script.getAttribute("data-ignore-extern-crates") : "";
534534
for (const lib of libs) {
535535
if (lib === window.currentCrate || ignoreExternCrates.indexOf(lib) !== -1) {
536536
continue;

0 commit comments

Comments
 (0)