Auto merge of #46247 - GuillaumeGomez:md-warnings, r=QuietMisdreqvus
Md warnings Fixes #45365. r? @QuietMisdreavus
This commit is contained in:
commit
ab79caa828
4 changed files with 64 additions and 23 deletions
|
@ -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() {
|
||||||
|
|
|
@ -2521,7 +2521,7 @@ pub struct Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Span {
|
impl Span {
|
||||||
fn empty() -> Span {
|
pub fn empty() -> Span {
|
||||||
Span {
|
Span {
|
||||||
filename: "".to_string(),
|
filename: "".to_string(),
|
||||||
loline: 0, locol: 0,
|
loline: 0, locol: 0,
|
||||||
|
|
|
@ -421,9 +421,19 @@ impl ToJson for IndexItemFunctionType {
|
||||||
thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default());
|
thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default());
|
||||||
thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
|
thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
|
||||||
RefCell::new(Vec::new()));
|
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()));
|
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",
|
||||||
|
@ -699,7 +709,10 @@ fn print_message(msg: &str, intro_msg: &mut bool, span: &Span, text: &str) {
|
||||||
println!("{}", msg);
|
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 {
|
match *diff {
|
||||||
html_diff::Difference::NodeType { ref elem, ref opposite_elem } => {
|
html_diff::Difference::NodeType { ref elem, ref opposite_elem } => {
|
||||||
print_message(&format!(" {} Types differ: expected: `{}`, found: `{}`",
|
print_message(&format!(" {} Types differ: expected: `{}`, found: `{}`",
|
||||||
|
@ -1853,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 {
|
||||||
|
|
|
@ -19,10 +19,15 @@ use rustc::session::search_paths::SearchPaths;
|
||||||
use rustc::session::config::Externs;
|
use rustc::session::config::Externs;
|
||||||
use syntax::codemap::DUMMY_SP;
|
use syntax::codemap::DUMMY_SP;
|
||||||
|
|
||||||
|
use clean::Span;
|
||||||
|
|
||||||
use externalfiles::{ExternalHtml, LoadStringError, load_string};
|
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::escape::Escape;
|
||||||
|
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;
|
||||||
|
@ -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,
|
pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
||||||
external_html: &ExternalHtml, include_toc: bool,
|
external_html: &ExternalHtml, include_toc: bool,
|
||||||
render_type: RenderType) -> isize {
|
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);
|
let input_p = Path::new(input);
|
||||||
output.push(input_p.file_stem().unwrap());
|
output.push(input_p.file_stem().unwrap());
|
||||||
output.set_extension("html");
|
output.set_extension("html");
|
||||||
|
@ -89,12 +98,36 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
||||||
|
|
||||||
reset_ids(false);
|
reset_ids(false);
|
||||||
|
|
||||||
let rendered = if include_toc {
|
let (hoedown_output, pulldown_output) = if include_toc {
|
||||||
format!("{}", MarkdownWithToc(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!("{}", MarkdownWithToc(text, ty)))
|
||||||
} else {
|
} 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!(
|
let err = write!(
|
||||||
&mut out,
|
&mut out,
|
||||||
r#"<!DOCTYPE html>
|
r#"<!DOCTYPE html>
|
||||||
|
@ -126,16 +159,16 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
||||||
css = css,
|
css = css,
|
||||||
in_header = external_html.in_header,
|
in_header = external_html.in_header,
|
||||||
before_content = external_html.before_content,
|
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,
|
after_content = external_html.after_content,
|
||||||
);
|
);
|
||||||
|
|
||||||
match err {
|
match err {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("rustdoc: cannot write to `{}`: {}", output.display(), e);
|
eprintln!("rustdoc: cannot write to `{}`: {}", output.display(), e);
|
||||||
6
|
6
|
||||||
}
|
}
|
||||||
Ok(_) => 0
|
Ok(_) => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue