Skip to content

Commit a08e0bf

Browse files
authored
Rollup merge of rust-lang#87270 - GuillaumeGomez:item-summary-table, r=notriddle
Don't display <table> in item summary Fixes rust-lang#87231. r? `@notriddle`
2 parents f4236cc + d6dc840 commit a08e0bf

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/librustdoc/html/markdown.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(crate) fn opts() -> Options {
5757

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

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

525+
fn is_forbidden_tag(t: &Tag<'_>) -> bool {
526+
matches!(t, Tag::CodeBlock(_) | Tag::Table(_) | Tag::TableHead | Tag::TableRow | Tag::TableCell)
527+
}
528+
525529
impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
526530
type Item = Event<'a>;
527531

@@ -535,14 +539,17 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
535539
if let Some(event) = self.inner.next() {
536540
let mut is_start = true;
537541
let is_allowed_tag = match event {
538-
Event::Start(Tag::CodeBlock(_)) | Event::End(Tag::CodeBlock(_)) => {
539-
return None;
540-
}
541542
Event::Start(ref c) => {
543+
if is_forbidden_tag(c) {
544+
return None;
545+
}
542546
self.depth += 1;
543547
check_if_allowed_tag(c)
544548
}
545549
Event::End(ref c) => {
550+
if is_forbidden_tag(c) {
551+
return None;
552+
}
546553
self.depth -= 1;
547554
is_start = false;
548555
check_if_allowed_tag(c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This test ensures that <table> elements aren't display in items summary.
2+
goto: file://|DOC_PATH|/lib2/summary_table/index.html
3+
// We check that we picked the right item first.
4+
assert-text: (".item-table .item-left", "Foo")
5+
// Then we check that its summary is empty.
6+
assert-text: (".item-table .item-right", "")

src/test/rustdoc-gui/src/lib2/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ pub mod long_trait {
5757
pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem: DerefMut<Target = u32>
5858
+ From<u128> + Send + Sync + AsRef<str> + 'static {}
5959
}
60+
61+
pub mod summary_table {
62+
/// | header 1 | header 2 |
63+
/// | -------- | -------- |
64+
/// | content | content |
65+
pub struct Foo;
66+
}

0 commit comments

Comments
 (0)