Code blocks in a language without a grammar get no div.sourceCode wrapper, so they lose the code-block box

Aperta
#1,079 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
frontend

Direzione di ricerca

Start by tracing how q2 renders fenced code blocks and adds sourceCode classes or the div.sourceCode wrapper, comparing the grammar and no grammar paths. Reproduce with the provided ini, default, and bash blocks in index.qmd. Done when language blocks without a grammar retain the code block box, and the behavior for blocks with no language matches the intended choice.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

When q2 has no grammar for a code block's language, it writes a bare <pre class="<lang> code-with-copy">, with no div.sourceCode wrapper and no sourceCode classes. The theme draws the code-block box (background, border, padding) on div.sourceCode, so these blocks render as plain text on the page background. Quarto 1 (Pandoc) wraps every block whose language its highlighter knows in div.sourceCode, even when it adds no colors. An example is ```default.

So a migrated site loses the code-block box on every block in a language outside q2's grammar set, not only the colors.

Versions

  • q2 0.41.0 (macOS, arm64)
  • Quarto 1.11.7, for comparison
  • Chrome, 1280×800 viewport, default theme

Repro

_quarto.yml:

project:
  type: website

website:
  title: Example

index.qmd:

---
title: Code styling
---

```ini
[Widget]
; Turn the widget on.
Enabled = true
```

```default
/opt/widget/1.0/bin/widget
```

```bash
echo "highlighted in both"
```
q2 render

Expected (Quarto 1.11.7)

All three blocks are div.sourceCode > pre.sourceCode.<lang>, and all three have the box. Computed style of each div.sourceCode: background rgba(233, 236, 239, 0.65), border 1px solid. The default block has the box but no colors.

<pre class="sourceCode ini code-with-copy">
<pre class="sourceCode default code-with-copy">
<pre class="sourceCode bash code-with-copy">

Actual (q2 0.41.0)

<pre class="ini code-with-copy">
<pre class="default code-with-copy">
<pre class="sourceCode bash">

Only the bash block has the box. The ini and default blocks have background rgba(0, 0, 0, 0) and no border.

Notes

  • Quarto 1 still leaves blocks with no language, and languages its highlighter does not know (for example text, nginx), without the wrapper. So "wrap every block that has a language class" would box a few blocks that Quarto 1 does not. To me that looks like the better default, but it is a choice.
  • Scale, from one real documentation site (about 2,070 code blocks): 617 blocks lost the box after the migration. They were ini 466, default 113, markdown 24, toml 5, and a few each of dockerfile, xml, powershell, apache, conf, and txt.
  • A user grammar in _quarto/grammars/<lang>/ fixes this for one language, because a highlighted block gets the wrapper. But that does not help default, which has nothing to highlight.
Lingua principale
Rust
Stelle
293
Fork
20
Merge medio
7h 45m
PR unite (30g)
187

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quarto-dev/q2

Tutte le issue di quarto-dev/q2

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.