aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2011-08-04 14:05:31 -0400
committerWaylan Limberg <waylan@gmail.com>2011-08-04 14:05:31 -0400
commit4cabf3b94c17317b16d82e143e8221c88ff60d99 (patch)
treefff5086d391fe3ff89593d4eb02e5be2a3ea0223
parent596492baa23623411d143186d9cad33a1305cd24 (diff)
downloadmarkdown-4cabf3b94c17317b16d82e143e8221c88ff60d99.tar.gz
markdown-4cabf3b94c17317b16d82e143e8221c88ff60d99.tar.bz2
markdown-4cabf3b94c17317b16d82e143e8221c88ff60d99.zip
TOC extension now attaches toc to Markdown instance (Markdown.toc), but only if a marker was not found in the document.
-rw-r--r--markdown/extensions/toc.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py
index 2fa5ce1..1f1de15 100644
--- a/markdown/extensions/toc.py
+++ b/markdown/extensions/toc.py
@@ -23,6 +23,8 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
yield parent, child
def run(self, doc):
+ marker_found = False
+
div = etree.Element("div")
div.attrib["class"] = "toc"
last_li = None
@@ -61,6 +63,7 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
if p[i] == c:
p[i] = div
break
+ marker_found = True
if header_rgx.match(c.tag):
tag_level = int(c.tag[-1])
@@ -106,6 +109,14 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
c.append(anchor)
list_stack[-1].append(last_li)
+ if not marker_found:
+ # searialize and attach to markdown instance.
+ prettify = self.markdown.treeprocessors.get('prettify')
+ if prettify: prettify.run(div)
+ toc = self.markdown.serializer(div)
+ for pp in self.markdown.postprocessors.values():
+ toc = pp.run(toc)
+ self.markdown.toc = toc
class TocExtension(markdown.Extension):
def __init__(self, configs):