Open thohan88 opened 3 years ago
I think this highlighting feature from remark is tricky. Let me explain :
In remarkjs this feature is made to highlight some code block in mardkown. When using .md
as remarkjs expect this code block won't be executed - so it does not matter if this is valid code for the language or not.
That is why having a *
(1st example ☝️) works when you use a non evaluated sql chunk, because it is directly remarkjs support (see https://github.com/gnab/remark/wiki/Configuration#highlighting)
xaringan will add support for {{ ... }}
and ... #<<
for knitr code chunk. These are replaced by *
in source chunk for remark to work. That is why using #<<
not in a knitr chunk does not work. (2nd example ☝️ ). This two syntax options have been chosen because it is valid R code, so adding those in the chunk is not creating issue with parsing and execution.
This is a bit shown in https://slides.yihui.org/xaringan/#29
About the third example, I think this is not working because {{ ... }}or
# <<or
*` are not valid SQL code. So parsing will fail hence the error.
So yes for now it won't work with SQL chunk, and any other engine where thos syntax are not valid code. This is because the tokens are not remove from the code before execution.
Maybe we could add a highlight.input
chunk option to mimic highlight.output
chunk option to pass a numeric vector to highlight in all kind of engine ?
Other solution would be to find another token supported by SQL.
Maybe we could add a
highlight.input
chunk option to mimichighlight.output
chunk option to pass a numeric vector to highlight in all kind of engine ?
I like this idea and was thinking the same thing, although I would propose we call it highlight.source
.
Oh yeah this is a better name :)
It is not as easy as I thought to cover all cases (like collapse = TRUE
) but I got a working branch for the SQL example - I'll share it so you have a look
I find highlighting lines to be a really useful feature of xaringan, but discovered that it's currently not working for evaluated SQL-expressions. Asterix (
*
) appears to work in non-evaluated expressions, but#<<
does not. Both throw an error in evaluated SQL-expressions.Example
Rmd
-file:Works - but expression is not evaluated
Does not work
Throws an error
Throws an error
Supporting this may not be high priority, but thought I would report it since I already created another SQL-related issue (#307).
Once again, thank you for all your great work.