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

@@ -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",
@@ -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 {