From 70e02c723496d32196dd0323258fb2270d38bbed Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 3 Aug 2025 07:59:33 +0100 Subject: Ignore style definitions using a style ID that has already been used --- mammoth/docx/styles_xml.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'mammoth') diff --git a/mammoth/docx/styles_xml.py b/mammoth/docx/styles_xml.py index 0b3f39d..3178553 100644 --- a/mammoth/docx/styles_xml.py +++ b/mammoth/docx/styles_xml.py @@ -67,7 +67,18 @@ def read_styles_xml_element(element): style = _read_style_element(style_element) style_set = styles.get(element_type) - if style_set is not None: + + # Per 17.7.4.17 style (Style Definition) of ECMA-376 4th edition Part 1: + # + # > If multiple style definitions each declare the same value for their + # > styleId, then the first such instance shall keep its current + # > identifier with all other instances being reassigned in any manner + # > desired. + # + # For the purpose of conversion, there's no point holding onto styles + # with reassigned style IDs, so we ignore such style definitions. + + if style_set is not None and style.style_id not in style_set: style_set[style.style_id] = style return Styles( -- cgit v1.2.3