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

How to pass {{< highlight r >}} for pygments (instead of using highlight.js) #125

Closed
ciflikli opened this issue Jun 21, 2017 · 3 comments
Closed

Comments

@ciflikli
Copy link

After being directed to the bookdown upon creating my first issue (the answer to my problem was sitting there quite obviously) I took my time looking around (Hugo forums, GitHub) however still lacking the solution for my syntax highlighting problem.

Basically, I want to use pygments to be able to manipulate class colors (with pygmentsuseclasses = true. However, I cannot seem to find where to pass Hugo's highlight function in blogdown. I have the library on the path.

Highligth.js works fine with a customized .css, but syntax like operators, functions etc. do not span their own class. This post for example has the functionality I want (just inspect any code chunk), however it was built by Jekyll. He seems to pass {% highlight r %} before the code. How can I do that with blogdown? Thanks.

@yihui
Copy link
Member

yihui commented Jun 21, 2017

I have to confess that I'm opinionated on this issue. To me, syntax highlighting is more for decoration purposes. It is not essential, and not worth too much effort on improving the precision or granularity. I'm rarely conscious of which specific characters are colored or not, or what specific colors are used when I read source code. My mind is pretty much focused on the meaning of the code instead of cosmetics. On the other hand, I believe too much syntax highlighting is worse than no syntax highlighting at all. Personally I don't like using pygments in Hugo because the HTML source for <pre> will not be clean. That said,

  1. Did you actually add r.min.js? cf How to enable highlight.js for syntax highlighting of code blocks yihui/hugo-xmin#5

  2. If you really don't like highlight.js (with the R language support) and must go with Pygments:

    1. If you use plain Markdown, there is nothing special. Just follow the Hugo documentation.

    2. If you use R Markdown, it will be tricky and awkward. Your only option is blogdown::shortcode_html('highlight', 'your-language', .content = 'your code'). See the end of this section: https://bookdown.org/yihui/blogdown/content.html Given that it is so much hassle, I'd rather use highlight.js and do not highlight operators or function names.

@ciflikli
Copy link
Author

I hear you. I think you are right. I thought the flexibility was warranted in the beginning, but maybe not anymore. Especially putting the content inside the shortcode.

I didn't have r.min.js before, but I was using a custom package with R added in. I had a slight change in the highlighting, but I prefer this one actually (example post).

I think I'll roll with highlight.js for now. Thanks for the above.

@yihui
Copy link
Member

yihui commented Jul 6, 2017

FYI I have added the highlight option to blogdown::html_page(), which makes it possible for you to use client-side syntax highlighting through Pandoc instead of Pygments.

I'm not sure how compatible the Haskell library highlighting-kate is with Pygments.

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

2 participants