aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2019-03-17 21:27:34 +0000
committerMichael Williamson <mike@zwobble.org>2019-03-17 21:28:06 +0000
commita45ad007f9c3e366313b0dc8d5b2b31eb43912d0 (patch)
treead78299162e299dc3a4688f730a2a123e384c4f2 /mammoth
parent65834fa39ee1ea77ef5581bc11e4e6046c6499a6 (diff)
Follow w:numStyleLink in w:abstractNum
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/docx/__init__.py2
-rw-r--r--mammoth/docx/numbering_xml.py19
2 files changed, 16 insertions, 5 deletions
diff --git a/mammoth/docx/__init__.py b/mammoth/docx/__init__.py
index 63a634c..fcb5da5 100644
--- a/mammoth/docx/__init__.py
+++ b/mammoth/docx/__init__.py
@@ -153,7 +153,7 @@ def _part_with_body_reader(document_path, zip_file, part_paths):
zip_file,
part_paths.numbering,
lambda element: read_numbering_xml_element(element, styles=styles),
- default=Numbering(abstract_nums={}, nums={}),
+ default=Numbering.EMPTY,
)
def read_part(name, reader, default=_undefined):
diff --git a/mammoth/docx/numbering_xml.py b/mammoth/docx/numbering_xml.py
index 3a0645e..af3d1d5 100644
--- a/mammoth/docx/numbering_xml.py
+++ b/mammoth/docx/numbering_xml.py
@@ -1,12 +1,13 @@
import cobble
from ..documents import numbering_level
+from .styles_xml import Styles
def read_numbering_xml_element(element, styles):
abstract_nums = _read_abstract_nums(element)
nums = _read_nums(element)
- return Numbering(abstract_nums=abstract_nums, nums=nums)
+ return Numbering(abstract_nums=abstract_nums, nums=nums, styles=styles)
def _read_abstract_nums(element):
@@ -17,12 +18,14 @@ def _read_abstract_nums(element):
def _read_abstract_num(element):
abstract_num_id = element.attributes.get("w:abstractNumId")
levels = _read_abstract_num_levels(element)
- return abstract_num_id, _AbstractNum(levels=levels)
+ num_style_link = element.find_child_or_null("w:numStyleLink").attributes.get("w:val")
+ return abstract_num_id, _AbstractNum(levels=levels, num_style_link=num_style_link)
@cobble.data
class _AbstractNum(object):
levels = cobble.field()
+ num_style_link = cobble.field()
def _read_abstract_num_levels(element):
@@ -60,9 +63,10 @@ class _Num(object):
class Numbering(object):
- def __init__(self, abstract_nums, nums):
+ def __init__(self, abstract_nums, nums, styles):
self._abstract_nums = abstract_nums
self._nums = nums
+ self._styles = styles
def find_level(self, num_id, level):
num = self._nums.get(num_id)
@@ -70,4 +74,11 @@ class Numbering(object):
return None
else:
abstract_num = self._abstract_nums[num.abstract_num_id]
- return abstract_num.levels.get(level)
+ if abstract_num.num_style_link is None:
+ return abstract_num.levels.get(level)
+ else:
+ style = self._styles.find_numbering_style_by_id(abstract_num.num_style_link)
+ return self.find_level(style.num_id, level)
+
+
+Numbering.EMPTY = Numbering(abstract_nums={}, nums={}, styles=Styles.EMPTY)