Skip to content

Commit

Permalink
Merge pull request #540 from Crozzers/prevent-header-id-counter-reset
Browse files Browse the repository at this point in the history
Add mechanism to prevent header ID counter resetting (issue #530)
  • Loading branch information
nicholasserra committed Dec 3, 2023
2 parents 6d19f3f + 0b81aa3 commit b123d68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -9,6 +9,7 @@
- [pull #535] Update `_slugify` to use utf-8 encoding (issue #534)
- [pull #536] Maintain order of appearance in footnotes
- [pull #538] Include HTML headers in TOC
- [pull #540] Add mechanism to prevent header ID counter resetting (issue #530)

## python-markdown2 2.4.10

Expand Down
6 changes: 4 additions & 2 deletions lib/markdown2.py
Expand Up @@ -244,7 +244,8 @@ def __init__(self, html4tags=False, tab_width=4, safe_mode=None,
if not isinstance(self.extras['header-ids'], dict):
self.extras['header-ids'] = {
'mixed': False,
'prefix': self.extras['header-ids']
'prefix': self.extras['header-ids'],
'reset-count': True
}

if 'break-on-newline' in self.extras:
Expand Down Expand Up @@ -292,7 +293,8 @@ def _setup_extras(self):
self.footnotes = OrderedDict()
self.footnote_ids = []
if "header-ids" in self.extras:
self._count_from_header_id = defaultdict(int)
if not hasattr(self, '_count_from_header_id') or self.extras['header-ids'].get('reset-count', False):
self._count_from_header_id = defaultdict(int)
if "metadata" in self.extras:
self.metadata = {}

Expand Down

0 comments on commit b123d68

Please sign in to comment.