Skip to content

Commit

Permalink
Merge pull request #312 from thombashi/fix_toc_depth_init_311
Browse files Browse the repository at this point in the history
Fix _toc_depth initialization: #311
  • Loading branch information
nicholasserra committed Oct 15, 2018
2 parents db84b92 + 4004122 commit 9d5111a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
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>

0 comments on commit 9d5111a

Please sign in to comment.