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

Đã đóng
#1,079 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #1093 của @cscheid — đã merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
frontend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
Rust
Star
293
Fork
20
Merge trung bình
5 giờ 38 phút
Pull request đã merge (30 ngày)
199

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quarto-dev/q2

Tất cả issue của quarto-dev/q2

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.