Repository navigation
html_document: restore code padding on pandoc 3, side-by-side images, caption nesting - #128
Merged
Merged
Conversation
modify_css() removed rmarkdown's injected 'pre code { padding: 0; }'
rule with an exact match on its two-space indentation. Pandoc >= 3
strips the indentation when it embeds CSS in self-contained output, so
the match failed and the rule overrode the 10px code block padding in
bioconductor.css. Match the rule with any whitespace instead; output
with the indented form (pandoc < 3, self_contained = FALSE) still
matches.
Add unit tests for modify_css() and a golden render test for both
self-contained and non-self-contained output.
Co-Authored-By: Claude <noreply@anthropic.com>
caption_titles() let the lazy title group run to the end of the line when a table caption had no sentence break, so a one-line caption such as '<caption>(#tab:x) Title</caption>' became '<span class="caption-title">Title</caption></span><br>', which is invalid nesting. For tables, end the title before a closing </caption> on the same line (dropping a final period, as for figures). Figure captions are unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
bioconductor.css gives every <img> display: block and 280px of horizontal padding under box-sizing: border-box, to indent full-width figures into the text column. An image with an explicit smaller width (out.width = "30%", fig.show = "hold", or raw <img width="30%"> tags) therefore stacked vertically, and in captioned figures its content box collapsed to nothing: the images were invisible (#52). A single captioned figure with out.width = "50%" rendered tiny and ignored fig.align (#54). For images whose width attribute is not "100%", drop the padding and make them inline-block, and indent the containing figure div or paragraph instead (via :has()), so the percentages refer to the figure column, several images sit side by side, and fig.align centers them. The narrow-screen media query removes the container indent as it does for full-width figures. Default, fig.small and fig.wide figures all have width="100%" and are not affected. test_default_figure_options counted lines matching width="100%", which now also match the embedded CSS; count <img> tags instead. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three fixes to
BiocStyle::html_documentoutput.1. Code blocks lose their padding on pandoc 3 (#103)
Broken: in self-contained HTML (the default), code and output blocks had no vertical padding, so the code sat flush against the grey box.
Root cause:
modify_css()removes rmarkdown's injectedpre code { padding: 0; }rule with an exact match on its two-space indentation. Pandoc >= 3 strips the indentation when it embeds the CSS, so the match failed and the rule overrode BiocStyle'spre code { padding: 10px 10px 10px 0 }.Fix: match the rule with any whitespace (
pre code \{\s*padding: 0;\s*\}, perl). The indented form (pandoc < 3, orself_contained = FALSE) still matches. Bootstrap's minifiedpre code{padding:0;…}doesn't match, and neither do BiocStyle's ownpre coderules.2. Images with a reduced width are invisible or stacked (#52, #54)
Broken:
knitr::include_graphics(rep(...))or plots without.width = "30%", fig.show = "hold"and afig.capshowed only the caption, with zero-width images. Without a caption, or with raw<img width="30%">tags, the images stacked vertically. A single captioned figure without.width = "50%"rendered tiny and ignoredfig.align(#54).Root cause:
bioconductor.cssgives everyimgdisplay: blockand 130px + 150px of horizontal padding underbox-sizing: border-box, to indent full-width figures into the text column. A 30% wide image (about 200px) is smaller than its 280px padding, so its content box collapses to 0. The block display also prevents images from sitting side by side.Fix: images whose
widthattribute isn't"100%"getdisplay: inline-block; padding: 0. Their containing.figurediv or<p>gets the indent instead (through:has()), so the percentages refer to the figure column, several images sit side by side, and knitr'sfig.aligncenters them. The narrow-screen media query removes that container indent, just as it does for full-width figures. Default,fig.smallandfig.widefigures all carrywidth="100%", so these rules never match them.3.
caption_titles()produces invalid tag nestingBroken: a one-line table caption without a sentence break (e.g. a
knitr::kablecaption) became<caption>… <span class="caption-title">Title</caption></span><br>.Root cause: the lazy title group, followed by the end-of-line alternative, consumed the closing
</caption>.Fix: for tables, end the title before a closing
</caption>on the same line. The output is now<span class="caption-title">Title</span><br></caption>. A final period is dropped, as it already was for figures. Figure captions are unchanged.Verification
R 4.6.0, rmarkdown 2.31, knitr 1.51, bookdown 0.47, Chromium 143. Pandoc 3.7.0.2 and 3.10.
inst/unitTests/test_html_document.Rcoversmodify_css()(indented and unindented rules, otherpre coderules kept) andcaption_titles()(nesting, final period, inline markup, multi-line captions, figures unchanged). The regression tests fail with the oldmodify_css()/caption_titles()and pass with the new ones.test_html_golden_code_block_paddingintest_render_golden.Rchecks that the rule is gone from both self-contained andself_contained = FALSEoutput. It fails with the oldmodify_css()on pandoc 3.7 and 3.10.test_default_figure_optionscounted lines containingwidth="100%", which now also match the embedded CSS. It now counts<img>tags.BiocGenerics:::testPackage("BiocStyle")gives 29 tests, 0 errors, 0 failures on both pandoc 3.7.0.2 and 3.10.R CMD build+_R_CHECK_FORCE_SUGGESTS_=false R CMD check --no-manualgivesStatus: OK(no WARNING/NOTE).fig.small,fig.wide, a long caption, an uncaptioned figure, side-by-side images (captioned and uncaptionedinclude_graphics, two plots withfig.show = "hold", raw<img>tags) and 50%-wide centered figures. I took headless Chromium screenshots before and after at 1400px and 900px, and also compared eachimg/p.caption/preelement's computed box (left, width, height, padding) between the two renders:fig.small,fig.wide, long-caption and uncaptioned figures (and their captions) have identical boxes before and after, at both widths.fig.align = "center".Notes
:has()needs Chrome/Edge 105+, Safari 15.4+ or Firefox 121+. In older browsers the container indent is skipped, and reduced-width images still show, side by side, starting at the container's left edge.fig.small = TRUE, out.width = "500px"was about 25px wide and is now 500px.<img width="…">(other than 100%) is now indented to the figure column. Before, such an image was a block element anyway.Fixes #103
Fixes #52
Fixes #54