diff --git a/CHANGES.md b/CHANGES.md index 4bc9e41b..87aadce7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/lib/markdown2.py b/lib/markdown2.py index 245197f8..368b0954 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -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: @@ -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 = {}