aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx/body_xml.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2021-01-09 13:52:02 +0000
committerMichael Williamson <mike@zwobble.org>2021-01-09 13:52:02 +0000
commit801b505840b698858c48761c640d52a5fa5ec3fb (patch)
tree00285ea140888c94bde0c17d1cc061b521ca29f0 /mammoth/docx/body_xml.py
parentd1910bc1e649deb9f0f69114b61023458f3d8d2f (diff)
Support numbering defined by paragraph style
Diffstat (limited to 'mammoth/docx/body_xml.py')
-rw-r--r--mammoth/docx/body_xml.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index 17cf31b..d4fdccf 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -131,7 +131,6 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
def paragraph(element):
properties = element.find_child_or_null("w:pPr")
alignment = properties.find_child_or_null("w:jc").attributes.get("w:val")
- numbering = _read_numbering_properties(properties.find_child_or_null("w:numPr"))
indent = _read_paragraph_indent(properties.find_child_or_null("w:ind"))
return _ReadResult.map_results(
@@ -141,7 +140,10 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
children=children,
style_id=style[0],
style_name=style[1],
- numbering=numbering,
+ numbering=_read_numbering_properties(
+ paragraph_style_id=style[0],
+ element=properties.find_child_or_null("w:numPr"),
+ ),
alignment=alignment,
indent=indent,
)).append_extra()
@@ -209,7 +211,12 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
def _undefined_style_warning(style_type, style_id):
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(element):
+ def _read_numbering_properties(paragraph_style_id, element):
+ 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: