Rollup merge of #55136 - GuillaumeGomez:short-doc, r=QuietMisdreavus
Remove short doc where it starts with a codeblock Fixes #54975.
This commit is contained in:
commit
2173681647
4 changed files with 78 additions and 35 deletions
|
@ -399,7 +399,6 @@ impl<'a, I: Iterator<Item = Event<'a>>> SummaryLine<'a, I> {
|
||||||
fn check_if_allowed_tag(t: &Tag) -> bool {
|
fn check_if_allowed_tag(t: &Tag) -> bool {
|
||||||
match *t {
|
match *t {
|
||||||
Tag::Paragraph
|
Tag::Paragraph
|
||||||
| Tag::CodeBlock(_)
|
|
||||||
| Tag::Item
|
| Tag::Item
|
||||||
| Tag::Emphasis
|
| Tag::Emphasis
|
||||||
| Tag::Strong
|
| Tag::Strong
|
||||||
|
@ -420,29 +419,36 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
|
||||||
if !self.started {
|
if !self.started {
|
||||||
self.started = true;
|
self.started = true;
|
||||||
}
|
}
|
||||||
let event = self.inner.next();
|
while let Some(event) = self.inner.next() {
|
||||||
let mut is_start = true;
|
let mut is_start = true;
|
||||||
let is_allowed_tag = match event {
|
let is_allowed_tag = match event {
|
||||||
Some(Event::Start(ref c)) => {
|
Event::Start(Tag::CodeBlock(_)) | Event::End(Tag::CodeBlock(_)) => {
|
||||||
self.depth += 1;
|
return None;
|
||||||
check_if_allowed_tag(c)
|
}
|
||||||
}
|
Event::Start(ref c) => {
|
||||||
Some(Event::End(ref c)) => {
|
self.depth += 1;
|
||||||
self.depth -= 1;
|
check_if_allowed_tag(c)
|
||||||
is_start = false;
|
}
|
||||||
check_if_allowed_tag(c)
|
Event::End(ref c) => {
|
||||||
}
|
self.depth -= 1;
|
||||||
_ => true,
|
is_start = false;
|
||||||
};
|
check_if_allowed_tag(c)
|
||||||
if is_allowed_tag == false {
|
}
|
||||||
if is_start {
|
_ => {
|
||||||
Some(Event::Start(Tag::Paragraph))
|
true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return if is_allowed_tag == false {
|
||||||
|
if is_start {
|
||||||
|
Some(Event::Start(Tag::Paragraph))
|
||||||
|
} else {
|
||||||
|
Some(Event::End(Tag::Paragraph))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Some(Event::End(Tag::Paragraph))
|
Some(event)
|
||||||
}
|
};
|
||||||
} else {
|
|
||||||
event
|
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2584,24 +2584,39 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||||
_ => "",
|
_ => "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let stab = myitem.stability_class();
|
||||||
|
let add = if stab.is_some() {
|
||||||
|
" "
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
|
||||||
let doc_value = myitem.doc_value().unwrap_or("");
|
let doc_value = myitem.doc_value().unwrap_or("");
|
||||||
write!(w, "
|
write!(w, "\
|
||||||
<tr class='{stab} module-item'>
|
<tr class='{stab}{add}module-item'>\
|
||||||
<td><a class=\"{class}\" href=\"{href}\"
|
<td><a class=\"{class}\" href=\"{href}\" \
|
||||||
title='{title_type} {title}'>{name}</a>{unsafety_flag}</td>
|
title='{title}'>{name}</a>{unsafety_flag}</td>\
|
||||||
<td class='docblock-short'>
|
<td class='docblock-short'>{stab_docs}{docs}\
|
||||||
{stab_docs} {docs}
|
</td>\
|
||||||
</td>
|
|
||||||
</tr>",
|
</tr>",
|
||||||
name = *myitem.name.as_ref().unwrap(),
|
name = *myitem.name.as_ref().unwrap(),
|
||||||
stab_docs = stab_docs,
|
stab_docs = stab_docs,
|
||||||
docs = MarkdownSummaryLine(doc_value, &myitem.links()),
|
docs = MarkdownSummaryLine(doc_value, &myitem.links()),
|
||||||
class = myitem.type_(),
|
class = myitem.type_(),
|
||||||
stab = myitem.stability_class().unwrap_or(String::new()),
|
add = add,
|
||||||
|
stab = stab.unwrap_or_else(|| String::new()),
|
||||||
unsafety_flag = unsafety_flag,
|
unsafety_flag = unsafety_flag,
|
||||||
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
|
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
|
||||||
title_type = myitem.type_(),
|
title = [full_path(cx, myitem), myitem.type_().to_string()]
|
||||||
title = full_path(cx, myitem))?;
|
.iter()
|
||||||
|
.filter_map(|s| if !s.is_empty() {
|
||||||
|
Some(s.as_str())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" "),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ pub struct Portable;
|
||||||
// @has doc_cfg/unix_only/index.html \
|
// @has doc_cfg/unix_only/index.html \
|
||||||
// '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
|
// '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
|
||||||
// 'This is supported on Unix only.'
|
// 'This is supported on Unix only.'
|
||||||
// @matches - '//*[@class=" module-item"]//*[@class="stab portability"]' '\AUnix\Z'
|
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AUnix\Z'
|
||||||
// @matches - '//*[@class=" module-item"]//*[@class="stab portability"]' '\AUnix and ARM\Z'
|
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AUnix and ARM\Z'
|
||||||
// @count - '//*[@class="stab portability"]' 3
|
// @count - '//*[@class="stab portability"]' 3
|
||||||
#[doc(cfg(unix))]
|
#[doc(cfg(unix))]
|
||||||
pub mod unix_only {
|
pub mod unix_only {
|
||||||
|
@ -52,7 +52,7 @@ pub mod unix_only {
|
||||||
|
|
||||||
// the portability header is different on the module view versus the full view
|
// the portability header is different on the module view versus the full view
|
||||||
// @has doc_cfg/index.html
|
// @has doc_cfg/index.html
|
||||||
// @matches - '//*[@class=" module-item"]//*[@class="stab portability"]' '\Aavx\Z'
|
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\Aavx\Z'
|
||||||
|
|
||||||
// @has doc_cfg/fn.uses_target_feature.html
|
// @has doc_cfg/fn.uses_target_feature.html
|
||||||
// @has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
|
// @has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
|
||||||
|
|
22
src/test/rustdoc/short-docblock-codeblock.rs
Normal file
22
src/test/rustdoc/short-docblock-codeblock.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has foo/index.html '//*[@class="module-item"]//td[@class="docblock-short"]' ""
|
||||||
|
// @!has foo/index.html '//*[@id="module-item"]//td[@class="docblock-short"]' "Some text."
|
||||||
|
// @!has foo/index.html '//*[@id="module-item"]//td[@class="docblock-short"]' "let x = 12;"
|
||||||
|
|
||||||
|
/// ```
|
||||||
|
/// let x = 12;
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Some text.
|
||||||
|
pub fn foo() {}
|
Loading…
Add table
Add a link
Reference in a new issue