Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code blocks with no language specified have class="NA" in generated HTML #1251

Closed
wch opened this issue Sep 10, 2021 · 5 comments · Fixed by #1395
Closed

Code blocks with no language specified have class="NA" in generated HTML #1251

wch opened this issue Sep 10, 2021 · 5 comments · Fixed by #1395
Labels
bug an unexpected problem or unintended behavior markdown ⬇️

Comments

@wch
Copy link
Member

wch commented Sep 10, 2021

For example:

#' ```
#' r <- reactive({ compute(bigdata()) } %>%
#'   bindCache({ extract_most_recent_time(bigdata()) })
#' ```

https://github.com/rstudio/shiny/blob/6f46b847e2efb74a0cb82edee4d1c60658d8c9e1/R/bind-cache.R#L60-L63

turns into:

\if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- reactive(\{ compute(bigdata()) \} \%>\%
  bindCache(\{ extract_most_recent_time(bigdata()) \})
}\if{html}{\out{</div>}}

https://github.com/rstudio/shiny/blob/6f46b847e2efb74a0cb82edee4d1c60658d8c9e1/man/bindCache.Rd#L66-L68

(Note that in the linked code above, it was generated with roxygen2 7.1.1 and does not have the sourceCode class, but the NA issue is still present.)

If ```R is used to open the code block, then it (correctly) turns into class="sourceCode R".

Update: Are curly braces (like ```{r, eval=FALSE}) needed for syntax highlighting?

@gaborcsardi
Copy link
Member

Would you prefer dropping the NA or using R instead?

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Sep 10, 2021
@wch
Copy link
Member Author

wch commented Sep 10, 2021

I'm conflicted -- I think in most cases, people would want R, but there are many cases where you might want to display non-R text (like tabular data), and then how would you do that? I suppose you could use something like txt, but that's very non-obvious to users.

@maelle
Copy link
Contributor

maelle commented Sep 11, 2021

FWIW pkgdown will assume code blocks with no language specified are R blocks. (or maybe it shouldn't, then 🙂 ) r-lib/pkgdown#1724

@hadley
Copy link
Member

hadley commented Mar 29, 2022

I think we should drop the class = "NA" and not imply R.

pkgdown can continue guessing that all unmarked code blocks are R because it will try to parse them, and if they're not valid R code they don't get R syntax highlighting.

@hadley
Copy link
Member

hadley commented Jul 10, 2022

Ok, this problem was more subtle than I thought. It only appears if the first character in the code is "r":

library(roxygen2)

out <- roc_proc_text(rd_roclet(), "
#' Title
#'
#' ```
#' r <- 1:10
#' ```
#' @md
foo <- function() {}")[[1]]
out$get_section("description")
#> \description{
#> \if{html}{\out{<div class="sourceCode NA">}}\preformatted{r <- 1:10
#> }\if{html}{\out{</div>}}
#> }

Created on 2022-07-10 by the reprex package (v2.0.1)
vs

library(roxygen2)

out <- roc_proc_text(rd_roclet(), "
#' Title
#'
#' ```
#' x <- 1:10
#' ```
#' @md
foo <- function() {}")[[1]]
out$get_section("description")
#> \description{
#> \if{html}{\out{<div class="sourceCode">}}\preformatted{x <- 1:10
#> }\if{html}{\out{</div>}}
#> }

Created on 2022-07-10 by the reprex package (v2.0.1)

hadley added a commit that referenced this issue Jul 10, 2022
hadley added a commit that referenced this issue Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior markdown ⬇️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants