Skip to content

Commit

Permalink
Auto merge of #46247 - GuillaumeGomez:md-warnings, r=QuietMisdreqvus
Browse files Browse the repository at this point in the history
Md warnings

Fixes #45365.

r? @QuietMisdreavus
  • Loading branch information
bors committed Dec 8, 2017
2 parents 88fc3bc + eb84f42 commit ab79caa
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/doc/not_found.md
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2521,7 +2521,7 @@ pub struct Span {
}

impl Span {
fn empty() -> Span {
pub fn empty() -> Span {
Span {
filename: "".to_string(),
loline: 0, locol: 0,
Expand Down
24 changes: 16 additions & 8 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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: `{}`",
Expand Down Expand Up @@ -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 {
Expand Down
47 changes: 40 additions & 7 deletions src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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,
}
}

Expand Down

0 comments on commit ab79caa

Please sign in to comment.