diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2014-12-30 11:00:27 -0500 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2014-12-30 11:12:56 -0500 |
commit | 52b9f8c1ea191ce9c1ae0cd485306460cb52f71b (patch) | |
tree | df18aad433a4f171c12f76c3876c262818498857 /markdown/extensions/toc.py | |
parent | 257c0fe9aad40879ebe9b6e84613d5c3a5adf2b5 (diff) | |
download | markdown-52b9f8c1ea191ce9c1ae0cd485306460cb52f71b.tar.gz markdown-52b9f8c1ea191ce9c1ae0cd485306460cb52f71b.tar.bz2 markdown-52b9f8c1ea191ce9c1ae0cd485306460cb52f71b.zip |
Add reset support to TOC extension.
Now, whenever the TOC extensiuon is loaded, the Markdown class instance
will always have a toc attribute (md.toc). Calling md.reset() will also
reset the toc attribute which defaults to an empty string.
Diffstat (limited to 'markdown/extensions/toc.py')
-rw-r--r-- | markdown/extensions/toc.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 99542ed..db6659c 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -234,6 +234,9 @@ class TocExtension(Extension): super(TocExtension, self).__init__(*args, **kwargs) def extendMarkdown(self, md, md_globals): + md.registerExtension(self) + self.md = md + self.reset() tocext = self.TreeProcessorClass(md) tocext.config = self.getConfigs() # Headerid ext is set to '>prettify'. With this set to '_end', @@ -243,6 +246,9 @@ class TocExtension(Extension): # to redefine ids after toc is created. But we do want toc prettified. md.treeprocessors.add("toc", tocext, "_end") + def reset(self): + self.md.toc = '' + def makeExtension(*args, **kwargs): return TocExtension(*args, **kwargs) |