Using Pygments with Hugo, I can do syntax highlighting with blocks like this:
```ruby
def hello object
puts "Hello, #{object}"
end
```
This "works" in that the code is colored, but the colors aren't good, with white text (from Pygments) on white background (from Hugo theme). Is there a way to change the theme of the highlighting?
The Syntax Highlighter is short and easily modified by going to Language > Define your language and selecting choicescript in the User language menu at the top of the new window. This will cover editing the syntax highlighter in Notepad++.
Syntax highlighting is one strategy to improve the readability and context of the text; especially for code that spans several pages. The reader can easily ignore large sections of comments or code, depending on what they are looking for. Syntax highlighting also helps programmers find errors in their program.
Syntax highlighting allows code in posts to be highlighted based on the language it's written in, to make it easier to read.
In /config.toml
you need these lines:
PygmentsCodeFences = true
PygmentsStyle = "monokai"
For a list of styles, https://help.farbox.com/pygments.html is a good source. I think there are more, but I haven't found a comprehensive list yet.
For the background of code blocks, actually this is set by the Hugo theme, for the Hyde theme I was using I needed to override the css like this:
/themes/hyde/static/css/override.css
pre {
background-color: #23241f;
}
code {
background-color: #EEE
}
And add the ref link to /themes/hyde/layouts/partials/head.html
<link rel="stylesheet" href="{{ .Site.BaseURL }}css/override.css">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With