aboutsummaryrefslogtreecommitdiffstats
path: root/markdown
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2012-12-13 14:47:34 -0500
committerWaylan Limberg <waylan@gmail.com>2012-12-13 14:47:34 -0500
commitf52d62656705841316d1d653644d874b4db9ff37 (patch)
tree01a77f09db092848ab91b76e2230aafd01e8e8d7 /markdown
parenta8e06b7cef5c5b0b372b9a0db0f56c4e7094e2bd (diff)
downloadmarkdown-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')
-rw-r--r--markdown/extensions/attr_list.py8
-rw-r--r--markdown/extensions/headerid.py10
2 files changed, 8 insertions, 10 deletions
diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py
index 36f3e3a..8734e9f 100644
--- a/markdown/extensions/attr_list.py
+++ b/markdown/extensions/attr_list.py
@@ -74,7 +74,6 @@ class AttrListTreeprocessor(markdown.treeprocessors.Treeprocessor):
def run(self, doc):
for elem in doc.getiterator():
- #import pdb; pdb.set_trace()
if isBlockLevel(elem.tag):
# Block level: check for attrs on last line of text
RE = self.BLOCK_RE
@@ -131,12 +130,7 @@ class AttrListTreeprocessor(markdown.treeprocessors.Treeprocessor):
class AttrListExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
- if 'headerid' in md.treeprocessors.keys():
- # insert after 'headerid' treeprocessor
- md.treeprocessors.add('attr_list', AttrListTreeprocessor(md), '>headerid')
- else:
- # insert after 'inline' treeprocessor
- md.treeprocessors.add('attr_list', AttrListTreeprocessor(md), '>inline')
+ md.treeprocessors.add('attr_list', AttrListTreeprocessor(md), '>inline')
def makeExtension(configs={}):
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 = []