Skip to content

Commit d8deb5a

Browse files
authored
Merge pull request #1041 from cderv/code-line-number-knitr
[knitr] Correctly handle code-line-numbers=false in R chunk
2 parents 2bfe2d6 + 76f1a8b commit d8deb5a

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

src/resources/rmd/hooks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
380380
}
381381
lineNumbers <- options[["code-line-numbers"]]
382382
if (!is.null(lineNumbers)) {
383-
attr <- paste(attr, paste0('code-line-numbers="', as.character(lineNumbers), '"'))
383+
attr <- paste(attr, paste0('code-line-numbers="', tolower(as.character(lineNumbers)), '"'))
384384
}
385385

386386
lang <- tolower(options$engine)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: "Plot Test"
3+
format: html
4+
code-line-numbers: true
5+
knitr:
6+
opts_chunk:
7+
eval: false
8+
---
9+
10+
# with line number comment {#with-numbering}
11+
12+
```{r}
13+
1 + 2
14+
```
15+
16+
# no line number comment {#no-numbering}
17+
18+
```{r}
19+
#| code-line-numbers: false
20+
1 + 2
21+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* render-r.test.ts
3+
*
4+
* Copyright (C) 2020 by RStudio, PBC
5+
*
6+
*/
7+
8+
import { fileLoader } from "../../utils.ts";
9+
import { ensureHtmlElements } from "../../verify.ts";
10+
import { testRender } from "./render.ts";
11+
12+
const doc = fileLoader("code-highlighting")(
13+
"code-line-number-knitr.qmd",
14+
"html",
15+
);
16+
testRender(doc.input, "html", false, [
17+
ensureHtmlElements(
18+
doc.output.outputPath,
19+
["#with-numbering div.cell-code > pre.number-lines"],
20+
["#no-numbering div.cell-code > pre.number-lines"],
21+
),
22+
]);

0 commit comments

Comments
 (0)