Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2df446

Browse files
Benjamin Toornstrascanny
authored andcommitted
bmk: add _PartBookmarkFinder._all_starts_and_ends
1 parent a6726c0 commit a2df446

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docx/bookmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _all_starts_and_ends(self):
8585
8686
Elements appear in document order.
8787
"""
88-
raise NotImplementedError
88+
return self._part.element.xpath("//w:bookmarkStart|//w:bookmarkEnd")
8989

9090
def _iter_starts(self):
9191
"""Generate (idx, bookmarkStart) elements in story.

tests/test_bookmark.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ def it_provides_an_iter_start_end_pairs_interface_method(
124124
_iter_start_end_pairs_.assert_called_once_with(ANY)
125125
assert pairs == _iter_start_end_pairs_.return_value
126126

127+
def it_gathers_all_the_bookmark_start_and_end_elements_to_help(self, part_):
128+
body = element(
129+
"w:body/(w:bookmarkStart,w:p,w:bookmarkEnd,w:p,w:bookmarkStart)"
130+
)
131+
part_.element = body
132+
finder = _PartBookmarkFinder(part_)
133+
134+
starts_and_ends = finder._all_starts_and_ends
135+
136+
assert starts_and_ends == [body[0], body[2], body[4]]
137+
127138
def it_iterates_start_end_pairs_to_help(
128139
self, _iter_starts_, _matching_end_, _name_already_used_
129140
):

0 commit comments

Comments
 (0)