davidhampgonsalves / hugo-black-and-light-theme

A High contrast, text oriented, performant and Javascript-free theme for Hugo.
https://themes.gohugo.io/themes/hugo-black-and-light-theme/
GNU General Public License v3.0
189 stars 94 forks source link

syntax highlighting #14

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi, I was wondering if there is a method to change the syntax highlighting for code chunks (R and Python).

I'm using the Blogdown package and have been looking at some of the solutions that other people have tried with different themes, here and here.

However, Black & White does not follow the same file structure as the themes in these examples so I couldn't get them to work. Is there something else that I may not be aware of that I could try? (I'm not a developer so navigating this stuff is a bit confusing atm). Thanks for any help and for the theme.

cardi commented 5 years ago

I'm not familiar with Blogdown, but Hugo comes with syntax highlighting built-in. Additionally, this particular theme doesn't override or prevent syntax highlighting.

In your config.toml, add the following lines (I'm using Hugo 0.50):

pygmentsUseClassic = false
pygmentsCodeFences = true
pygmentsStyle      = "colorful"

(a full list of built-in styles is here)

Then, in the .md file of your choice, try adding the following snippet and generating your site:

```python
#!/usr/bin/python3

from engine import RunForrestRun

"""Test code for syntax highlighting!"""

class Foo:
  def __init__(self, var):
    self.var = var
    self.run()

  def run(self):
    RunForrestRun()  # run along!
```

The resulting .html file should have colorized output.

davidhampgonsalves commented 5 years ago

thanks @cardi for this explanation.