diff options
-rw-r--r-- | markdown/extensions/headerid.py | 4 | ||||
-rw-r--r-- | markdown/extensions/toc.py | 2 | ||||
-rw-r--r-- | tests/test_extensions.py | 7 |
3 files changed, 10 insertions, 3 deletions
diff --git a/markdown/extensions/headerid.py b/markdown/extensions/headerid.py index b6a12e8..cf3df17 100644 --- a/markdown/extensions/headerid.py +++ b/markdown/extensions/headerid.py @@ -101,7 +101,7 @@ def unique(id, ids): id = '%s_%d'% (m.group(1), int(m.group(2))+1) else: id = '%s_%d'% (id, 1) - ids.append(id) + ids.add(id) return id @@ -191,7 +191,7 @@ class HeaderIdExtension (markdown.Extension): md.treeprocessors.add('headerid', self.processor, '>prettify') def reset(self): - self.processor.IDs = [] + self.processor.IDs = set() def makeExtension(configs=None): diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py index 7edc0cc..1d6639e 100644 --- a/markdown/extensions/toc.py +++ b/markdown/extensions/toc.py @@ -127,7 +127,7 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor): self.use_anchors = self.config["anchorlink"] in [1, '1', True, 'True', 'true'] # Get a list of id attributes - used_ids = [] + used_ids = set() for c in doc.getiterator(): if "id" in c.attrib: used_ids.append(c.attrib["id"]) diff --git a/tests/test_extensions.py b/tests/test_extensions.py index fa9a801..d9d77b8 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -199,6 +199,13 @@ class TestHeaderId(unittest.TestCase): self.assertEqual(self.md.convert(text), '<h1 id="some-header">Some Header</h1>') + def testUniqueFunc(self): + """ Test 'unique' function. """ + from markdown.extensions.headerid import unique + ids = set(['foo']) + self.assertEqual(unique('foo', ids), 'foo_1') + self.assertEqual(ids, set(['foo', 'foo_1'])) + def testUniqueIds(self): """ Test Unique IDs. """ |