yuin / goldmark

:trophy: A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.
MIT License
3.68k stars 255 forks source link

5th level of nested list is treated as a code block #220

Closed johnphamvan closed 3 years ago

johnphamvan commented 3 years ago

Hello. I am try to represent deeply nested ordered lists with semantically correct ol which are especially important for accessibility. Unfortunately, I can see that Goldmark stops at the third level in list.go: https://github.com/yuin/goldmark/blob/75d8cce5b78c7e1d5d9c4ca32c1164f0a1e57b53/parser/list.go#L92

I have checked the spec and tested with dingus. There does not seem to be a limit to indentations on lists, and the spec states that:

If there is any ambiguity between an interpretation of indentation as a code block and as indicating that material belongs to a list item, the list item interpretation takes precedence:

Thanks in advance. ~John

  1. What version of goldmark are you using? : 1.3.5
  2. What version of Go are you using? : 1.16
  3. What operating system and processor architecture are you using? : MacOS Big Sur
  4. What did you do? Nested five levels of ordered lists.
  5. What did you expect to see? : Five levels of nested ordered lists.
  6. What did you see instead? : Four levels of nested ordered lists and a code block beyond that.
  7. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?: Yes. Here is the permalink to Dingus

Update Seems that the it only breaks when there is also an attribute block that goes with the nested list. Adding an attribute seems to break the next level of indented list if it is the last item in the list.

Example:

1. First level[^1]
    1. Indented ordered list
        1. I hope third levels aren't common
        2. In case they are though...
        3. Can I go a 4th level of bullets?
            1. 4th ok?
            2. Another 4th
            { .decimal }
                1. 5th? NOPE breaks.
                2. Also 5th. Shown in a code block.
                    1. How about 6th?
                { .lower-roman }
        { .lower-roman }
    2. The numbering should start over.
    3. This should be the second level of bullets.
    { .parens-lower-alpha }
1. Still first level[^2]
{ .decimal }

[^1]: This is the first footnote.
[^2]: This is the second footnote.

This, however, works without the attribute after the 4th level.

1. First level[^1]
    1. Indented ordered list
        1. I hope third levels aren't common
        2. In case they are though...
        3. Can I go a 4th level of bullets?
            1. 4th ok?
            2. Another 4th
                1. 5th? NOPE breaks.
                2. Also 5th. Shown in a code block.
                    1. How about 6th?
                    { .lower-roman }
        { .lower-roman }
    2. The numbering should start over.
    3. This should be the second level of bullets.
    { .parens-lower-alpha }
1. Still first level[^2]
{ .decimal }

[^1]: This is the first footnote.
[^2]: This is the second footnote.
johnphamvan commented 3 years ago

Nevermind. Posting the solution in hopes it helps someone in the future. The attribute for the block must appear after all the indented blocks and correctly align with the rest of the block.

Working example

1. First level[^1]
    1. Indented ordered list
        1. I hope third levels aren't common
        2. In case they are though...
        3. Can I go a 4th level of bullets?
            1. 4th ok?
            2. Another 4th
                1. 5th level.
                1. Also 5th. 
                    1. How about 6th?
                    { .parens-lower-roman }
                1. Picking up the 5th level
                { .upper-alpha }
            3. Third 4th level
            4. Fourth 4th level
            { .parens-decimal }
        { .lower-roman }
    2. The numbering should start over.
    3. This should be the second level of bullets.
    { .parens-lower-alpha }
1. Still first level[^2]
{ .decimal }