Skip to content

Commit aa3d64e

Browse files
Rollup merge of #87270 - GuillaumeGomez:item-summary-table, r=notriddle
Don't display <table> in item summary Fixes #87231. r? `@notriddle`
2 parents 7c89e38 + de25b1c commit aa3d64e

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
@@ -66,3 +66,10 @@ pub mod long_table {
6666
/// I wanna sqdkfnqds f dsqf qds f dsqf dsq f dsq f qds f qds f qds f dsqq f dsf sqdf dsq fds f dsq f dq f ds fq sd fqds f dsq f sqd fsq df sd fdsqfqsd fdsq f dsq f dsqfd s dfq
6767
pub struct Foo;
6868
}
69+
70+
pub mod summary_table {
71+
/// | header 1 | header 2 |
72+
/// | -------- | -------- |
73+
/// | content | content |
74+
pub struct Foo;
75+
}

0 commit comments

Comments
 (0)