Skip to content

Commit

Permalink
Fix duplicate entries in TOC when using mixed headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Crozzers committed Dec 3, 2023
1 parent efd824f commit 53bfe0b
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# abc
# abc
# abc
5 changes: 5 additions & 0 deletions test/tm-cases/toc_duplicate_entries.toc_html
Original file line number Diff line number Diff line change
@@ -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 53bfe0b

Please sign in to comment.