@@ -441,6 +441,42 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for LinkReplacer<'a, I> {
441
441
}
442
442
}
443
443
444
+ /// Wrap HTML tables into `<div>` to prevent having the doc blocks width being too big.
445
+ struct TableWrapper < ' a , I : Iterator < Item = Event < ' a > > > {
446
+ inner : I ,
447
+ stored_events : VecDeque < Event < ' a > > ,
448
+ }
449
+
450
+ impl < ' a , I : Iterator < Item = Event < ' a > > > TableWrapper < ' a , I > {
451
+ fn new ( iter : I ) -> Self {
452
+ Self { inner : iter, stored_events : VecDeque :: new ( ) }
453
+ }
454
+ }
455
+
456
+ impl < ' a , I : Iterator < Item = Event < ' a > > > Iterator for TableWrapper < ' a , I > {
457
+ type Item = Event < ' a > ;
458
+
459
+ fn next ( & mut self ) -> Option < Self :: Item > {
460
+ if let Some ( first) = self . stored_events . pop_front ( ) {
461
+ return Some ( first) ;
462
+ }
463
+
464
+ let event = self . inner . next ( ) ?;
465
+
466
+ Some ( match event {
467
+ Event :: Start ( Tag :: Table ( t) ) => {
468
+ self . stored_events . push_back ( Event :: Start ( Tag :: Table ( t) ) ) ;
469
+ Event :: Html ( CowStr :: Borrowed ( "<div>" ) )
470
+ }
471
+ Event :: End ( Tag :: Table ( t) ) => {
472
+ self . stored_events . push_back ( Event :: Html ( CowStr :: Borrowed ( "</div>" ) ) ) ;
473
+ Event :: End ( Tag :: Table ( t) )
474
+ }
475
+ e => e,
476
+ } )
477
+ }
478
+ }
479
+
444
480
type SpannedEvent < ' a > = ( Event < ' a > , Range < usize > ) ;
445
481
446
482
/// Make headings links with anchor IDs and build up TOC.
@@ -983,6 +1019,7 @@ impl Markdown<'_> {
983
1019
let p = HeadingLinks :: new ( p, None , & mut ids) ;
984
1020
let p = Footnotes :: new ( p) ;
985
1021
let p = LinkReplacer :: new ( p. map ( |( ev, _) | ev) , links) ;
1022
+ let p = TableWrapper :: new ( p) ;
986
1023
let p = CodeBlocks :: new ( p, codes, edition, playground) ;
987
1024
html:: push_html ( & mut s, p) ;
988
1025
@@ -1003,7 +1040,8 @@ impl MarkdownWithToc<'_> {
1003
1040
{
1004
1041
let p = HeadingLinks :: new ( p, Some ( & mut toc) , & mut ids) ;
1005
1042
let p = Footnotes :: new ( p) ;
1006
- let p = CodeBlocks :: new ( p. map ( |( ev, _) | ev) , codes, edition, playground) ;
1043
+ let p = TableWrapper :: new ( p. map ( |( ev, _) | ev) ) ;
1044
+ let p = CodeBlocks :: new ( p, codes, edition, playground) ;
1007
1045
html:: push_html ( & mut s, p) ;
1008
1046
}
1009
1047
@@ -1031,7 +1069,8 @@ impl MarkdownHtml<'_> {
1031
1069
1032
1070
let p = HeadingLinks :: new ( p, None , & mut ids) ;
1033
1071
let p = Footnotes :: new ( p) ;
1034
- let p = CodeBlocks :: new ( p. map ( |( ev, _) | ev) , codes, edition, playground) ;
1072
+ let p = TableWrapper :: new ( p. map ( |( ev, _) | ev) ) ;
1073
+ let p = CodeBlocks :: new ( p, codes, edition, playground) ;
1035
1074
html:: push_html ( & mut s, p) ;
1036
1075
1037
1076
s
0 commit comments