aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/extensions/attr_list.py8
-rw-r--r--markdown/extensions/headerid.py10
-rw-r--r--tests/test_extensions.py12
3 files changed, 20 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 = []
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index 315e7ef..b10414e 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -171,6 +171,18 @@ header_forceid: Off
self.assertEqual(markdown.markdown(text, ['headerid', 'meta']),
'<h2>A Header</h2>')
+ def testHeaderIdWithAttr_List(self):
+ """ Test HeaderIDs with Attr_List extension. """
+
+ text = '# Header1 {: #foo }\n# Header2 {: .bar }'
+ self.assertEqual(markdown.markdown(text, ['headerid', 'attr_list']),
+ '<h1 id="foo">Header1</h1>\n'
+ '<h1 class="bar" id="header2">Header2</h1>')
+ # Switch order extensions are loaded - should be no change in behavior.
+ self.assertEqual(markdown.markdown(text, ['attr_list', 'headerid']),
+ '<h1 id="foo">Header1</h1>\n'
+ '<h1 class="bar" id="header2">Header2</h1>')
+
class TestMetaData(unittest.TestCase):
""" Test MetaData extension. """