Skip to content

Commit bdae7a4

Browse files
Merge pull request #210 from adamtheturtle/combine-loops
Simplify loops as header rows and body rows are treated the same
2 parents 2065a55 + 64e1647 commit bdae7a4

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

src/sphinx_notion/__init__.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -458,31 +458,19 @@ def _(
458458
msg = "Tables with multiple header rows are not supported."
459459
raise ValueError(msg)
460460

461-
n_rows = len(table_structure.header_rows) + len(
462-
table_structure.body_rows
463-
)
461+
rows = [*table_structure.header_rows, *table_structure.body_rows]
464462
table = UnoTable(
465-
n_rows=n_rows,
463+
n_rows=len(rows),
466464
n_cols=table_structure.n_cols,
467465
header_row=bool(table_structure.header_rows),
468466
)
469467

470-
row_idx = 0
471-
for header_row in table_structure.header_rows:
472-
for col_idx, entry in enumerate(iterable=header_row.children):
473-
source = _cell_source_node(entry=entry)
474-
table[row_idx, col_idx] = _create_rich_text_from_children(
475-
node=source
476-
)
477-
row_idx += 1
478-
479-
for body_row in table_structure.body_rows:
480-
for col_idx, entry in enumerate(iterable=body_row.children):
468+
for row_index, row in enumerate(iterable=rows):
469+
for column_index, entry in enumerate(iterable=row.children):
481470
source = _cell_source_node(entry=entry)
482-
table[row_idx, col_idx] = _create_rich_text_from_children(
483-
node=source
471+
table[row_index, column_index] = (
472+
_create_rich_text_from_children(node=source)
484473
)
485-
row_idx += 1
486474

487475
self._add_block_to_tree(block=table, parent_path=parent_path)
488476

0 commit comments

Comments
 (0)