Bug with rendering of specific YAML snippets in code fences

I have a list with nested code fences like this:

1. First item

    ```yaml
    ports:
      foo: bar
    ```

2. Second item

    ```yaml
    ports:
    - port: 80
    ```

3. Third item

Both code fences are indented by 4 spaces. The first YAML block under “First item” renders just fine, however the one under “Second item” doesn’t, and just prints the raw code fence syntax (picture below). I was able to determine that it’s happening when the code block contains an array like above.

This is a known Blackfriday bug:

It would be awesome if someone with Go skills can fix it.

I use the below hack with the assumption that no one will copy-paste stuff directly from that code block:

  1. If a code block is in a list, and
  2. If a line in that code block begins with the regular dash (HYPHEN-MINUS) character or a PLUS SIGN (0x2b), replace that character with the HYPHEN character (which looks like HYPHEN-MINUS, but has a different binary code… 0x2010 instead of 0x2d). That is enough to fool Blackfriday to get around this bug.

Test page

  • Test page (That page has a link to the Markdown source too.)

Thanks for pointing this out, I’ll follow up on Blackfriday repo.

I’m not sure if your recommendation would work if it’s replacing the character in the output. Since these are for code blocks, ideally the characters typed in the code block should be rendered as-is.

Of course, in an ideal world… As Blackfriday has unideally left this bug unfixed for more than 2 years, I didn’t have a choice but bake in this hack in my ox-hugo package. I keep my blog sources in Org mode, and then ox-hugo does those hyphen replacements at the right places, when exporting Org to Markdown.