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

Abierto
#1,079 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
frontend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Rust
Estrellas
293
Forks
20
Merge medio
7 h 45 min
PR fusionados (30 d)
187

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de quarto-dev/q2

Todos los issues de quarto-dev/q2

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.