-
Notifications
You must be signed in to change notification settings - Fork 78
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
BUG: mark
can't cope with multiple classes in class.*
chunk options
#106
Comments
This is because the CommonMark spec doesn't support multiple classes for code blocks (although Pandoc does): commonmark::markdown_html('```{.op1 .op2}
## [1] 2
```') <pre><code class="language-{.op1">## [1] 2
</code></pre> But I think it makes sense to support this feature. I'll see what I can do. |
Should be fixed now. Thanks for the report! You can install the development version via remotes::install_github('rstudio/markdown') Or wait for an hour or two and install.packages('markdown', repos = 'https://rstudio.r-universe.dev') Make sure |
Thanks for the fast fix. But there is one more thing I am buffled (I reformatted the HTML by hand for better legibility): cc <- "```{r class.output = c(\"ss\", \"tt\")}\n1+1\n```"
cat(cc)
# ```{r class.output = c("ss", "tt")}
# 1+1
# ```
cat(knitr::knit(text = cc))
# ```r
# 1+1
# ```
# ```{.ss .tt}
# ## [1] 2
# ```
cat(mark(knitr::knit(text = cc)))
# <pre>
# <code class="language-r">1+1</code>
# </pre>
# <pre>
# <code class="language-ss tt">## [1] 2# </code>
# </pre> Reading https://spec.commonmark.org/0.28/#info-string I understand that the first class element becomes prefixed with .language-ss {/* */} // must not forget to prefix my class with language-
.tt {/* */} // must not forget to NOT prefix the second class Is it then recommended to always add a (dummy) class ( cc <- "```{r class.output = c(\"r\", \"ss\", \"tt\")}\n1+1\n```"
cat(mark(knitr::knit(text = cc)))
# <pre><code class="language-r">1+1
# </code></pre>
# <pre><code class="language-r ss tt">## [1] 2
# </code></pre> .ss {/* */}
.tt {/* */} If this is the intended behaviour, would it make sense to add an |
I thought about this issue when implementing this feature yesterday. Since this is outside the CommonMark specs, I don't know what I should do. Adding the The second reason is that it should be rare that the same code in a single code block can have multiple languages (e.g., The third reason is the rest of classes may not be language names at all, and class names like
Again, I don't want to bother users who do not desire class names that they didn't specify (BTW, knitr::opts_hooks$set(class.output = function(options) {
options$class.output = c('r-output', options$class.output)
options
}) |
I guess this is what I tripped over in the first place. For me, After reading the specs, I understand now that the first class becomes the language class (prefixed by
Well, they should provide the language tag (whatever this should be for an output chunk) as well because otherwise they get
Exactly, and not knowing that the first class IS the language name (and not a custom class) created all this mess for me ;) To sum up, as a user it was not clear to me that the first item of |
Good suggestion. I'll do it. Thanks! |
Yihui Xie (13): start the next version finally I can get rid of this internal function thanks to the leaflet release v2.2.0: https://github.com/rstudio/leaflet/releases/tag/v2.2.0 use PCRE to fix #104, in the same way as a5b42c2 define an internal version of gregexpr() that has perl = TRUE by default add a comment so that I can remember why I'm using perl = FALSE here gregexpr() has perl = TRUE by default now, so no need to have this extra argument (`...` is enough) rmarkdown 2.18 was released on 2022-11-09; I assume it's old enough that not many people still use lower versions close #105: support HTML widgets fix #106: support attributes for fenced code blocks add documentation for fenced code blocks: rstudio/markdown#106 (comment) check the availability of rmarkdown before processing HTML dependencies return early if there are no HTML dependencies to process CRAN release v1.9
Consider the following reprex:
As you can see the rendered HTML is a mess. Changing
class.output = c("op1", "op")
yields the same results.Using a single `class does work:
The text was updated successfully, but these errors were encountered: