lepture/mistune

"max-level" option MUST be <= 3

jet10000 opened this issue · 3 comments

        md = mistune.create_markdown(
            plugins=[
                RSTDirective([
                    TableOfContents(),
                ]),
            ]
        )
        add_toc_hook(md=md, min_level=1, max_level=6, heading_id=None)

How to set it?

Your code works well. Here is my demo:

import mistune
from mistune.toc import add_toc_hook, render_toc_ul
from mistune.directives import RSTDirective, TableOfContents

md = mistune.create_markdown(
    plugins=[
	RSTDirective([
	    TableOfContents(),
	]),
    ]
)
add_toc_hook(md=md, min_level=1, max_level=6, heading_id=None)

text = """
# h1

## h2

### h3

#### h4

##### h5

###### h6
"""

html, state = md.parse(text)
toc_items = state.env['toc_items']
toc_html = render_toc_ul(toc_items)

print(toc_html)

And the result is:

<ul>
<li><a href="#toc_1">h1</a>
<ul>
<li><a href="#toc_2">h2</a>
<ul>
<li><a href="#toc_3">h3</a>
<ul>
<li><a href="#toc_4">h4</a>
<ul>
<li><a href="#toc_5">h5</a>
<ul>
<li><a href="#toc_6">h6</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
image image

It works

image