Closed mattwarkentin closed 2 years ago
@cderv would probably have great insights into this possible feature...
Thanks for the ping, I would have probably miss this otherwise. I did not looked closely but it can be currently not straight forward. Some thoughts:
About downlit, it allows to highlight for HTML currently with two set of classes : The ones for Pandoc's own highlighter to work with Pandoc's highlighting styles, and the ones for Chroma used by Hugo. Currently, there is not direct support for highlight JS. However, this could probably be added there. About disabling highlight.js to use downlit, this would mean probably that non R code source code would not have highlighting anymore. Not a problem for R only presentation, but could be for others.
About xaringan, it does not use Pandoc for syntax highlighting. So downlit can't be used as post processing on the rendered HTML (as it will be rendered in browser). One way would be to use on the md file as pre processor, but it is also tied to Pandoc so could be tricky. Applying as a source hook (like in distill I think) would be a solution but this would introduce some HTML content inside the markdown content to be rendered by remark.js, and we know this can cause trouble in some cases. (https://github.com/yihui/xaringan/issues/333#issuecomment-943359597). To try. But I think auto linking won't be possible in that case (if I remember correctly some previous try).
If the above is done, this would add some HTML with classes for Chroma or Pandoc in the current downlit state. So, the classes applied won't get any CSS theme applied. It requires indeed to have some stylesheets built specially. Either one by CSS theme included, or some specific ones for highlighting theme. We could port pandoc styles as their own CSS obviously, but I wonder if it would not be better to come back to my first point about support highlightjs format in downlit. In that case, the highlightjs style could be chosen, and this would allow to have also the same style for non R code chunks.
So anyhow, this could be tried in a POC to see what would be the best solution for this, its complexity and if it is worth the benefit (having downlit highlighting instead of highlight.js one).
Regarding where, it could be in directly in xaringan for convenience I get. Otherwise, in xaringanExtra, it seems possible to add a hook and some CSS probably to be used in a presentation.
Thanks for the detailed response, @cderv. It seems like making downlit
play nicely with hightlight.js
is the most robust solution. Not sure when I will have a chance to play around with this until after I am done my dissertation. But this may be something I come back to in the future to see if we can get something working.
Great !
It seems like making downlit play nicely with hightlight.js is the most robust solution.
Maybe you could open this question as feature request in downlit to see if this is something that would be welcomed before you plan to work on this ?
If xaringan changed their flow to use pandoc, then I think this would be feasible. But otherwise, it's pretty much a non-starter. downlit operates on pandoc's AST or on rendered HTML, neither of which are available to xaringan during the rendering step or even after the rendering step.
Hi @gadenbuie,
How difficult do you think it would be to use
{downlit}
for syntax highlighting in axaringan
presentation?I think a
knitr
output hook for the source code, bundling a stylesheet, and disablinghighlight.js
would get most of the way there. What do you think? It would be nice to have the autolinking.I would be happy to work on a PR, but I wanted to float it past your first to see what you think.