Skip to content

Commit ab79caa

Browse files
committed
Auto merge of #46247 - GuillaumeGomez:md-warnings, r=QuietMisdreqvus
Md warnings Fixes #45365. r? @QuietMisdreavus
2 parents 88fc3bc + eb84f42 commit ab79caa

File tree

4 files changed

+64
-23
lines changed

4 files changed

+64
-23
lines changed

src/doc/not_found.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ Some things that might be helpful to you though:
1313

1414
# Search
1515

16-
* <form action="https://duckduckgo.com/">
16+
<form action="https://duckduckgo.com/">
1717
<input type="text" id="site-search" name="q" size="80"></input>
18-
<input type="submit" value="Search DuckDuckGo">
19-
</form>
20-
* Rust doc search: <span id="core-search"></span>
18+
<input type="submit" value="Search DuckDuckGo"></form>
19+
20+
Rust doc search: <span id="core-search"></span>
2121

2222
# Reference
2323

24-
* [The Rust official site](https://www.rust-lang.org)
25-
* [The Rust reference](https://doc.rust-lang.org/reference/index.html)
24+
* [The Rust official site](https://www.rust-lang.org)
25+
* [The Rust reference](https://doc.rust-lang.org/reference/index.html)
2626

2727
# Docs
2828

29-
* [The standard library](https://doc.rust-lang.org/std/)
29+
[The standard library](https://doc.rust-lang.org/std/)
3030

3131
<script>
3232
function get_url_fragments() {

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,7 @@ pub struct Span {
25212521
}
25222522

25232523
impl Span {
2524-
fn empty() -> Span {
2524+
pub fn empty() -> Span {
25252525
Span {
25262526
filename: "".to_string(),
25272527
loline: 0, locol: 0,

src/librustdoc/html/render.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,19 @@ impl ToJson for IndexItemFunctionType {
421421
thread_local!(static CACHE_KEY: RefCell<Arc<Cache>> = Default::default());
422422
thread_local!(pub static CURRENT_LOCATION_KEY: RefCell<Vec<String>> =
423423
RefCell::new(Vec::new()));
424-
thread_local!(static USED_ID_MAP: RefCell<FxHashMap<String, usize>> =
424+
thread_local!(pub static USED_ID_MAP: RefCell<FxHashMap<String, usize>> =
425425
RefCell::new(init_ids()));
426426

427+
pub fn render_text<F: FnMut(RenderType) -> String>(mut render: F) -> (String, String) {
428+
// Save the state of USED_ID_MAP so it only gets updated once even
429+
// though we're rendering twice.
430+
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
431+
let hoedown_output = render(RenderType::Hoedown);
432+
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
433+
let pulldown_output = render(RenderType::Pulldown);
434+
(hoedown_output, pulldown_output)
435+
}
436+
427437
fn init_ids() -> FxHashMap<String, usize> {
428438
[
429439
"main",
@@ -699,7 +709,10 @@ fn print_message(msg: &str, intro_msg: &mut bool, span: &Span, text: &str) {
699709
println!("{}", msg);
700710
}
701711

702-
fn render_difference(diff: &html_diff::Difference, intro_msg: &mut bool, span: &Span, text: &str) {
712+
pub fn render_difference(diff: &html_diff::Difference,
713+
intro_msg: &mut bool,
714+
span: &Span,
715+
text: &str) {
703716
match *diff {
704717
html_diff::Difference::NodeType { ref elem, ref opposite_elem } => {
705718
print_message(&format!(" {} Types differ: expected: `{}`, found: `{}`",
@@ -1853,12 +1866,7 @@ fn render_markdown(w: &mut fmt::Formatter,
18531866
prefix: &str,
18541867
scx: &SharedContext)
18551868
-> fmt::Result {
1856-
// Save the state of USED_ID_MAP so it only gets updated once even
1857-
// though we're rendering twice.
1858-
let orig_used_id_map = USED_ID_MAP.with(|map| map.borrow().clone());
1859-
let hoedown_output = format!("{}", Markdown(md_text, RenderType::Hoedown));
1860-
USED_ID_MAP.with(|map| *map.borrow_mut() = orig_used_id_map);
1861-
let pulldown_output = format!("{}", Markdown(md_text, RenderType::Pulldown));
1869+
let (hoedown_output, pulldown_output) = render_text(|ty| format!("{}", Markdown(md_text, ty)));
18621870
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
18631871
differences.retain(|s| {
18641872
match *s {

src/librustdoc/markdown.rs

+40-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ use rustc::session::search_paths::SearchPaths;
1919
use rustc::session::config::Externs;
2020
use syntax::codemap::DUMMY_SP;
2121

22+
use clean::Span;
23+
2224
use externalfiles::{ExternalHtml, LoadStringError, load_string};
2325

24-
use html::render::reset_ids;
26+
use html_diff;
27+
28+
use html::render::{render_text, reset_ids};
2529
use html::escape::Escape;
30+
use html::render::render_difference;
2631
use html::markdown;
2732
use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, old_find_testable_code};
2833
use html::markdown::RenderType;
@@ -52,6 +57,10 @@ fn extract_leading_metadata<'a>(s: &'a str) -> (Vec<&'a str>, &'a str) {
5257
pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
5358
external_html: &ExternalHtml, include_toc: bool,
5459
render_type: RenderType) -> isize {
60+
// Span used for markdown hoedown/pulldown differences.
61+
let mut span = Span::empty();
62+
span.filename = input.to_owned();
63+
5564
let input_p = Path::new(input);
5665
output.push(input_p.file_stem().unwrap());
5766
output.set_extension("html");
@@ -89,12 +98,36 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
8998

9099
reset_ids(false);
91100

92-
let rendered = if include_toc {
93-
format!("{}", MarkdownWithToc(text, render_type))
101+
let (hoedown_output, pulldown_output) = if include_toc {
102+
// Save the state of USED_ID_MAP so it only gets updated once even
103+
// though we're rendering twice.
104+
render_text(|ty| format!("{}", MarkdownWithToc(text, ty)))
94105
} else {
95-
format!("{}", Markdown(text, render_type))
106+
// Save the state of USED_ID_MAP so it only gets updated once even
107+
// though we're rendering twice.
108+
render_text(|ty| format!("{}", Markdown(text, ty)))
96109
};
97110

111+
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
112+
differences.retain(|s| {
113+
match *s {
114+
html_diff::Difference::NodeText { ref elem_text,
115+
ref opposite_elem_text,
116+
.. }
117+
if elem_text.split_whitespace().eq(opposite_elem_text.split_whitespace()) => {
118+
false
119+
}
120+
_ => true,
121+
}
122+
});
123+
124+
if !differences.is_empty() {
125+
let mut intro_msg = false;
126+
for diff in differences {
127+
render_difference(&diff, &mut intro_msg, &span, text);
128+
}
129+
}
130+
98131
let err = write!(
99132
&mut out,
100133
r#"<!DOCTYPE html>
@@ -126,16 +159,16 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
126159
css = css,
127160
in_header = external_html.in_header,
128161
before_content = external_html.before_content,
129-
text = rendered,
162+
text = if render_type == RenderType::Pulldown { pulldown_output } else { hoedown_output },
130163
after_content = external_html.after_content,
131-
);
164+
);
132165

133166
match err {
134167
Err(e) => {
135168
eprintln!("rustdoc: cannot write to `{}`: {}", output.display(), e);
136169
6
137170
}
138-
Ok(_) => 0
171+
Ok(_) => 0,
139172
}
140173
}
141174

0 commit comments

Comments
 (0)