aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--mammoth/docx/body_xml.py12
-rw-r--r--tests/docx/body_xml_tests.py21
3 files changed, 29 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 6a3950b..5b5b8b5 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+# 1.7.1
+
+* Switch the precedence of numbering properties in paragraph properties and the
+ numbering in paragraph styles so that the numbering properties in paragraph
+ properties takes precedence.
+
# 1.7.0
* Support attributes in HTML paths in style mappings.
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index f880c72..005ad3d 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -236,17 +236,17 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
return results.warning("{0} style with ID {1} was referenced but not defined in the document".format(style_type, style_id))
def _read_numbering_properties(paragraph_style_id, element):
+ num_id = element.find_child_or_null("w:numId").attributes.get("w:val")
+ level_index = element.find_child_or_null("w:ilvl").attributes.get("w:val")
+ if num_id is not None and level_index is not None:
+ return numbering.find_level(num_id, level_index)
+
if paragraph_style_id is not None:
level = numbering.find_level_by_paragraph_style_id(paragraph_style_id)
if level is not None:
return level
- num_id = element.find_child_or_null("w:numId").attributes.get("w:val")
- level_index = element.find_child_or_null("w:ilvl").attributes.get("w:val")
- if num_id is None or level_index is None:
- return None
- else:
- return numbering.find_level(num_id, level_index)
+ return None
def _read_paragraph_indent(element):
attributes = element.attributes
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index 32f6642..44a3e34 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -105,7 +105,20 @@ class ParagraphTests(object):
assert_equal("1", paragraph.numbering.level_index)
assert_equal(True, paragraph.numbering.is_ordered)
- def test_numbering_on_paragraph_style_takes_precedence_over_numpr(self):
+ def test_paragraph_has_numbering_from_paragraph_style_if_present(self):
+ properties_xml = xml_element("w:pPr", {}, [
+ xml_element("w:pStyle", {"w:val": "List"}),
+ ])
+ paragraph_xml = xml_element("w:p", {}, [properties_xml])
+
+ numbering = _NumberingMap(
+ levels_by_paragraph_style_id={"List": documents.numbering_level("1", True)}
+ )
+ paragraph = _read_and_get_document_xml_element(paragraph_xml, numbering=numbering)
+
+ assert_equal(True, paragraph.numbering.is_ordered)
+
+ def test_numbering_properties_in_paragraph_properties_takes_precedence_over_numbering_in_paragraph_style(self):
numbering_properties_xml = xml_element("w:numPr", {}, [
xml_element("w:ilvl", {"w:val": "1"}),
xml_element("w:numId", {"w:val": "42"}),
@@ -117,12 +130,12 @@ class ParagraphTests(object):
paragraph_xml = xml_element("w:p", {}, [properties_xml])
numbering = _NumberingMap(
- nums={"42": {"1": documents.numbering_level("1", False)}},
- levels_by_paragraph_style_id={"List": documents.numbering_level("1", True)}
+ nums={"42": {"1": documents.numbering_level("1", True)}},
+ levels_by_paragraph_style_id={"List": documents.numbering_level("2", True)}
)
paragraph = _read_and_get_document_xml_element(paragraph_xml, numbering=numbering)
- assert_equal(True, paragraph.numbering.is_ordered)
+ assert_equal("1", paragraph.numbering.level_index)
def test_numbering_properties_are_ignored_if_lvl_is_missing(self):
paragraph_xml = self._paragraph_with_numbering_properties([