Parent Epic
#44
Bug
_element_size() in lower.py:2492 requires startIndex/endIndex to compute a table's character size. Synthetic content (new tab, new header, new footer, new footnote) has no API indices, so any path through _lower_content_insert with a table element raises NotImplementedError.
Root Cause
# lower.py:2492
def _element_size(el: StructuralElement) -> int:
if el.paragraph is not None:
return utf16_len(_para_text(el.paragraph)) # works
if el.section_break is not None:
return 1 # works
start, end = _element_range(el)
if start is not None and end is not None:
return end - start
raise NotImplementedError(...) # tables hit this
For paragraphs, size is computed from text. For tables, it falls through to startIndex/endIndex which don't exist on synthetic content.
Affected Paths
All 5 content containers when creating a new segment:
addDocumentTab → body with table
createHeader → header with table
createFooter → footer with table
createFootnote → footnote with table
- Any combination: paragraph → table → paragraph (running index breaks at table)
Suggested Fix
Compute table size from cell contents:
table_size = 1 (table opener) + sum_per_row(1 (row opener) + sum_per_cell(1 (cell opener) + cell_content_size))
Where cell_content_size recursively uses _element_size on cell content elements.
xfail Tests (7)
TestNewTabWithTable::test_new_tab_with_table
TestNewTabWithTable::test_new_tab_with_table_only
TestNewTabWithTable::test_new_tab_with_multi_paragraph_table_cell
TestElementSizeCascade::test_new_header_with_table_content
TestElementSizeCascade::test_new_footer_with_table_content
TestElementSizeCascade::test_new_footnote_with_table_content
TestElementSizeCascade::test_new_tab_para_table_para
TestNewHeaderMixedContent::test_new_header_text_then_table
Parent Epic
#44
Bug
_element_size()inlower.py:2492requiresstartIndex/endIndexto compute a table's character size. Synthetic content (new tab, new header, new footer, new footnote) has no API indices, so any path through_lower_content_insertwith a table element raisesNotImplementedError.Root Cause
For paragraphs, size is computed from text. For tables, it falls through to
startIndex/endIndexwhich don't exist on synthetic content.Affected Paths
All 5 content containers when creating a new segment:
addDocumentTab→ body with tablecreateHeader→ header with tablecreateFooter→ footer with tablecreateFootnote→ footnote with tableSuggested Fix
Compute table size from cell contents:
Where
cell_content_sizerecursively uses_element_sizeon cell content elements.xfail Tests (7)
TestNewTabWithTable::test_new_tab_with_tableTestNewTabWithTable::test_new_tab_with_table_onlyTestNewTabWithTable::test_new_tab_with_multi_paragraph_table_cellTestElementSizeCascade::test_new_header_with_table_contentTestElementSizeCascade::test_new_footer_with_table_contentTestElementSizeCascade::test_new_footnote_with_table_contentTestElementSizeCascade::test_new_tab_para_table_paraTestNewHeaderMixedContent::test_new_header_text_then_table