File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1+ # 1.11.0
2+
3+ * Ignore style definitions using a style ID that has already been used.
4+
15# 1.10.0
26
37* Add "Heading" and "Body" styles, as found in documents created by Apple Pages,
Original file line number Diff line number Diff line change @@ -67,7 +67,18 @@ def read_styles_xml_element(element):
6767 style = _read_style_element (style_element )
6868
6969 style_set = styles .get (element_type )
70- if style_set is not None :
70+
71+ # Per 17.7.4.17 style (Style Definition) of ECMA-376 4th edition Part 1:
72+ #
73+ # > If multiple style definitions each declare the same value for their
74+ # > styleId, then the first such instance shall keep its current
75+ # > identifier with all other instances being reassigned in any manner
76+ # > desired.
77+ #
78+ # For the purpose of conversion, there's no point holding onto styles
79+ # with reassigned style IDs, so we ignore such style definitions.
80+
81+ if style_set is not None and style .style_id not in style_set :
7182 style_set [style .style_id ] = style
7283
7384 return Styles (
Original file line number Diff line number Diff line change @@ -101,6 +101,18 @@ def test_numbering_style_has_num_id_read_from_paragraph_properties():
101101 assert_equal ("42" , styles .find_numbering_style_by_id ("List1" ).num_id )
102102
103103
104+ def test_when_multiple_style_elements_have_same_style_id_then_only_first_element_is_used ():
105+ element = xml_element ("w:styles" , {}, [
106+ _table_style_element ("TableNormal" , "Normal Table" ),
107+ _table_style_element ("TableNormal" , "Table Normal" ),
108+ ])
109+ styles = read_styles_xml_element (element )
110+ assert_equal (
111+ "Normal Table" ,
112+ styles .find_table_style_by_id ("TableNormal" ).name
113+ )
114+
115+
104116def _paragraph_style_element (style_id , name ):
105117 return _style_element ("paragraph" , style_id , name )
106118
You can’t perform that action at this time.
0 commit comments