fix markdown file differences

This commit is contained in:
Guillaume Gomez 2017-11-24 23:12:35 +01:00
parent 8b1fc4b842
commit eb84f4243f
3 changed files with 22 additions and 25 deletions

View File

@ -13,20 +13,20 @@ Some things that might be helpful to you though:
# Search # Search
* <form action="https://duckduckgo.com/"> <form action="https://duckduckgo.com/">
<input type="text" id="site-search" name="q" size="80"></input> <input type="text" id="site-search" name="q" size="80"></input>
<input type="submit" value="Search DuckDuckGo"> <input type="submit" value="Search DuckDuckGo"></form>
</form>
* Rust doc search: <span id="core-search"></span> Rust doc search: <span id="core-search"></span>
# Reference # Reference
* [The Rust official site](https://www.rust-lang.org) * [The Rust official site](https://www.rust-lang.org)
* [The Rust reference](https://doc.rust-lang.org/reference/index.html) * [The Rust reference](https://doc.rust-lang.org/reference/index.html)
# Docs # Docs
* [The standard library](https://doc.rust-lang.org/std/) [The standard library](https://doc.rust-lang.org/std/)
<script> <script>
function get_url_fragments() { function get_url_fragments() {

View File

@ -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>> = thread_local!(pub static USED_ID_MAP: RefCell<FxHashMap<String, usize>> =
RefCell::new(init_ids())); 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> { fn init_ids() -> FxHashMap<String, usize> {
[ [
"main", "main",
@ -1856,12 +1866,7 @@ fn render_markdown(w: &mut fmt::Formatter,
prefix: &str, prefix: &str,
scx: &SharedContext) scx: &SharedContext)
-> fmt::Result { -> fmt::Result {
// Save the state of USED_ID_MAP so it only gets updated once even let (hoedown_output, pulldown_output) = render_text(|ty| format!("{}", Markdown(md_text, ty)));
// 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 mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output); let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
differences.retain(|s| { differences.retain(|s| {
match *s { match *s {

View File

@ -25,9 +25,9 @@ use externalfiles::{ExternalHtml, LoadStringError, load_string};
use html_diff; use html_diff;
use html::render::reset_ids; use html::render::{render_text, reset_ids};
use html::escape::Escape; use html::escape::Escape;
use html::render::{USED_ID_MAP, render_difference}; use html::render::render_difference;
use html::markdown; use html::markdown;
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, old_find_testable_code}; use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, old_find_testable_code};
use html::markdown::RenderType; use html::markdown::RenderType;
@ -101,19 +101,11 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
let (hoedown_output, pulldown_output) = if include_toc { let (hoedown_output, pulldown_output) = if include_toc {
// Save the state of USED_ID_MAP so it only gets updated once even // Save the state of USED_ID_MAP so it only gets updated once even
// though we're rendering twice. // though we're rendering twice.
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone()); render_text(|ty| format!("{}", MarkdownWithToc(text, ty)))
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)
} else { } else {
// Save the state of USED_ID_MAP so it only gets updated once even // Save the state of USED_ID_MAP so it only gets updated once even
// though we're rendering twice. // though we're rendering twice.
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone()); render_text(|ty| format!("{}", Markdown(text, ty)))
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)
}; };
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output); let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);