Skip to content

Commit

Permalink
rfctr(table): reimplement CT_Tc._tr_above
Browse files Browse the repository at this point in the history
Use XPath rather than oxml structures.
  • Loading branch information
scanny committed Apr 29, 2024
1 parent 5a1d614 commit 6d49a69
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/docx/oxml/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,10 @@ def _tr_above(self) -> CT_Row:
Raises |ValueError| if called on a cell in the top-most row.
"""
tr_lst = self._tbl.tr_lst
tr_idx = tr_lst.index(self._tr)
if tr_idx == 0:
raise ValueError("no tr above topmost tr")
return tr_lst[tr_idx - 1]
tr_aboves = self.xpath("./ancestor::w:tr[position()=1]/preceding-sibling::w:tr[1]")
if not tr_aboves:
raise ValueError("no tr above topmost tr in w:tbl")
return tr_aboves[0]

@property
def _tr_below(self) -> CT_Row | None:
Expand Down

0 comments on commit 6d49a69

Please sign in to comment.