Skip to content

Commit 0bbb5ac

Browse files
committed
Avoid being specific to mathjax.
1 parent 4a1b2e8 commit 0bbb5ac

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/librustdoc/html/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct Layout {
2121
pub external_html: ExternalHtml,
2222
pub krate: String,
2323
pub playground_url: String,
24-
pub use_mathjax: bool,
24+
pub enable_math: bool,
2525
}
2626

2727
pub struct Page<'a> {
@@ -165,7 +165,7 @@ r##"<!DOCTYPE html>
165165

166166
// this must be done after everything is rendered, so that
167167
// `math_seen` captures all possible $$'s on this page.
168-
if layout.use_mathjax && markdown::math_seen.get().map_or(false, |x| *x) {
168+
if layout.enable_math && markdown::math_seen.get().map_or(false, |x| *x) {
169169
try!(dst.write_str("\
170170
<script async src=\"https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML\"></script>"));
171171
}

src/librustdoc/html/markdown.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ struct MyOpaque {
108108
dfltblk: extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
109109
*const hoedown_buffer, *mut libc::c_void),
110110
toc_builder: Option<TocBuilder>,
111-
math_enabled: bool,
112111
math_seen: bool,
113112
}
114113

@@ -167,9 +166,8 @@ fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
167166
fn hoedown_extensions() -> libc::c_uint {
168167
let mut extensions = HOEDOWN_EXTENSIONS;
169168

170-
match use_mathjax.get().as_ref() {
171-
Some(use_math) if **use_math => { extensions |= HOEDOWN_EXT_MATH; }
172-
_ => {}
169+
if enable_math.get().map_or(false, |x| *x) {
170+
extensions |= HOEDOWN_EXT_MATH;
173171
}
174172

175173
extensions
@@ -179,7 +177,7 @@ local_data_key!(used_header_map: RefCell<HashMap<String, uint>>)
179177
local_data_key!(test_idx: Cell<uint>)
180178
// None == render an example, but there's no crate name
181179
local_data_key!(pub playground_krate: Option<String>)
182-
local_data_key!(pub use_mathjax: bool)
180+
local_data_key!(pub enable_math: bool)
183181
local_data_key!(pub math_seen: bool)
184182

185183
pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
@@ -305,9 +303,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
305303

306304
opaque.math_seen = true;
307305

308-
let (open, close) = if !opaque.math_enabled {
309-
("$$", "$$")
310-
} else if display_mode == 1 {
306+
let (open, close) = if display_mode == 1 {
311307
("\\[", "\\]")
312308
} else {
313309
("\\(", "\\)")
@@ -332,7 +328,6 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
332328
let mut opaque = MyOpaque {
333329
dfltblk: (*renderer).blockcode.unwrap(),
334330
toc_builder: if print_toc {Some(TocBuilder::new())} else {None},
335-
math_enabled: use_mathjax.get().map_or(false, |x| *x),
336331
math_seen: false,
337332
};
338333
(*(*renderer).opaque).opaque = &mut opaque as *mut _ as *mut libc::c_void;

src/librustdoc/html/render.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
247247
external_html: external_html.clone(),
248248
krate: krate.name.clone(),
249249
playground_url: "".to_string(),
250-
use_mathjax: false,
250+
enable_math: false,
251251
},
252252
include_sources: true,
253253
render_redirect_pages: false,
254254
};
255255

256-
markdown::use_mathjax.replace(None);
256+
markdown::enable_math.replace(None);
257257

258258
try!(mkdir(&cx.dst));
259259

@@ -290,9 +290,9 @@ pub fn run(mut krate: clean::Crate, external_html: &ExternalHtml, dst: Path) ->
290290
cx.include_sources = false;
291291
}
292292
clean::Word(ref x)
293-
if "enable_mathjax" == x.as_slice() => {
294-
cx.layout.use_mathjax = true;
295-
markdown::use_mathjax.replace(Some(true));
293+
if "enable_math" == x.as_slice() => {
294+
cx.layout.enable_math = true;
295+
markdown::enable_math.replace(Some(true));
296296
}
297297
_ => {}
298298
}

0 commit comments

Comments
 (0)