Skip to content

Commit

Permalink
Rollup merge of rust-lang#87270 - GuillaumeGomez:item-summary-table, …
Browse files Browse the repository at this point in the history
…r=notriddle

Don't display <table> in item summary

Fixes rust-lang#87231.

r? `@notriddle`
  • Loading branch information
Dylan-DPC authored Jul 21, 2021
2 parents f4236cc + d6dc840 commit a08e0bf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn opts() -> Options {

/// A subset of [`opts()`] used for rendering summaries.
pub(crate) fn summary_opts() -> Options {
Options::ENABLE_STRIKETHROUGH | Options::ENABLE_SMART_PUNCTUATION
Options::ENABLE_STRIKETHROUGH | Options::ENABLE_SMART_PUNCTUATION | Options::ENABLE_TABLES
}

/// When `to_string` is called, this struct will emit the HTML corresponding to
Expand Down Expand Up @@ -522,6 +522,10 @@ fn check_if_allowed_tag(t: &Tag<'_>) -> bool {
)
}

fn is_forbidden_tag(t: &Tag<'_>) -> bool {
matches!(t, Tag::CodeBlock(_) | Tag::Table(_) | Tag::TableHead | Tag::TableRow | Tag::TableCell)
}

impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
type Item = Event<'a>;

Expand All @@ -535,14 +539,17 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
if let Some(event) = self.inner.next() {
let mut is_start = true;
let is_allowed_tag = match event {
Event::Start(Tag::CodeBlock(_)) | Event::End(Tag::CodeBlock(_)) => {
return None;
}
Event::Start(ref c) => {
if is_forbidden_tag(c) {
return None;
}
self.depth += 1;
check_if_allowed_tag(c)
}
Event::End(ref c) => {
if is_forbidden_tag(c) {
return None;
}
self.depth -= 1;
is_start = false;
check_if_allowed_tag(c)
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc-gui/item-summary-table.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This test ensures that <table> elements aren't display in items summary.
goto: file://|DOC_PATH|/lib2/summary_table/index.html
// We check that we picked the right item first.
assert-text: (".item-table .item-left", "Foo")
// Then we check that its summary is empty.
assert-text: (".item-table .item-right", "")
7 changes: 7 additions & 0 deletions src/test/rustdoc-gui/src/lib2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ pub mod long_trait {
pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem: DerefMut<Target = u32>
+ From<u128> + Send + Sync + AsRef<str> + 'static {}
}

pub mod summary_table {
/// | header 1 | header 2 |
/// | -------- | -------- |
/// | content | content |
pub struct Foo;
}

0 comments on commit a08e0bf

Please sign in to comment.