Skip to content

Commit 8a0aab1

Browse files
committed
Semi-conditionally insert the CSS.
Only on all pages in crates with #[doc(enable_math)], not on all pages in all crates.
1 parent 2088184 commit 8a0aab1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustdoc/html/layout.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ r##"<!DOCTYPE html>
5353
<title>{title}</title>
5454
5555
<link rel="stylesheet" type="text/css" href="{root_path}main.css">
56-
<link rel="stylesheet" type="text/css" href="{root_path}katex/katex.min.css">
56+
{katex_css}
5757
5858
{favicon}
5959
{in_header}
@@ -163,13 +163,22 @@ r##"<!DOCTYPE html>
163163
} else {
164164
format!(r#"<script src="{}playpen.js"></script>"#, page.root_path)
165165
},
166+
katex_css = if layout.enable_math {
167+
// this is inserted even for pages for which there is no
168+
// actual mathematics (unlike the JS), but this CSS is quite
169+
// small, and it's harder to insert this conditionally, since
170+
// that would require rendering the whole thing into memory
171+
// and then printing this, and only then print the
172+
// markdown.
173+
format!(r#"<link rel="stylesheet" type="text/css" href="{}katex/katex.min.css">"#,
174+
page.root_path)
175+
} else {
176+
"".to_string()
177+
},
166178
));
167179

168180
// This must be done after everything is rendered, so that
169181
// `math_seen` captures all possible $$'s on this page.
170-
//
171-
// We conditionally insert only the JS, since it's 5x larger than
172-
// the CSS.
173182
if layout.enable_math && markdown::math_seen.get().map_or(false, |x| *x) {
174183
try!(write!(dst, "<script src=\"{}katex/katex.min.js\"></script>", page.root_path));
175184
}

0 commit comments

Comments
 (0)