Skip to content

Disable code line numbers by default; add page-level opt-in#236

Merged
cwickham merged 3 commits intomainfrom
line-numbers-default-off
May 8, 2026
Merged

Disable code line numbers by default; add page-level opt-in#236
cwickham merged 3 commits intomainfrom
line-numbers-default-off

Conversation

@cwickham
Copy link
Copy Markdown
Collaborator

@cwickham cwickham commented May 7, 2026

Closes #208.

Summary

  • Line numbers no longer render by default. Posts that want them set code-line-numbers: true in frontmatter — same key Quarto authors already use.
  • The render hook (layouts/_default/_markup/render-codeblock.html) reads the page param and forces linenos=true into chroma options when set.
  • For posts that opt in, the gutter got a small style refresh: lighter line-number color (gray-500, AAA contrast on blue-100), a 1px white separator between the gutter and the code, and corrected horizontal padding (the previous .lntable padding was a no-op because Tailwind preflight forces border-collapse: collapse, which kills <table> padding — moved onto the cell <pre> elements).
  • Opted in the two existing posts where prose references specific line numbers: shinychat-tool-ui and latex-output-tables.

Caveats

  • Quarto strips code-line-numbers (document, per-cell, and per-block forms) when rendering to GFM, so page-level opt-in is currently the only honored form. Per-cell line-range highlights like "7-10" in shinychat-tool-ui remain unrendered — they were already unrendered in production before this PR.
  • latex-output-tables got an incidental fix: format: htmlformat: hugo-md (the post was outputting HTML even though the project default is hugo-md, an artifact of the original port) and code-fold: yescode-fold: true for Quarto's strict YAML. The re-rendered .md includes a code-fold details wrapper around the first Python block as a result.

Test plan

  • Confirm no line numbers on a normal post (e.g. /blog/2026-04-23_mori-0-1-0/)
  • Confirm line numbers present on /blog/2025-11-20_shinychat-tool-ui/ and /blog/2024-11-13_latex-output-tables/
  • Confirm contrast still passes WCAG 2.1 AA on the new gray-500 line numbers (8.79:1 against blue-100)
  • Confirm code-fold details wrapper renders as expected on the latex post's first Python block

Closes #208. Line numbers now appear only on posts that set
`code-line-numbers: true` in frontmatter — matches the Quarto
authoring pattern people already know.

Mechanism:
- hugo.toml: flip `[markup.highlight] lineNos` to false
- render-codeblock hook: when the page sets `code-line-numbers`,
  merge `linenos: true` into chroma options for every block on
  that page

Style refresh for line-numbered blocks:
- color → `--color-gray-500` (8.79:1 contrast on blue-100, AAA)
- white 1px separator between gutter and code
- horizontal padding moved off `<table>` (Tailwind preflight forces
  border-collapse:collapse, which makes table padding a no-op) and
  onto the cell `<pre>` elements where it actually renders

Opted in two posts that need numbering for prose references:
- shinychat-tool-ui (per-cell `#| code-line-numbers` in source got
  stripped by Quarto's GFM renderer; page-level brings it back —
  line-range highlights like "7-10" remain unrendered)
- latex-output-tables (also switched `format: html` → `format:
  hugo-md` and tightened YAML strictness for `code-fold`)
@netlify
Copy link
Copy Markdown

netlify Bot commented May 7, 2026

Deploy Preview for posit-open-source canceled.

Name Link
🔨 Latest commit 368ed37
🔍 Latest deploy log https://app.netlify.com/projects/posit-open-source/deploys/69fd0d609a168a0008cae2fb

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Publishing checklist

  • Get a review — request at least one reviewer on this PR
  • Check your post — once the deploy preview is ready, a comment will appear with direct links to your post
  • Check the blog listing — confirm your post appears with the correct title, image, and description
  • Merge — once everything looks good and you have an approving review, merge to main

cwickham added 2 commits May 7, 2026 15:06
Add the new `code-line-numbers` toggle to the authoring guide
(under .qmd content reference, alongside code-folding) and the
metadata schema in CLAUDE.md.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Blog YAML Checks

content/blog/great-tables/latex-output-tables/index.md

  • ⚠️ image is required but missing.
  • ⚠️ image-alt is required but missing.

content/blog/shiny/shinychat-tool-ui/index.md

  • ⚠️ image-alt is required but missing.

Summary: 2 files checked, 3 warnings

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

@cwickham cwickham merged commit 70b52d8 into main May 8, 2026
13 checks passed
@cwickham cwickham deleted the line-numbers-default-off branch May 8, 2026 21:25
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.

Line numbers make code blocks harder to read

1 participant