Skip to content

Commit eb84f42

Browse files
fix markdown file differences
1 parent 8b1fc4b commit eb84f42

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

src/doc/not_found.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ Some things that might be helpful to you though:
1313

1414
# Search
1515

16-
* <form action="https://duckduckgo.com/">
16+
<form action="https://duckduckgo.com/">
1717
<input type="text" id="site-search" name="q" size="80"></input>
18-
<input type="submit" value="Search DuckDuckGo">
19-
</form>
20-
* Rust doc search: <span id="core-search"></span>
18+
<input type="submit" value="Search DuckDuckGo"></form>
19+
20+
Rust doc search: <span id="core-search"></span>
2121

2222
# Reference
2323

24-
* [The Rust official site](https://www.rust-lang.org)
25-
* [The Rust reference](https://doc.rust-lang.org/reference/index.html)
24+
* [The Rust official site](https://www.rust-lang.org)
25+
* [The Rust reference](https://doc.rust-lang.org/reference/index.html)
2626

2727
# Docs
2828

29-
* [The standard library](https://doc.rust-lang.org/std/)
29+
[The standard library](https://doc.rust-lang.org/std/)
3030

3131
<script>
3232
function get_url_fragments() {

src/librustdoc/html/render.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,16 @@ thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
424424
thread_local!(pub static USED_ID_MAP: RefCell<FxHashMap<String, usize>> =
425425
RefCell::new(init_ids()));
426426

427+
pub fn render_text<F: FnMut(RenderType) -> String>(mut render: F) -> (String, String) {
428+
// Save the state of USED_ID_MAP so it only gets updated once even
429+
// though we're rendering twice.
430+
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
431+
let hoedown_output = render(RenderType::Hoedown);
432+
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
433+
let pulldown_output = render(RenderType::Pulldown);
434+
(hoedown_output, pulldown_output)
435+
}
436+
427437
fn init_ids() -> FxHashMap<String, usize> {
428438
[
429439
"main",
@@ -1856,12 +1866,7 @@ fn render_markdown(w: &mut fmt::Formatter,
18561866
prefix: &str,
18571867
scx: &SharedContext)
18581868
-> fmt::Result {
1859-
// Save the state of USED_ID_MAP so it only gets updated once even
1860-
// though we're rendering twice.
1861-
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
1862-
let hoedown_output = format!("{}", Markdown(md_text, RenderType::Hoedown));
1863-
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
1864-
let pulldown_output = format!("{}", Markdown(md_text, RenderType::Pulldown));
1869+
let (hoedown_output, pulldown_output) = render_text(|ty| format!("{}", Markdown(md_text, ty)));
18651870
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
18661871
differences.retain(|s| {
18671872
match *s {

src/librustdoc/markdown.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use externalfiles::{ExternalHtml, LoadStringError, load_string};
2525

2626
use html_diff;
2727

28-
use html::render::reset_ids;
28+
use html::render::{render_text, reset_ids};
2929
use html::escape::Escape;
30-
use html::render::{USED_ID_MAP, render_difference};
30+
use html::render::render_difference;
3131
use html::markdown;
3232
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, old_find_testable_code};
3333
use html::markdown::RenderType;
@@ -101,19 +101,11 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
101101
let (hoedown_output, pulldown_output) = if include_toc {
102102
// Save the state of USED_ID_MAP so it only gets updated once even
103103
// though we're rendering twice.
104-
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
105-
let hoedown_output = format!("{}", MarkdownWithToc(text, RenderType::Hoedown));
106-
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
107-
let pulldown_output = format!("{}", MarkdownWithToc(text, RenderType::Pulldown));
108-
(hoedown_output, pulldown_output)
104+
render_text(|ty| format!("{}", MarkdownWithToc(text, ty)))
109105
} else {
110106
// Save the state of USED_ID_MAP so it only gets updated once even
111107
// though we're rendering twice.
112-
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
113-
let hoedown_output = format!("{}", Markdown(text, RenderType::Hoedown));
114-
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
115-
let pulldown_output = format!("{}", Markdown(text, RenderType::Pulldown));
116-
(hoedown_output, pulldown_output)
108+
render_text(|ty| format!("{}", Markdown(text, ty)))
117109
};
118110

119111
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);

0 commit comments

Comments
 (0)