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

[FR] Syntax highlighting via downlit #152

Closed
mattwarkentin opened this issue Feb 23, 2022 · 5 comments
Closed

[FR] Syntax highlighting via downlit #152

mattwarkentin opened this issue Feb 23, 2022 · 5 comments

Comments

@mattwarkentin
Copy link
Contributor

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
Copy link
Contributor Author

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

@cderv
Copy link

cderv commented Feb 28, 2022

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. (Details breaks code formatting yihui/xaringan#333 (comment)). 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.

@mattwarkentin
Copy link
Contributor Author

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
Copy link

cderv commented Mar 9, 2022

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
Copy link
Owner

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.

@gadenbuie gadenbuie closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants