1
Fork 0

Display rustdoc pulldown switch warnings everytime

This commit is contained in:
Guillaume Gomez 2017-10-16 21:41:10 +02:00
parent ba4e8d7db3
commit 11b2b08ba9

View file

@ -1826,37 +1826,32 @@ fn render_markdown(w: &mut fmt::Formatter,
prefix: &str, prefix: &str,
scx: &SharedContext) scx: &SharedContext)
-> fmt::Result { -> fmt::Result {
// We only emit warnings if the user has opted-in to Pulldown rendering. // Save the state of USED_ID_MAP so it only gets updated once even
let output = if render_type == RenderType::Pulldown { // though we're rendering twice.
// Save the state of USED_ID_MAP so it only gets updated once even let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
// though we're rendering twice. let hoedown_output = format!("{}", Markdown(md_text, RenderType::Hoedown));
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone()); USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
let hoedown_output = format!("{}", Markdown(md_text, RenderType::Hoedown)); let pulldown_output = format!("{}", Markdown(md_text, RenderType::Pulldown));
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map); let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
let pulldown_output = format!("{}", Markdown(md_text, RenderType::Pulldown)); differences.retain(|s| {
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output); match *s {
differences.retain(|s| { html_diff::Difference::NodeText { ref elem_text,
match *s { ref opposite_elem_text,
html_diff::Difference::NodeText { ref elem_text, .. }
ref opposite_elem_text, if elem_text.split_whitespace().eq(opposite_elem_text.split_whitespace()) => {
.. } false
if elem_text.split_whitespace().eq(opposite_elem_text.split_whitespace()) => {
false
}
_ => true,
} }
}); _ => true,
if !differences.is_empty() {
scx.markdown_warnings.borrow_mut().push((span, md_text.to_owned(), differences));
} }
});
pulldown_output if !differences.is_empty() {
} else { scx.markdown_warnings.borrow_mut().push((span, md_text.to_owned(), differences));
format!("{}", Markdown(md_text, RenderType::Hoedown)) }
};
write!(w, "<div class='docblock'>{}{}</div>", prefix, output) write!(w, "<div class='docblock'>{}{}</div>",
prefix,
if render_type == RenderType::Pulldown { pulldown_output } else { hoedown_output })
} }
fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLink, fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLink,