Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate entries in TOC when using mixed headers #539

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading