Fenced code block with language unsupported by Pygments


#1

Hello,

I have the pygmentsCodeFences set to true in my site config.toml.

And here is the example code block:

+++
title = "Org Source Block"
+++

```org
# Org comment
```

With that I get this HTML (simplified to highlight the issue) generated by Hugo:

<div class="post">
    <h1 class="post-title">Org Source Block</h1>
    # Org comment
</div>

If I remove that language identifier:

+++
title = "Org Source Block"
+++

```
# Org comment
```

, OR set pygmentsCodeFences to false, the HTML is:

<div class="post">
    <h1 class="post-title">Org Source Block</h1>
    <pre><code class="language-org"># Org comment
    </code></pre>
</div>

I believe this behavior is because org is not a supported Lexer by Pygments. But even in that case, can Hugo be fixed so that the HTML output is the latter of the above even with pygmentsCodeFences set to true. i.e. even if a language foo is not supported by Pygments, wrap the user-specified code block in:

    <pre><code class="language-foo">some foo code
    </code></pre>

#2

I suspect that the logic is:

– If language set, send through Pygments.
– Else, let Blackfriday handle it

As we cannot know in a simple way what languages Pygments support, the answer to your question is: Probably no.


#3

Can the pygments call’s return value be checked for an error or something? If error code is returned, pass

```
some foo code
```

to Blackfriday (remove the language descriptor following the backticks).


#4

Maybe, but you would have to raise an issue on GitHub. And probably investigate it yourself, cause I don’t have this problem.


#5

Done! https://github.com/gohugoio/hugo/issues/3783