Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hugo + Pygments—How to change highlighting theme?

Tags:

pygments

hugo

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?

like image 995
Mirror318 Avatar asked Aug 08 '16 04:08

Mirror318


People also ask

How do I enable syntax highlighting in Notepad ++?

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++.

What is the use of syntax highlighting?

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.

What is syntax highlighting Tumblr?

Syntax highlighting allows code in posts to be highlighted based on the language it's written in, to make it easier to read.


Video Answer


1 Answers

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">
like image 103
Mirror318 Avatar answered Sep 23 '22 14:09

Mirror318