Skip to content

Commit 2bfe2d6

Browse files
committed
HTML table caption processing (margin support)
1 parent 8c2ca7e commit 2bfe2d6

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/format/html/format-html-bootstrap.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
636665
const 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
});

src/resources/formats/html/bootstrap/_bootstrap-rules.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ aside,
655655
font-size: 0.825rem;
656656
}
657657

658+
.panel-caption.margin-caption {
659+
text-align: inherit;
660+
}
661+
662+
658663
.column-margin.column-container p {
659664
margin-bottom: 0;
660665
}

0 commit comments

Comments
 (0)