Having the TOC also include HTML headings <h> #7707
-
Basically i've been having issues with the TOC as when creating headings that use HTML instead of the usual markdown annotations like in ## Heading What i use <h3 id="weapon-file"">Weapon File</h3> They're excluded from the table of contents I've seen a few simmilar discussions on the same topic, but i haven't been able to reproduce the contrary expected result, like in: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
This is a limitation of Python Markdown, which MkDocs uses (our upstream dependency) to render Markdown. You can see that this is not related to Material for MkDocs by using another theme – same result. I think this is a deliberate design decision. In any case, please take this upstream. |
Beta Was this translation helpful? Give feedback.
-
I think there is an important misunderstanding being made. Yes, this is a limitation in Python Markdown, but you can force raw HTML headers to be included in the TOC by using Normally, HTML is taken out and handled differently. But if you use import markdown
import pymdownx
print(f'Pymdown Extensions Version: {pymdownx.__version__}')
print(f'Markdown Version: {markdown.__version__}')
print('-----')
MD = """
[TOC]
## Test 1
<h2 markdown>Test 2</h2>
"""
extensions = ["toc", "md_in_html"]
extension_configs = {}
print(markdown.markdown(MD, extensions=extensions, extension_configs=extension_configs)) <div class="toc">
<ul>
<li><a href="#test-1">Test 1</a></li>
<li><a href="#test-2">Test 2</a></li>
</ul>
</div>
<h2 id="test-1">Test 1</h2>
<h2 id="test-2">Test 2</h2> Are there cases where this may not always work? Maybe, but generally, at root level, this should work. |
Beta Was this translation helpful? Give feedback.
Well, you are not using
md_in_html
correctly.Let me explain how this works. Python Markdown does not process block HTML unless it has a
markdown
attribute.So you want to process an
<h3>
inside a<div>
? You need to ensure the parent elements also allow markdown processing.