gohugo-theme-ananke icon indicating copy to clipboard operation
gohugo-theme-ananke copied to clipboard

Syntax highlight not working

Open bilotAIcore opened this issue 5 years ago • 3 comments

I'm trying to get syntax (r/python) to be highlighted properly in Rmarkdown posts but sofar had 0 luck. For example, changing the pygments options only seem to affect code blocks in .md files. I would apreciate a guide on what to alter in the site source codes to make this work.

Thanks.

bilotAIcore avatar Oct 01 '19 10:10 bilotAIcore

Would you post an example of the code so we can investigate?

susodapop avatar Oct 01 '19 19:10 susodapop

I'm seeing the same thing. For example, I've put this into my post markdown:

```csharp
[Route("api/v2/products/{productName}/groups/{groupName}/features")]
public class FeatureV2Controller
{
    ...
    [Route("{title}/versions/{version}")]
    [HttpPost]
    public async Task<ActionResult<Feature>> PostAsync(Feature feature, string productName, string groupName, string title, string version)
    {
        if (!feature.Title.Equals(title, StringComparison.OrdinalIgnoreCase))
        ...
    }
    ...
}

And it renders like this:

Screenshot 2019-11-13 15 29 07

As you can see it's just white text on a black background, but no highlighting of keywords or anything. Am I missing something?

jmezach avatar Nov 13 '19 14:11 jmezach

I managed to fix this:

$ hugo version
Hugo Static Site Generator v0.63.1-CE9ACEB7/extended linux/amd64 BuildDate: 2020-01-23T20:15:47Z
  1. Generate syntax CSS style:
    hugo gen chromastyles --style=monokai > static/css/syntax-monokai.css
    
  2. Enable syntax CSS and highlight settings in config:
    markup:
      highlight:
        codeFences: true
        guessSyntax: false
        hl_Lines: ""
        lineNoStart: 1
        lineNos: false
        lineNumbersInTable: true
        noClasses: false
        style: monokai  # looks like this has no effect, only imported CSS matters
        tabWidth: 4
    
    params:
      ...
      custom_css:
        - css/custom.css
        - css/syntax-monokai.css
    

Then my site properly highlight code which is just placed between "```" blocks.

References:

  • https://gohugo.io/content-management/syntax-highlighting/#generate-syntax-highlighter-css
  • https://gohugo.io/getting-started/configuration-markup#highlight

agrrh avatar Jan 24 '20 13:01 agrrh