From 67c544082dae7839b18d519e21f73ca3c24a4910 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 2 Sep 2025 17:17:25 +0200 Subject: [PATCH 1/2] revealjs - code line numbers not working when set to "1" because it was parsed as true. --- news/changelog-1.8.md | 1 + .../filters/quarto-pre/line-numbers.lua | 4 +++- tests/docs/smoke-all/2025/09/02/13316.qmd | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/docs/smoke-all/2025/09/02/13316.qmd diff --git a/news/changelog-1.8.md b/news/changelog-1.8.md index 390412fdc73..ad6731d9627 100644 --- a/news/changelog-1.8.md +++ b/news/changelog-1.8.md @@ -42,6 +42,7 @@ All changes included in 1.8: - ([#12598](https://github.com/quarto-dev/quarto-cli/pull/12598)): Ensure `.fragment` on an image with caption applies to whole figure. - ([#12716](https://github.com/quarto-dev/quarto-cli/issues/12716)): Correctly resolve `"brand"` set in `theme` configuration for document in subdirectory from project root. - Use `cdn.jsdelivr.net` for mathjax dependencies to ensure consistent CDN usage across formats. Previously, `cdnjs.cloudflare.com` was used for `revealjs` mathjax dependencies, while `cdn.jsdelivr.net` was used for html format. +- [#13316](https://github.com/quarto-dev/quarto-cli/issues/13316): `code-line-numbers: "1"` correctly highlight the first line now. ### `docx` diff --git a/src/resources/filters/quarto-pre/line-numbers.lua b/src/resources/filters/quarto-pre/line-numbers.lua index e5c818666b3..300ed2904fb 100644 --- a/src/resources/filters/quarto-pre/line-numbers.lua +++ b/src/resources/filters/quarto-pre/line-numbers.lua @@ -26,7 +26,9 @@ end function lineNumbersAttribute(el) local default = param(constants.kCodeLineNumbers, false) local lineNumbers = attribute(el, constants.kCodeLineNumbers, default) - if lineNumbers == true or lineNumbers == "true" or lineNumbers == "1" then + -- format that do accept string for this attributes. "1" and "0" should not be parsed as TRUE / FALSE + local acceptStrings = _quarto.format.isRevealJsOutput() and not _quarto.format.isDocusaurusOutput() + if lineNumbers == true or lineNumbers == "true" or (lineNumbers == "1" and not acceptStrings) then return true elseif lineNumbers == false or lineNumbers == "false" or lineNumbers == "0" then return false diff --git a/tests/docs/smoke-all/2025/09/02/13316.qmd b/tests/docs/smoke-all/2025/09/02/13316.qmd new file mode 100644 index 00000000000..2d2cb503cf2 --- /dev/null +++ b/tests/docs/smoke-all/2025/09/02/13316.qmd @@ -0,0 +1,22 @@ +--- +format: html +_quarto: + tests: + html: + ensureHtmlElements: + - ['pre.sourceCode.number-lines'] + - ['#cb1[data-code-line-numbers="1"]'] + revealjs: + ensureHtmlElements: + - ['#cb1[data-code-line-numbers="1"]', 'pre.sourceCode.number-lines'] + - [] +execute: + echo: true +--- + +```{r} +#| code-line-numbers: "1" +mean( + c(1, 2, 3, 4, 5) +) +``` From 75717b571ff73ba8b5c3803ac3e9ca758c04e3f0 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 2 Sep 2025 17:35:48 +0200 Subject: [PATCH 2/2] docusaurus - fix code-line-numbers: "1" not highlighting first line This also affects docusaurus-md output. Add test, and fix filter --- news/changelog-1.8.md | 4 ++++ src/resources/filters/quarto-pre/line-numbers.lua | 2 +- tests/docs/smoke-all/2025/09/02/13316.qmd | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/news/changelog-1.8.md b/news/changelog-1.8.md index ad6731d9627..07565bcd62e 100644 --- a/news/changelog-1.8.md +++ b/news/changelog-1.8.md @@ -71,6 +71,10 @@ All changes included in 1.8: - ([#12676](https://github.com/quarto-dev/quarto-cli/issues/12676)): Add support for rendering layout panels that are not floats. +### `docusaurus-md` + +- [#13316](https://github.com/quarto-dev/quarto-cli/issues/13316): `code-line-numbers: "1"` correctly highlight the first line now. + ## Projects ### `website` diff --git a/src/resources/filters/quarto-pre/line-numbers.lua b/src/resources/filters/quarto-pre/line-numbers.lua index 300ed2904fb..00a88ace4da 100644 --- a/src/resources/filters/quarto-pre/line-numbers.lua +++ b/src/resources/filters/quarto-pre/line-numbers.lua @@ -27,7 +27,7 @@ function lineNumbersAttribute(el) local default = param(constants.kCodeLineNumbers, false) local lineNumbers = attribute(el, constants.kCodeLineNumbers, default) -- format that do accept string for this attributes. "1" and "0" should not be parsed as TRUE / FALSE - local acceptStrings = _quarto.format.isRevealJsOutput() and not _quarto.format.isDocusaurusOutput() + local acceptStrings = _quarto.format.isRevealJsOutput() or _quarto.format.isDocusaurusOutput() if lineNumbers == true or lineNumbers == "true" or (lineNumbers == "1" and not acceptStrings) then return true elseif lineNumbers == false or lineNumbers == "false" or lineNumbers == "0" then diff --git a/tests/docs/smoke-all/2025/09/02/13316.qmd b/tests/docs/smoke-all/2025/09/02/13316.qmd index 2d2cb503cf2..d4a60b58f9c 100644 --- a/tests/docs/smoke-all/2025/09/02/13316.qmd +++ b/tests/docs/smoke-all/2025/09/02/13316.qmd @@ -1,4 +1,5 @@ --- +title: highlight first line format: html _quarto: tests: @@ -10,6 +11,10 @@ _quarto: ensureHtmlElements: - ['#cb1[data-code-line-numbers="1"]', 'pre.sourceCode.number-lines'] - [] + docusaurus-md: + ensureFileRegexMatches: + - ['[`]{3}r \{1\} showLineNumbers'] + - [] execute: echo: true ---