gadenbuie / xaringanExtra

:ferris_wheel: A playground of enhancements and extensions for xaringan slides.
https://pkg.garrickadenbuie.com/xaringanExtra
Other
448 stars 36 forks source link

[FR] Syntax highlighting via downlit #152

Closed mattwarkentin closed 2 years ago

mattwarkentin commented 2 years ago

Hi @gadenbuie,

How difficult do you think it would be to use {downlit} for syntax highlighting in a xaringan presentation?

I think a knitr output hook for the source code, bundling a stylesheet, and disabling highlight.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.

mattwarkentin commented 2 years ago

@cderv would probably have great insights into this possible feature...

cderv commented 2 years ago

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:

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.

mattwarkentin commented 2 years ago

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.

cderv commented 2 years ago

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 ?

gadenbuie commented 2 years ago

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.