I recently started using the blogdown package in R to create static websites with Hugo. I’m currently using the cactus plus theme.
When I set pygmentsuseclasses = true in config.toml, the code chunks are turned into classes, however the functionality is limited: I only get .hljs-string, number, keyword, and comment classes (wrapped by pre and code) for R syntax. Operators, functions etc. are thrown together as hljs php, meaning they all share the same properties and look identical.
In comparison, when I inspect a website using the same theme (but in Jekyll), there are way more classes, allowing further customisation. Is it possible to have the same functionality in Hugo? Thanks.
Thanks for the reply. Sorry, I don’t think I formulated the question well - I’m also new to the platform, so I might have some terms mixed up.
I believe I’m currently using highlight.js with a customized theme however this does not give me enough flexibility with syntax highlighting. Here’s the link to my first post. I can’t assign colors to operators, functions, parantheses etc. Even though there are many classes defined in the highlist.css
When I look at Thomas’ website (link in the first post), virtually everything in the code chunk gets a different class (this is what I want):
If I understand it correctly, for that kind of customisation you need pygments? As in, maybe the R syntax in highight.js is a bit more limited than pygments? I’m willing to use either as long as it solves my problem
Sorry I can’t be of more help here, @ciflikli, but I think your best bet is to reach out to the theme’s maintainer and inquire about better syntax highlighting for highlight.js. The comparisons you’re making to other sites might also be a matter of CSS (i.e., the color scheme used for the highlighting).
As to whether pygments has been syntax highlighting, that’s far outside the scope of my understanding since pygments is a separate project (written in python; Hugo is Golang). I’ve used highlight.js on a few projects and think coverage is pretty extensive. The download page should give you an idea of what I mean.
@ciflikli if you want to mess around with pygments, you might use pygments-mathematica . I prefer to have highlighting done inline, without javascript, so I’ve geeked out on pygments a bit. If you don’t have a preference, I would probably go with highlight.js; learning pygments is very fun, but maybe not as fun as getting your site published.
@cifliki as a former jekyll user that still uses pygments I’d assume your purpose for using pygments is for backward compatibility on older posts that you don’t have time to edit for client-side code formatting. If that’s the case then maybe just skip the classes on those. I use prismjs on client-side for my more recent posts and it’s more powerful than highlightjs imo
Thanks, @rdwatters. I think it’s more of a pygments vs. highlight.js type of syntax highlighting preference. I used to think the flexibility that comes with pygments was important, but after digging around a bit, I think I’ll settle on highlight.js.