Skip to content

Commit 74690aa

Browse files
author
JJ Allaire
committed
Merge branch 'main' of github.com:quarto-dev/quarto-cli into main
2 parents ce78954 + fc1ed92 commit 74690aa

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

‎src/format/reveal/format-reveal.ts‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -601,23 +601,16 @@ function applyStretch(doc: Document, autoStretch: boolean) {
601601
hasStretchClass(imageEl) &&
602602
imageEl.parentNode?.nodeName !== "SECTION"
603603
) {
604+
// Remove element then maybe remove its parents if empty
604605
const removeEmpty = function (el: Element) {
605606
const parentEl = el.parentElement;
606-
// Remove element then maybe remove its parents
607607
parentEl?.removeChild(el);
608608
if (parentEl?.innerText.trim() === "") removeEmpty(parentEl);
609609
};
610610

611-
// Remove image from its parent
612-
removeEmpty(imageEl);
613-
// insert at first level after the element
614-
slideEl.insertBefore(
615-
image,
616-
nodeEl.nextElementSibling,
617-
);
618-
619611
// Figure environment ? Get caption and alignment
620612
const quartoFig = slideEl.querySelector("div.quarto-figure");
613+
const caption = doc.createElement("p");
621614
if (quartoFig) {
622615
// Get alignment
623616
const align = quartoFig.className.match(
@@ -627,18 +620,28 @@ function applyStretch(doc: Document, autoStretch: boolean) {
627620
// Get Caption
628621
const figCaption = nodeEl.querySelector("figcaption");
629622
if (figCaption) {
630-
const caption = doc.createElement("p");
631623
caption.classList.add("caption");
632624
caption.innerHTML = figCaption.innerHTML;
633-
slideEl.insertBefore(
634-
caption,
635-
imageEl.nextElementSibling,
636-
);
637-
figCaption.remove();
638625
}
639-
// Remove the container
640-
removeEmpty(quartoFig);
641626
}
627+
628+
// Remove image from its parent
629+
removeEmpty(imageEl);
630+
// insert at first level after the element
631+
slideEl.insertBefore(
632+
image,
633+
nodeEl.nextElementSibling,
634+
);
635+
636+
// If there was a caption processed add it after
637+
if (caption.classList.contains("caption")) {
638+
slideEl.insertBefore(
639+
caption,
640+
imageEl.nextElementSibling,
641+
);
642+
}
643+
// Remove container if still there
644+
if (quartoFig) removeEmpty(quartoFig);
642645
}
643646
}
644647
}

0 commit comments

Comments
 (0)