lepture/mistune

Deep nested lists to html render trouble

ulanzetz opened this issue · 3 comments

I tried to render deep numbered md list to html and it start work incorrectly with 7 level of depth

Also result of v1 and v2 version lib is different

MD example

1. Foo0:
    1. Foo1
	2. Foo2:
        1. Foo3:
            1. Foo4:
                1. Foo5
                    1. Foo6
                        1. Foo7
                        2. Foo8

HTML on v3

<ol>
<li>Foo0:<ol>
<li>Foo1</li>
<li>Foo2:<ol>
<li>Foo3:<ol>
<li>Foo4:<ol>
<li>Foo5<ol>
<li>Foo6
 1. Foo7
 2. Foo8</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
image

HTML on v2

<ol>
<li>Foo0:<ol>
<li>Foo1</li>
<li>Foo2:<ol>
<li>Foo3:<ol>
<li>Foo4:<ol>
<li>Foo5<ol>
<li>Foo6<ol>
<li> 1. Foo7
 2. Foo8</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
</li>
</ol>
image

Is there a workaround to fix it?

There is a max_nested_level option for BlockParser, you can use a custom BlockParser with higher max_nested_level:

https://github.com/lepture/mistune/blob/master/src/mistune/block_parser.py#L94

For v2, you will need to subclass BlockParser, can change the LIST_MAX_DEPTH value:

https://github.com/lepture/mistune/blob/v2/mistune/block_parser.py#L88

@ulanzetz any feedback? I'll close this issue for now. If the above solutions can't fix your issue, please reopen it again.