diff options
author | Waylan Limberg <waylan@gmail.com> | 2009-07-21 20:56:49 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2009-07-21 20:56:49 -0400 |
commit | 93dddf9eb7b3263beda332e79ee84cf8ab9c13bb (patch) | |
tree | 2fa660b1e9c7eaaa6e47410d1e7cc080535970c4 /markdown/extensions | |
parent | c38f1813a1c2d7c531517a74c456166af92356b4 (diff) | |
download | markdown-93dddf9eb7b3263beda332e79ee84cf8ab9c13bb.tar.gz markdown-93dddf9eb7b3263beda332e79ee84cf8ab9c13bb.tar.bz2 markdown-93dddf9eb7b3263beda332e79ee84cf8ab9c13bb.zip |
Fixed TOC extension to properly nest multiple header levels in the table of contents. Specificly, when stepping back multiple levels, the nestsed listed now follow suite. Test included. Thanks for the patch Jack Miller.
Diffstat (limited to 'markdown/extensions')
-rw-r--r-- | markdown/extensions/toc.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 1624ccf..1d9489c 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -60,13 +60,9 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor): if header_rgx.match(c.tag): tag_level = int(c.tag[-1]) - # Regardless of how many levels we jumped - # only one list should be created, since - # empty lists containing lists are illegal. - - if tag_level < level: + while tag_level < level: list_stack.pop() - level = tag_level + level -= 1 if tag_level > level: newlist = etree.Element("ul") @@ -75,7 +71,7 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor): else: list_stack[-1].append(newlist) list_stack.append(newlist) - level = tag_level + level += 1 # Do not override pre-existing ids if not "id" in c.attrib: |