diff options
| author | bors <bors@rust-lang.org> | 2017-12-08 14:10:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-08 14:10:07 +0000 |
| commit | ab79caa828cf955e658faa4386cf9e8e0a8c3e28 (patch) | |
| tree | 385b47ae2d91a30e95475e94a7face13ccc85d80 | |
| parent | 88fc3bc271cbc5c74777f855f6d213b74bf0eb9d (diff) | |
| parent | eb84f4243fa7e18f97ee39f6c0b751f4c329a4ee (diff) | |
| download | rust-ab79caa828cf955e658faa4386cf9e8e0a8c3e28.tar.gz rust-ab79caa828cf955e658faa4386cf9e8e0a8c3e28.zip | |
Auto merge of #46247 - GuillaumeGomez:md-warnings, r=QuietMisdreqvus
Md warnings Fixes #45365. r? @QuietMisdreavus
| -rw-r--r-- | src/doc/not_found.md | 14 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 24 | ||||
| -rw-r--r-- | src/librustdoc/markdown.rs | 47 |
4 files changed, 64 insertions, 23 deletions
diff --git a/src/doc/not_found.md b/src/doc/not_found.md index ebe7c59313f..f404aa046c1 100644 --- a/src/doc/not_found.md +++ b/src/doc/not_found.md @@ -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() { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index be7bd3d5510..fbff6e83fb9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2521,7 +2521,7 @@ pub struct Span { } impl Span { - fn empty() -> Span { + pub fn empty() -> Span { Span { filename: "".to_string(), loline: 0, locol: 0, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d42faebd39e..d423e53ca18 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -421,9 +421,19 @@ impl ToJson for IndexItemFunctionType { thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default()); thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> = RefCell::new(Vec::new())); -thread_local!(static USED_ID_MAP: RefCell<FxHashMap<String, usize>> = +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", @@ -699,7 +709,10 @@ fn print_message(msg: &str, intro_msg: &mut bool, span: &Span, text: &str) { println!("{}", msg); } -fn render_difference(diff: &html_diff::Difference, intro_msg: &mut bool, span: &Span, text: &str) { +pub fn render_difference(diff: &html_diff::Difference, + intro_msg: &mut bool, + span: &Span, + text: &str) { match *diff { html_diff::Difference::NodeType { ref elem, ref opposite_elem } => { print_message(&format!(" {} Types differ: expected: `{}`, found: `{}`", @@ -1853,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 { diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index fe6bd985bb6..9b94e9918f8 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -19,10 +19,15 @@ use rustc::session::search_paths::SearchPaths; use rustc::session::config::Externs; use syntax::codemap::DUMMY_SP; +use clean::Span; + use externalfiles::{ExternalHtml, LoadStringError, load_string}; -use html::render::reset_ids; +use html_diff; + +use html::render::{render_text, reset_ids}; use html::escape::Escape; +use html::render::render_difference; use html::markdown; use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, old_find_testable_code}; use html::markdown::RenderType; @@ -52,6 +57,10 @@ fn extract_leading_metadata<'a>(s: &'a str) -> (Vec<&'a str>, &'a str) { pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, external_html: &ExternalHtml, include_toc: bool, render_type: RenderType) -> isize { + // Span used for markdown hoedown/pulldown differences. + let mut span = Span::empty(); + span.filename = input.to_owned(); + let input_p = Path::new(input); output.push(input_p.file_stem().unwrap()); output.set_extension("html"); @@ -89,12 +98,36 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, reset_ids(false); - let rendered = if include_toc { - format!("{}", MarkdownWithToc(text, render_type)) + 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. + render_text(|ty| format!("{}", MarkdownWithToc(text, ty))) } else { - format!("{}", Markdown(text, render_type)) + // Save the state of USED_ID_MAP so it only gets updated once even + // though we're rendering twice. + render_text(|ty| format!("{}", Markdown(text, ty))) }; + let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output); + differences.retain(|s| { + match *s { + html_diff::Difference::NodeText { ref elem_text, + ref opposite_elem_text, + .. } + if elem_text.split_whitespace().eq(opposite_elem_text.split_whitespace()) => { + false + } + _ => true, + } + }); + + if !differences.is_empty() { + let mut intro_msg = false; + for diff in differences { + render_difference(&diff, &mut intro_msg, &span, text); + } + } + let err = write!( &mut out, r#"<!DOCTYPE html> @@ -126,16 +159,16 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, css = css, in_header = external_html.in_header, before_content = external_html.before_content, - text = rendered, + text = if render_type == RenderType::Pulldown { pulldown_output } else { hoedown_output }, after_content = external_html.after_content, - ); + ); match err { Err(e) => { eprintln!("rustdoc: cannot write to `{}`: {}", output.display(), e); 6 } - Ok(_) => 0 + Ok(_) => 0, } } |
