From 72087f37e7aeaeda5e60a7c931f4356ba75eaa54 Mon Sep 17 00:00:00 2001 From: Nasty Date: Thu, 12 Sep 2024 16:08:08 +0300 Subject: [PATCH] TLDR-809 fix docx numeration bug --- dedoc/readers/docx_reader/numbering_extractor.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dedoc/readers/docx_reader/numbering_extractor.py b/dedoc/readers/docx_reader/numbering_extractor.py index 4378adab..35b7e85d 100644 --- a/dedoc/readers/docx_reader/numbering_extractor.py +++ b/dedoc/readers/docx_reader/numbering_extractor.py @@ -104,6 +104,7 @@ def __get_list_item_text(self, ilvl: str, num_id: str) -> str: if abstract_num_id in self.state.prev_ilvl_dict: prev_ilvl = self.state.prev_ilvl_dict[abstract_num_id] + restarted = False # startOverride: if lvl_info.restart: if abstract_num_id in self.state.prev_num_id_dict: @@ -112,13 +113,15 @@ def __get_list_item_text(self, ilvl: str, num_id: str) -> str: prev_num_id = None if prev_num_id and prev_num_id != num_id: self.state.numerations_dict[(abstract_num_id, ilvl)] = lvl_info.start + restarted = True - # it's a new deeper level - if prev_ilvl < ilvl and lvl_info.lvl_restart or (abstract_num_id, ilvl) not in self.state.numerations_dict: - self.state.numerations_dict[(abstract_num_id, ilvl)] = lvl_info.start - # it's a continue of the old level (current level <= previous level) - else: - self.state.numerations_dict[(abstract_num_id, ilvl)] += 1 + if not restarted: + # it's a new deeper level + if prev_ilvl < ilvl and lvl_info.lvl_restart or (abstract_num_id, ilvl) not in self.state.numerations_dict: + self.state.numerations_dict[(abstract_num_id, ilvl)] = lvl_info.start + # it's a continue of the old level (current level <= previous level) + else: + self.state.numerations_dict[(abstract_num_id, ilvl)] += 1 # there isn't the information about this list else: