Preventing code block generation from indented `en.toml` entries

I couldn’t find anything in Goldmark or the Hugo docs on this. I’ll be the first to call out that this isn’t worth a lot of thought as you can fix it by just removing the indentation. We’ve been wondering since we keep having non-technical people indent text in our i18n/en.toml file without knowing it’ll display weirdly.

Questions

  1. When a user indents in the en.toml file, it causes that text to turn into a code block. What causes this, and how can we prevent it?
  2. Is there a config entry to globally prevent all code block generation?

Example entry so you can test locally

[markdownify_with_indentation_causing_code_block]
other = """
Text without an indent displays as expected

    But indented text gets turned into a code block

- same thing with list items
- same thing with list items
- same thing with list items

Let's indent some list items...

    - indented list items also get a code block
    1. indented list items also get a code block

But again, no indent means no code block
"""

Then in an HTML file put {{ i18n "markdownify_with_indentation_causing_code_block" | markdownify }}

You should see this:

@ju52 Thank you for sharing those links, I’m not seeing any references to my question in the three links. Could you please clarify?

Goldmark follows Commonmark Spec, that’s called Indented code blocks

https://spec.commonmark.org/0.30/#indented-code-blocks


Test Commonmark:

Test Commonmark


AFAIK, there is no option to disable this automatic indented code block conversion.

Ah, thank you.

I had not heard of commonmark. That is definitely the cause. I wonder if there is a Hugo way or a Goldmark way to disable syntax highlighting altogether.

Just to make sure we’re using the correct terminology, text indented with four or more spaces is an indented code block — there is no syntax highlighting. Syntax highlighting is achieved with fenced code blocks.

While you can disable syntax highlighting when using fenced code blocks, you cannot modify the rendering of indented code blocks.

1 Like

@jmooring thank you for clarifying the correct terminology, I’ve updated my post’s language to match.

While you can disable syntax highlighting when using fenced code blocks, you cannot modify the rendering of indented code blocks.

Darn, good to know. It kind of makes sense that a tool (and a spec) that’s built for developers would prioritize code block generation over flexibility content editors.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.