Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _toc_depth initialization: #311 #312

Merged
merged 1 commit into from Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/markdown2.py
Expand Up @@ -236,8 +236,11 @@ def __init__(self, html4tags=False, tab_width=4, safe_mode=None,
extras = dict([(e, None) for e in extras])
self.extras.update(extras)
assert isinstance(self.extras, dict)
if "toc" in self.extras and "header-ids" not in self.extras:
self.extras["header-ids"] = None # "toc" implies "header-ids"

if "toc" in self.extras:
if "header-ids" not in self.extras:
self.extras["header-ids"] = None # "toc" implies "header-ids"

if self.extras["toc"] is None:
self._toc_depth = 6
else:
Expand Down
13 changes: 13 additions & 0 deletions test/tm-cases/toc_5.html
@@ -0,0 +1,13 @@
<h1 id="fruit">Fruit</h1>

<ul>
<li>apples</li>
<li>bananas</li>
</ul>

<h1 id="veggies">Veggies</h1>

<ul>
<li>carrots</li>
<li>lettuce</li>
</ul>
1 change: 1 addition & 0 deletions test/tm-cases/toc_5.opts
@@ -0,0 +1 @@
{"extras": ["toc", "header-ids"]}
1 change: 1 addition & 0 deletions test/tm-cases/toc_5.tags
@@ -0,0 +1 @@
toc extra
10 changes: 10 additions & 0 deletions test/tm-cases/toc_5.text
@@ -0,0 +1,10 @@
# Fruit

- apples
- bananas

# Veggies

- carrots
- lettuce

4 changes: 4 additions & 0 deletions test/tm-cases/toc_5.toc_html
@@ -0,0 +1,4 @@
<ul>
<li><a href="#fruit">Fruit</a></li>
<li><a href="#veggies">Veggies</a></li>
</ul>