From 71a7afdb7ad33a8d000fa3ff067c9607bcfb00db Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 3 Dec 2023 17:51:37 +0000 Subject: [PATCH 1/2] Add mechanism to prevent header ID counter resetting --- lib/markdown2.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/markdown2.py b/lib/markdown2.py index 479663b0..4c13500c 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 = {} From 0b81aa30a385b410fa3f64dc0e6414f3beae2e9a Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sun, 3 Dec 2023 17:58:31 +0000 Subject: [PATCH 2/2] Update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) 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