diff --git a/html4docx/h4d.py b/html4docx/h4d.py index 5184e16..0f03708 100644 --- a/html4docx/h4d.py +++ b/html4docx/h4d.py @@ -52,6 +52,7 @@ def set_initial_attrs(self, document=None): self.list_restart_counter = 0 self.current_ol_num_id = None self._list_num_ids = {} + self._ol_id_stack = [] # Stack to track parent ol IDs for nested lists # NEW: Set style map & tag overrides according to options @@ -1448,7 +1449,9 @@ def handle_starttag(self, tag, attrs): return elif tag in ['ol', 'ul']: if tag == 'ol': - # Assign new ID if it's a fresh top-level list + # Push current ID to stack before creating new one (for nested lists) + self._ol_id_stack.append(self.current_ol_num_id) + # Assign new ID for this