Skip to content

Fix quote_footer() rendering across tufte and non-tufte outputs - #134

Merged
cderv merged 9 commits into
mainfrom
fix-73
May 19, 2026
Merged

cderv merged 9 commits into
mainfrom
fix-73

Conversation

@cderv

@cderv cderv commented May 18, 2026 •

Copy link
Copy Markdown
Collaborator

quote_footer() produced inconsistent output across formats:

  • In rmarkdown::html_document() and bslib::bs_theme() themes
    (Bootstrap 3/4/5), the footer was not right-aligned because
    Bootstrap's CSS styles blockquote footer without text-align: right.
  • For Bootstrap 4 and 5, the CSS selector moved from
    blockquote footer to the .blockquote-footer class, so the bare
    <footer> emitted by quote_footer() received no Bootstrap styling
    at all (no em-dash, no grey small text).
  • The quote_footer('--- Author') pattern shown in the R Markdown book
    rendered as a doubled em-dash (— --- Author) in non-tufte HTML,
    because Bootstrap's ::before rule injects an em-dash on top of the
    caller's literal ---.

Fix

quote_footer() now emits <footer class="blockquote-footer" style="text-align: right;"> for non-tufte HTML. The class matches Bootstrap 4 and 5; Bootstrap 3 still styles the same element via its blockquote footer selector; tufte's own CSS is unaffected because it also targets blockquote footer.

To render an em-dash consistently across all outputs, the helper now strips a leading "---" (or em-dash) from text and branches per destination:

  • non-tufte HTML: strip the dash so Bootstrap's ::before em-dash is not doubled;
  • tufte HTML: insert an em-dash + non-breaking space in the markup, since tufte.css has no ::before rule;
  • LaTeX outputs (tufte or non-tufte): preserve the leading "---" so pandoc's smart-punctuation extension converts it to an em-dash glyph.

tufte_html() and tufte_pdf() now register a tufte.format entry in knitr::opts_knit so quote_footer() can detect whether it is being called from a tufte format without resorting to heuristics. This mirrors the rmarkdown.* entries that rmarkdown::render() already sets in opts_knit.

The "only works for HTML and LaTeX output" warning is silenced when knitr::pandoc_to() returns NULL, so quote_footer() can be used unconditionally in inline R expressions evaluated outside a pandoc context.

Test Plan

