Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fenced code block with language unsupported by Pygments #3783

Closed
kaushalmodi opened this issue Aug 7, 2017 · 2 comments
Closed

Fenced code block with language unsupported by Pygments #3783

kaushalmodi opened this issue Aug 7, 2017 · 2 comments
Labels

Comments

@kaushalmodi
Copy link
Contributor

[Reference]


Hello,

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

And here is an example post in Markdown:

+++
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>

Note that "# Org comment" is not in a <code> block!

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>

Suggested solution

Can the pygmentize call's return value be checked for an error or something? If error code is returned, as a foo language is not supported by pygmentize, pass

```
some foo code
```

to Blackfriday (remove the language descriptor following the backticks), instead of:

```foo
some foo code
```

I don't know how to code in Go. So I would be grateful to anyone who can implement this. Thanks!

@kaushalmodi
Copy link
Contributor Author

Chroma syntax highlighting handles this gracefully..

```foo
some foo code
```

gets exported as below in HTML:

<div class="highlight"><pre class="chroma"><code class="language-foo" data-lang="foo">some foo code</code></pre>
</div>

So whoever ends up here in future, if you have the same issue, see if switching from Pygments to Chroma fixes it for you.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant