aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-06-08 00:17:05 +0100
committerMichael Williamson <mike@zwobble.org>2025-06-08 00:17:05 +0100
commitcc1ad1d283264284e10beeff33b140abc16156d3 (patch)
tree2f573f8aa641e41b9fb1f8941a4be5ff47404025 /mammoth/docx
parente2f39827f29ece66875e9fb4bb501cb391d3aa09 (diff)
Replace _vmerge with TableCellUnmerged
Diffstat (limited to 'mammoth/docx')
-rw-r--r--mammoth/docx/body_xml.py36
1 files changed, 17 insertions, 19 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index 40b5f9d..3de2c60 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -370,12 +370,11 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
colspan = int(gridspan)
return _read_xml_elements(element.children) \
- .map(lambda children: _add_attrs(
- documents.table_cell(
- children=children,
- colspan=colspan
- ),
- _vmerge=read_vmerge(properties),
+ .map(lambda children: documents.table_cell_unmerged(
+ children=children,
+ colspan=colspan,
+ rowspan=1,
+ vmerge=read_vmerge(properties),
))
def read_vmerge(properties):
@@ -398,7 +397,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
)])
unexpected_non_cells = any(
- not isinstance(cell, documents.TableCell)
+ not isinstance(cell, documents.TableCellUnmerged)
for row in rows
for cell in row.children
)
@@ -411,17 +410,23 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
for row in rows:
cell_index = 0
for cell in row.children:
- if cell._vmerge and cell_index in columns:
+ if cell.vmerge and cell_index in columns:
columns[cell_index].rowspan += 1
else:
columns[cell_index] = cell
- cell._vmerge = False
+ cell.vmerge = False
cell_index += cell.colspan
for row in rows:
- row.children = lists.filter(lambda cell: not cell._vmerge, row.children)
- for cell in row.children:
- del cell._vmerge
+ row.children = [
+ documents.table_cell(
+ children=cell.children,
+ colspan=cell.colspan,
+ rowspan=cell.rowspan,
+ )
+ for cell in row.children
+ if not cell.vmerge
+ ]
return _success(rows)
@@ -716,13 +721,6 @@ def _concat(*values):
return result
-def _add_attrs(obj, **kwargs):
- for key, value in kwargs.items():
- setattr(obj, key, value)
-
- return obj
-
-
def _is_int(value):
if value is None:
return False