flomei
December 26, 2018, 9:31pm
1
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?
Thanks!
zwbetz
December 26, 2018, 9:40pm
2
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
flomei
December 26, 2018, 9:44pm
3
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.
zwbetz
December 26, 2018, 9:47pm
4
How are you writing your code snippets?
If using code fences, you can specify the language:
```php
php code here
```
flomei
December 26, 2018, 10:20pm
5
I have tried that, and I have also tried:
{{< highlight php >}}
# code here...
{{< /highlight >}}
Both with no success.
zwbetz
December 26, 2018, 10:25pm
6
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.
zwbetz
December 26, 2018, 10:31pm
8
Link to a git repo would be best.
If you can’t do that, create a small sample project and link to that.
flomei
December 26, 2018, 10:37pm
9
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”.
zwbetz
December 26, 2018, 10:38pm
10
Depending on the syntax highlighting style you chose, it may not have a “color” for certain php keywords.
flomei
December 26, 2018, 10:41pm
11
Ah, my sample code is now perfectly highlighted, seems it was just the missing opening tag to identify the language.
zwbetz
December 26, 2018, 10:51pm
12
I mentioned that earlier but glad you got things worked out
flomei
December 26, 2018, 11:02pm
13
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