@@ -360,7 +360,14 @@ function bootstrapHtmlPostprocessor(
360360 format . metadata [ kAppendixStyle ] !== false &&
361361 format . metadata [ kAppendixStyle ] !== "none"
362362 ) {
363- await processDocumentAppendix ( input , inputTraits , format , flags , doc , offset ) ;
363+ await processDocumentAppendix (
364+ input ,
365+ inputTraits ,
366+ format ,
367+ flags ,
368+ doc ,
369+ offset ,
370+ ) ;
364371 }
365372
366373 // no resource refs
@@ -632,6 +639,28 @@ const processFigureMarginCaption = (
632639 }
633640} ;
634641
642+ const processTableMarginCaption = (
643+ captionContainer : Element ,
644+ doc : Document ,
645+ ) => {
646+ // Find a caption
647+ const caption = captionContainer . querySelector ( "caption" ) ;
648+ if ( caption ) {
649+ const marginCapEl = doc . createElement ( "DIV" ) ;
650+ marginCapEl . classList . add ( "quarto-table-caption" ) ;
651+ marginCapEl . classList . add ( "margin-caption" ) ;
652+ marginCapEl . innerHTML = caption . innerHTML ;
653+
654+ captionContainer . parentElement ?. insertBefore (
655+ marginCapEl ,
656+ captionContainer . nextElementSibling ,
657+ ) ;
658+
659+ caption . remove ( ) ;
660+ removeCaptionClass ( captionContainer ) ;
661+ }
662+ } ;
663+
635664// Process any captions that appear in margins
636665const processMarginCaptions = ( doc : Document ) => {
637666 // Forward caption class from parents to the child fig caps
@@ -649,6 +678,23 @@ const processMarginCaptions = (doc: Document) => {
649678 } else {
650679 processFigureMarginCaption ( captionContainer , doc ) ;
651680 }
681+ } else {
682+ // Deal with table margin captions
683+ if ( figureEl . classList . contains ( "tbl-parent" ) ) {
684+ // This is table panel, so only grab the main caption
685+ const capDivEl = figureEl . querySelector ( "div.panel-caption" ) ;
686+ if ( capDivEl ) {
687+ capDivEl . classList . add ( "margin-caption" ) ;
688+ capDivEl . remove ( ) ;
689+ figureEl . appendChild ( capDivEl ) ;
690+ }
691+ } else {
692+ // This is just a table, grab that caption
693+ const table = figureEl . querySelector ( "table" ) ;
694+ if ( table ) {
695+ processTableMarginCaption ( table , doc ) ;
696+ }
697+ }
652698 }
653699 removeCaptionClass ( figureEl ) ;
654700 } ) ;
0 commit comments