A page's `body-classes` replaces the layout classes on `<body>` instead of adding to them

Open
#1,218 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start with the body-classes handling in crates/quarto-core/src/template.rs, especially the comments at lines 201 and 1232 cited in the issue. Compare the rendered body classes from the provided q2 repro with the expected Quarto 1 output, then run the repro after the change. Done when page classes are added to computed layout classes while the plain page output remains correct.

Written by the indexing model from the issue text.

Description

This issue was written by Claude while adding q2 support to Great Docs. The output shown comes from running each repro.

Bug description

When a page sets body-classes, q2 writes only those classes on <body>. The classes q2 computes
for the layout, such as nav-fixed, fullcontent and quarto-light, are dropped. Quarto 1 adds the
page's classes to the computed ones.

This looks intended: crates/quarto-core/src/template.rs:201 says a body-classes "supplied by the
author or a filter is kept wholesale and suppresses the compose below", and so does the comment at
:1232. But the theme's CSS and JavaScript select on those classes: nav-fixed for the fixed
navbar, fullcontent and the other layout classes for the page grid, and quarto-light for the
color scheme. So a page that adds one class of its own loses that styling.

Great Docs sets body-classes on its API and CLI reference pages (doc-reference,
doc-api-page and others), on blog index pages and on the tags index. Its CSS uses them to style
those pages. Under q2 each of those pages loses its layout classes. As a workaround, Great Docs' filter moves body-classes
into a <meta> tag, and a post-render script adds them to the classes q2 wrote.

Steps to reproduce
mkdir body-classes && cd body-classes
printf 'project:\n  type: website\nwebsite:\n  navbar:\n    left: [index.qmd, plain.qmd]\n' > _quarto.yml
printf -- '---\ntitle: Home\ntoc: false\nbody-classes: my-page\n---\n\nHome.\n' > index.qmd
printf -- '---\ntitle: Plain\ntoc: false\n---\n\nPlain.\n' > plain.qmd
q2 render
grep -o '<body[^>]*>' _site/index.html _site/plain.html
Actual behavior
_site/index.html:<body class="my-page">
_site/plain.html:<body class="fullcontent nav-fixed quarto-light">
Expected behavior

As in Quarto 1.9.37:

_site/index.html:<body class="nav-fixed my-page fullcontent quarto-light">
_site/plain.html:<body class="nav-fixed fullcontent quarto-light">

Add the page's body-classes to the computed classes. If replacing them should still be possible,
an explicit opt-in such as !prefer would serve, rather than making replacement the default.

Dominant language
Rust
Stars
302
Forks
22
Avg merge
5h 2m
Merged PRs (30d)
213

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quarto-dev/q2

All issues in quarto-dev/q2

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.