diff options
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 43 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/html/static/css/rustdoc.css | 5 |
3 files changed, 48 insertions, 3 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index aa3723eddfc..bb2bc5008e3 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -441,6 +441,42 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> { } } +/// Wrap HTML tables into `<div>` to prevent having the doc blocks width being too big. +struct TableWrapper<'a, I: Iterator<Item = Event<'a>>> { + inner: I, + stored_events: VecDeque<Event<'a>>, +} + +impl<'a, I: Iterator<Item = Event<'a>>> TableWrapper<'a, I> { + fn new(iter: I) -> Self { + Self { inner: iter, stored_events: VecDeque::new() } + } +} + +impl<'a, I: Iterator<Item = Event<'a>>> Iterator for TableWrapper<'a, I> { + type Item = Event<'a>; + + fn next(&mut self) -> Option<Self::Item> { + if let Some(first) = self.stored_events.pop_front() { + return Some(first); + } + + let event = self.inner.next()?; + + Some(match event { + Event::Start(Tag::Table(t)) => { + self.stored_events.push_back(Event::Start(Tag::Table(t))); + Event::Html(CowStr::Borrowed("<div>")) + } + Event::End(Tag::Table(t)) => { + self.stored_events.push_back(Event::Html(CowStr::Borrowed("</div>"))); + Event::End(Tag::Table(t)) + } + e => e, + }) + } +} + type SpannedEvent<'a> = (Event<'a>, Range<usize>); /// Make headings links with anchor IDs and build up TOC. @@ -983,6 +1019,7 @@ impl Markdown<'_> { let p = HeadingLinks::new(p, None, &mut ids); let p = Footnotes::new(p); let p = LinkReplacer::new(p.map(|(ev, _)| ev), links); + let p = TableWrapper::new(p); let p = CodeBlocks::new(p, codes, edition, playground); html::push_html(&mut s, p); @@ -1003,7 +1040,8 @@ impl MarkdownWithToc<'_> { { let p = HeadingLinks::new(p, Some(&mut toc), &mut ids); let p = Footnotes::new(p); - let p = CodeBlocks::new(p.map(|(ev, _)| ev), codes, edition, playground); + let p = TableWrapper::new(p.map(|(ev, _)| ev)); + let p = CodeBlocks::new(p, codes, edition, playground); html::push_html(&mut s, p); } @@ -1031,7 +1069,8 @@ impl MarkdownHtml<'_> { let p = HeadingLinks::new(p, None, &mut ids); let p = Footnotes::new(p); - let p = CodeBlocks::new(p.map(|(ev, _)| ev), codes, edition, playground); + let p = TableWrapper::new(p.map(|(ev, _)| ev)); + let p = CodeBlocks::new(p, codes, edition, playground); html::push_html(&mut s, p); s diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 39ef641a3ac..6da60533b1c 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -273,7 +273,8 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl write!( w, "<h2 id=\"{id}\" class=\"section-header\">\ - <a href=\"#{id}\">{name}</a></h2>\n{}", + <a href=\"#{id}\">{name}</a>\ + </h2>\n{}", ITEM_TABLE_OPEN, id = cx.derive_id(short.to_owned()), name = name diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 23ca6eeaf3b..2d4bfc62af6 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -522,6 +522,11 @@ nav.sub { position: relative; } +.docblock > * { + max-width: 100%; + overflow-x: auto; +} + .content .out-of-band { flex-grow: 0; text-align: right; |
