Skip to content

Commit

Permalink
Merge pull request #539 from Crozzers/fix-duplicate-toc-entries
Browse files Browse the repository at this point in the history
Fix duplicate entries in TOC when using mixed headers
  • Loading branch information
nicholasserra committed Dec 3, 2023
2 parents efd824f + 53bfe0b commit 6d19f3f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/markdown2.py
Expand Up @@ -1811,7 +1811,7 @@ def _header_id_exists(self, text):
prefix = self.extras['header-ids'].get('prefix')
if prefix and isinstance(prefix, str):
header_id = prefix + '-' + header_id
return header_id in self._count_from_header_id
return header_id in self._count_from_header_id or header_id in map(lambda x: x[1], self._toc)

def _toc_add_entry(self, level, id, name):
if level > self._toc_depth:
Expand Down
5 changes: 5 additions & 0 deletions test/tm-cases/toc_duplicate_entries.html
@@ -0,0 +1,5 @@
<h1 id="abc">abc</h1>

<h1 id="abc-2">abc</h1>

<h1 id="abc-3">abc</h1>
6 changes: 6 additions & 0 deletions test/tm-cases/toc_duplicate_entries.opts
@@ -0,0 +1,6 @@
{
"extras": {
"toc": {"depth": 3},
"header-ids": {"mixed": True}
}
}
3 changes: 3 additions & 0 deletions test/tm-cases/toc_duplicate_entries.text
@@ -0,0 +1,3 @@
# abc
# abc
# abc
5 changes: 5 additions & 0 deletions test/tm-cases/toc_duplicate_entries.toc_html
@@ -0,0 +1,5 @@
<ul>
<li><a href="#abc">abc</a></li>
<li><a href="#abc-2">abc</a></li>
<li><a href="#abc-3">abc</a></li>
</ul>

0 comments on commit 6d19f3f

Please sign in to comment.