Most output is asserted in tests/testthat/test-utils.R (structural checks via xml2). Reviewer eyeball items:

  • Visually confirm right-alignment + em-dash placement of `r tufte::quote_footer('--- Joe Martin')` in a rendered html_document() (default Bootstrap 3) and in a bslib::bs_theme() Bootstrap 5 theme (only BS4 is exercised in tests).
  • Visually confirm --- Joe Martin renders as — Joe Martin in pdf_document() and tufte_handout outputs (relies on pandoc's smart-punct conversion, which is not asserted in tests).

Fixes #73

cderv added 8 commits May 19, 2026 10:32
Bootstrap CSS shipped by `rmarkdown::html_document()` styles the
blockquote footer (em-dash prefix, grey small text) but does not
right-align it. Add an inline `text-align: right` so the visual intent
of `quote_footer()` carries to non-tufte HTML formats.

Bootstrap 4 and 5 (via `bslib::bs_theme()`) replaced the `blockquote
footer` element selector with a class-based `.blockquote-footer`
selector. Tag the emitted `<footer>` with that class so BS4/5 themes
apply the same styling as BS3.

Also silence the "only works for HTML and LaTeX" warning when
`knitr::pandoc_to()` is NULL, so callers can use `quote_footer()`
unconditionally in inline R expressions evaluated outside a pandoc
context.
Lock file pins installed agent skills (posit-dev/skills) so the set is
reproducible across clones. The .claude/ and .agents/ directories hold
copies of those skills and are personal/transient — gitignored, and
R-build-ignored to keep R CMD build output clean.
…tputs

`quote_footer()` previously emitted whatever `text` the caller supplied
verbatim, leaving the em-dash story to each format's CSS or to pandoc's
smart-punct extension. This produced different visual output for the same
R call across tufte HTML, non-tufte HTML, and LaTeX outputs. In
particular, the pattern shown in the R Markdown documentation,
`quote_footer('--- Joe Martin')`, rendered as a doubled em-dash
(`-- --- Joe Martin`) in `html_document()` because Bootstrap's
`blockquote footer::before` rule already injects an em-dash.

Detect a leading `"---"` (or em-dash) in `text` and branch on whether
the active output is a tufte format. The tufte output formats now
register a `tufte.format` entry in `knitr::opts_knit` so
`quote_footer()` can read it without heuristics, mirroring the pattern
used by `rmarkdown` for its own `rmarkdown.*` opts_knit entries.

- non-tufte HTML: strip the leading `"---"` so Bootstrap CSS does not
  double the em-dash;
- tufte HTML: insert an em-dash + non-breaking space in the markup,
  since `tufte.css` has no `::before` rule;
- LaTeX (tufte or non-tufte): preserve the leading `"---"` so pandoc's
  smart-punct extension converts it to an em-dash glyph.

Add a `local_knit_opts()` test helper that temporarily sets
`knitr::opts_knit` entries via `withr::defer`, and use it to exercise
the new tufte-vs-non-tufte branch in `quote_footer()`. Switch the
remaining `expect_false(grepl(...))` calls to `expect_no_match()`.
- DESCRIPTION: add missing trailing comma after `xml2` in `Suggests`.
  Without it `read.dcf()` parses `xml2` and `bookdown` as a single
  malformed dependency, breaking R CMD check (review job 1206).

- `quote_footer()`: detect an active `bslib::bs_theme()` via
  `bslib::bs_current_theme()` instead of unconditionally stripping a
  leading `"---"` for all non-tufte HTML outputs. The unconditional
  strip silently dropped the em-dash for `html_document(theme = NULL)`
  and other non-Bootstrap HTML formats (ioslides, slidy, custom
  frameworks, ...), since no CSS rule replaced the stripped marker.

  Three HTML branches now:

  - Tufte HTML: emit `<footer>` with an em-dash glyph injected in markup
    (unchanged).
  - Non-tufte HTML with bslib (Bootstrap 4/5) active: strip the `"---"`
    and emit `<footer class="blockquote-footer">` so the
    `.blockquote-footer::before` rule supplies the em-dash exactly once.
  - All other HTML (Bootstrap 3 default `html_document`, `theme: null`,
    ioslides, slidy, ...): emit `<p>` with the em-dash glyph injected in
    markup. `<p>` is chosen rather than `<footer>` to avoid Bootstrap 3's
    `blockquote footer::before` rule doubling the em-dash for callers
    following the documented `quote_footer('--- Author')` pattern.

  Add `bslib` to `Suggests` so `R CMD check` recognises the namespace
  reference; the call to `bslib::bs_current_theme()` is wrapped in
  `tryCatch()` for robustness when the package is absent.

  Add integration tests rendering `quote_footer('--- Author')` in
  `html_document` with default theme, `theme = NULL`, and bslib BS4,
  asserting that the rendered footer contains an em-dash but not a
  literal `"---"` in each case (review job 1209).
The bslib-based detection introduced in 9a811ec covered Bootstrap 4/5
via `bslib::bs_current_theme()` but had no signal for the legacy
Bootstrap 3 default theme (which doesn't go through bslib). The
fallback `<p>` branch silently dropped Bootstrap's CSS-supplied
em-dash for the `quote_footer('Author')` (no leading dash) case in
`html_document(theme = "default")` — a regression for the rmarkdown
default.

Revert to the simpler unconditional strip from cf58d41: non-tufte
HTML emits `<footer class="blockquote-footer">` with the leading
`"---"` stripped, relying on Bootstrap CSS (`::before` on either the
`blockquote footer` element selector in BS3 or the
`.blockquote-footer` class selector in BS4/5) to supply the em-dash.

Known limitation (review job 1209): when the active HTML output ships
no Bootstrap CSS (e.g. `html_document(theme = NULL)`, ioslides, slidy,
custom HTML frameworks), the em-dash is silently dropped. Detecting
this reliably requires distinguishing legacy BS3 default from
non-Bootstrap formats at knit time, which has no clean signal — bslib
returns NULL for both. The trade-off favours not regressing the
common BS3-default case.

Keep the DESCRIPTION trailing-comma fix from 9a811ec (review job
1206); drop `bslib` from `Suggests` since it is no longer referenced.
R CMD check warns on non-ASCII characters in R source. Replace the
literal em-dash in the dash_pattern regex and the em-dash + nbsp prefix
literal with — /   escapes, and rewrite the comment glyph in
plain English. No behaviour change.
The original issue reported that a markdown citation passed to
quote_footer() rendered literally (un-converted) in beamer with
citation_package: natbib. The behaviour passes on current pandoc; lock
it with three tests:

- Unit-level: assert pandoc emits \citep when given quote_footer()'s
  LaTeX output (--natbib path, no TinyTeX required).
- Integration: render tufte_handout and beamer_presentation with
  natbib + a citation inside quote_footer(), assert the kept .tex
  contains both \hfill and \citep[3]{dorian10}.
@cderv
cderv merged commit f00f702 into main May 19, 2026
18 checks passed
@cderv
cderv deleted the fix-73 branch May 19, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different behavior of quote_footer() in beamer and html

1 participant