HUGO

Blackfriday not handling lists and code blocks the right way

I’m using the binary from github,

Hugo Static Site Generator v0.56.3-F637A1EA/extended linux/amd64
BuildDate: 2019-07-31T12:54:46Z

I still getting problems with blackfriday not handling lists and code blocks the right way

take this code

* Some Content

    * ```
    code 1
    ```

# Title

Some Content

It is related to this issue https://github.com/gohugoio/hugo/issues/6040

please read

https://daringfireball.net/projects/markdown/syntax#precode

until version 0.55.4 everything was fine.

but, I did some tests here, the only way to make code blocks and lists work together in the current version 0.56.3 is:

On the first level in a list, the first code block in the the topic shall use 8 spaces:

  * Some Content

          content

The subsequent levels, the first code block in the topic only needs 8 spaces + (4 spaces * preview level):

  * First level
          
          code

      * Second level

              code

The first code block in a list topic shall not use the triple Grave Accent syntax. It Shall use only spaces. The subsequent code block in the same level, without a content in between shall use use grave accent syntax:

  * First level
          
          code

      ```c
      code
      ```

The thing is, when using code highlight and different programming languages, how to achieve using spaces indentation?

I write lists

- <pre>ATOM: 90.934 Bytes = 100%</pre>
- <pre>JSON: 78.218 Bytes =  86%</pre>

and code

<pre><code>
[outputFormats.ATOM]
MediaType             = "application/atom+xml"
BaseName              = "feed"
suffix                = "xml"
IsHTML                = false
IsPlainText           = false
noUgly                = true
Rel                   = "alternate"<br/> 
[outputFormats.JSON]
MediaType             = "application/json"
BaseName              = "feed"
suffix                = "json"
IsHTML                = false
IsPlainText           = true
noUgly                = false
Rel                   = "alternate"<br/> 
[outputs]
home                  = [ "HTML", "ATOM", "JSON"]
section               = [ "HTML",  ]
page                  = [ "HTML" ]
taxonomy              = [ "HTML" ]
taxonomyTerm          = [ "HTML" ]
</pre></code>

Mixing html with markdown is not an option for me. Content, only markdown.

What are you trying to do in that Markdown snippet? Do you want the code block to be simply in that first bullet? In that case, why is there an * before ```?


As an aside, I use - instead of * for lists. So I’m not sure if Blackfriday is buggy when using * as plain list markers.

From that referenced issue, when I last tested, this rendered fine after the fix:

-   list item 1
    ```md
    *hello*
    ```
-   list item 2
1 Like

* and - does not matter, works fine and are part of the default markdown syntax, and 0.55.4 is the only one doing fine until now.

the problem with - is that, if your file start with a list, and your list use - symbol, hugo will throw an error invalid YAML delimiter, because is expecting a front-matter.

I’m on my phone so unable to test for myself. But as an example, this would throw that error?

---
title: Some Page
---

- eggs
- bacon
- grits

no, that’s fine, but if the file does not have a front-mater, only have the code bellow, hugo goes wild:

- eggs
- bacon
- grits

I thought content needed at least empty front matter like

---
---

I really don’t know what is the expected behavior in hugo, its a feature, a bug, or nobody knows in this case, but a file starting with only:

* item 1
* item 2
* item 3

It render fine.

Hmm, honestly, I haven’t yet come across a need to not have any front-matter. @bep is the best person to answer this.

Regarding your original question, this Markdown renders to this HTML, with the list item and code block placements as expected, using the latest Hugo 0.57-DEV (built post 0.56.3 release).

I setup the version Hugo Static Site Generator v0.57.0-DEV linux/amd64 BuildDate: unknown to test locally. Your example worked fine. I pushed some more combinations and was able to break the thing

in 0.55.4, if you have a code like this:

  - level 1
      ```md
      code
      ```

       - ```md
      code 2
      ```

 # title

In the second level, 4 spaces before - and 4 spaces before code 2 and before the 3 grave accent, this does not break the parser loop, and the title is processed and stay in the right indentation, but on 0.57.0-DEV, the behavior is different, it break the hole thing, the parser goes wild, and everything after that is messed up.

To make it to work fine in 0.57.0-DEV, in the level 2 you have to add 8 spaces before code 2 and before the 3 grave accent, for 0.55.4, 4 or 8 spaces does not matter for the first code block in the second level:

  - level 1
      ```md
      code
      ```

       - ```md
          code 2
          ```

 # title

but on the second matter.

  - level 1
      ```md
      code
      ```

       - ```md
          code 2
          ```

          ```md
          code 2
          ```

 # title

The thing is, I don’t know if there was some kind of safeguard on 0.55.4, where the intention was that the hole thing does not break, and was removed on 0.57.0-DEV, or finally the expected behavior is working…

Hmm, I have always kept the beginnning ``` and ending ``` at the same indentation level, so never had this issue. Your question might be for the BlackFriday team… though, does it make sense to have the beginning and ending ``` at different indentations?

makes sense, but I really don’t know why on hugo 0.55.4 was working fine, and in 0.57.0-DEV the behavior changed, is blackfriday version different?

Because the list handling code in Blackfriday got more robust inbetween:

1 Like