No classes added to syntax highlighting

Hey!
I enabled syntax highlighting in my Hugo with a config.toml like this:

pygmentscodefences = true
pygmentscodefencesguesssyntax = true
pygmentsoptions = "linenos=table"
pygmentsstyle = "lovelace"
pygmentsuseclasses = true
pygmentsuseclassic = false

I have generated the “lovelace” CSS and added it to my custom.css which gets loaded by the theme.

I tried using the three backticks and also the highlight shortcode, but either way, no classes except the enclosing code-tag are generated for the code block.

Am I missing something?

Bildschirmfoto%20von%202018-12-26%2022-30-45

Thanks!

Assuming you want to use chroma for syntax highlighting, only these lines are needed:

pygmentsCodefences = true
pygmentsCodefencesGuessSyntax = true
pygmentsStyle = "lovelace"

The lovelace styles are automatically applied per the above. No need to generate the stylesheet, unless you prefer to do it that way.

1 Like

Thank you very much, I stripped the unnecessary lines and removed the CSS, but that didn’t change anything.

There are still no other classes added to the markup.

How are you writing your code snippets?

If using code fences, you can specify the language:

```php
php code here
```

I have tried that, and I have also tried:

{{< highlight php >}}

   # code here...

{{< /highlight >}}

Both with no success.

If you share your site code, I’ll help you troubleshoot further.


Keep in mind that it matters where you put those lines in your config.toml. Make sure they are above any tables/maps.

What do you need? :slight_smile:

Link to a git repo would be best.
If you can’t do that, create a small sample project and link to that.

Hm, tried something else. Seems like Chroma needs an opening PHP tag to correctly format it.

This works:

```php
<?php

# code...

Not sure if this is default behavior, I thought I could leave the tags out when I define the language in the markdown-code-“tag”.

Depending on the syntax highlighting style you chose, it may not have a “color” for certain php keywords.

Ah, my sample code is now perfectly highlighted, seems it was just the missing opening tag to identify the language.

I mentioned that earlier :slight_smile: but glad you got things worked out

Yeah, I did that. But you need fences + the opening php tag for Chroma to correctly identify the language.

It would be great if you could open a feature request with Chroma. It looks like two previous Chroma issues (#80 and #93) touched on this, but the solutions didn’t address this particular problem.

1 Like

Did that. Thanks!

1 Like