Skip to content

Commit

Permalink
fix markdown file differences
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 7, 2017
1 parent 8b1fc4b commit eb84f42
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
14 changes: 7 additions & 7 deletions src/doc/not_found.md
Expand Up @@ -13,20 +13,20 @@ Some things that might be helpful to you though:

# Search

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

Rust doc search: <span id="core-search"></span>

# Reference

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

# Docs

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

<script>
function get_url_fragments() {
Expand Down
17 changes: 11 additions & 6 deletions src/librustdoc/html/render.rs
Expand Up @@ -424,6 +424,16 @@ thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
thread_local!(pub static USED_ID_MAP: RefCell<FxHashMap<String, usize>> =
RefCell::new(init_ids()));

pub fn render_text<F: FnMut(RenderType) -> String>(mut render: F) -> (String, String) {
// Save the state of USED_ID_MAP so it only gets updated once even
// though we're rendering twice.
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
let hoedown_output = render(RenderType::Hoedown);
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
let pulldown_output = render(RenderType::Pulldown);
(hoedown_output, pulldown_output)
}

fn init_ids() -> FxHashMap<String, usize> {
[
"main",
Expand Down Expand Up @@ -1856,12 +1866,7 @@ fn render_markdown(w: &mut fmt::Formatter,
prefix: &str,
scx: &SharedContext)
-> fmt::Result {
// Save the state of USED_ID_MAP so it only gets updated once even
// though we're rendering twice.
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
let hoedown_output = format!("{}", Markdown(md_text, RenderType::Hoedown));
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
let pulldown_output = format!("{}", Markdown(md_text, RenderType::Pulldown));
let (hoedown_output, pulldown_output) = render_text(|ty| format!("{}", Markdown(md_text, ty)));
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
differences.retain(|s| {
match *s {
Expand Down
16 changes: 4 additions & 12 deletions src/librustdoc/markdown.rs
Expand Up @@ -25,9 +25,9 @@ use externalfiles::{ExternalHtml, LoadStringError, load_string};

use html_diff;

use html::render::reset_ids;
use html::render::{render_text, reset_ids};
use html::escape::Escape;
use html::render::{USED_ID_MAP, render_difference};
use html::render::render_difference;
use html::markdown;
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, old_find_testable_code};
use html::markdown::RenderType;
Expand Down Expand Up @@ -101,19 +101,11 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
let (hoedown_output, pulldown_output) = if include_toc {
// Save the state of USED_ID_MAP so it only gets updated once even
// though we're rendering twice.
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
let hoedown_output = format!("{}", MarkdownWithToc(text, RenderType::Hoedown));
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
let pulldown_output = format!("{}", MarkdownWithToc(text, RenderType::Pulldown));
(hoedown_output, pulldown_output)
render_text(|ty| format!("{}", MarkdownWithToc(text, ty)))
} else {
// Save the state of USED_ID_MAP so it only gets updated once even
// though we're rendering twice.
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
let hoedown_output = format!("{}", Markdown(text, RenderType::Hoedown));
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
let pulldown_output = format!("{}", Markdown(text, RenderType::Pulldown));
(hoedown_output, pulldown_output)
render_text(|ty| format!("{}", Markdown(text, ty)))
};

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

0 comments on commit eb84f42

Please sign in to comment.