diff options
author | Waylan Limberg <waylan@gmail.com> | 2012-12-13 14:47:34 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2012-12-13 14:47:34 -0500 |
commit | f52d62656705841316d1d653644d874b4db9ff37 (patch) | |
tree | 01a77f09db092848ab91b76e2230aafd01e8e8d7 /markdown/extensions/headerid.py | |
parent | a8e06b7cef5c5b0b372b9a0db0f56c4e7094e2bd (diff) | |
download | markdown-f52d62656705841316d1d653644d874b4db9ff37.tar.gz markdown-f52d62656705841316d1d653644d874b4db9ff37.tar.bz2 markdown-f52d62656705841316d1d653644d874b4db9ff37.zip |
Fixed #165. Switched the order of treeprocessors when attr_list and headerid extensions are used togeather. While this means headerid may alter IDs defined in attr_lists for uniqueness, automaticaly generated ids will not contain unparsed attr_lists. This is the lesser of two evils - and actually generates a more valid output (all IDs will be unique)
Diffstat (limited to 'markdown/extensions/headerid.py')
-rw-r--r-- | markdown/extensions/headerid.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/markdown/extensions/headerid.py b/markdown/extensions/headerid.py index 2d18c15..1d158f9 100644 --- a/markdown/extensions/headerid.py +++ b/markdown/extensions/headerid.py @@ -133,7 +133,7 @@ class HeaderIdTreeprocessor(markdown.treeprocessors.Treeprocessor): if elem.tag in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']: if force_id: if "id" in elem.attrib: - id = elem.id + id = elem.get('id') else: id = slugify(u''.join(itertext(elem)), sep) elem.set('id', unique(id, self.IDs)) @@ -183,8 +183,12 @@ class HeaderIdExtension (markdown.Extension): self.processor = HeaderIdTreeprocessor() self.processor.md = md self.processor.config = self.getConfigs() - # Replace existing hasheader in place. - md.treeprocessors.add('headerid', self.processor, '>inline') + if 'attr_list' in md.treeprocessors.keys(): + # insert after attr_list treeprocessor + md.treeprocessors.add('headerid', self.processor, '>attr_list') + else: + # insert after 'inline' treeprocessor. + md.treeprocessors.add('headerid', self.processor, '>inline') def reset(self): self.processor.IDs = [] |