Skip to content

Commit

Permalink
MAINT: Use add_bookmark_destination in add_bookmark_dict (#1099)
Browse files Browse the repository at this point in the history
Re-use code

See #1098
  • Loading branch information
MartinThoma authored Jul 12, 2022
1 parent b2279ee commit d7b64dc
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions PyPDF2/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ def getNamedDestRoot(self) -> ArrayObject: # pragma: no cover
return self.get_named_dest_root()

def add_bookmark_destination(
self, dest: PageObject, parent: Optional[TreeObject] = None
self, dest: Union[PageObject, TreeObject], parent: Optional[TreeObject] = None
) -> IndirectObject:
dest_ref = self._add_object(dest)

Expand Down Expand Up @@ -1096,18 +1096,7 @@ def add_bookmark_dict(
action_ref = self._add_object(action)
bookmark_obj[NameObject("/A")] = action_ref

bookmark_ref = self._add_object(bookmark_obj)

outline_ref = self.get_outline_root()

if parent is None:
parent = outline_ref

parent = parent.get_object() # type: ignore
assert parent is not None, "hint for mypy"
parent.add_child(bookmark_ref, self)

return bookmark_ref
return self.add_bookmark_destination(bookmark_obj, parent)

def addBookmarkDict(
self, bookmark: BookmarkTypes, parent: Optional[TreeObject] = None
Expand Down

0 comments on commit d7b64dc

Please sign in to comment.