Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions docx/parts/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ def new_pic_inline(self, image_descriptor, width, height):

@property
def next_id(self):
"""Next available positive integer id value in this story XML document.

The value is determined by incrementing the maximum existing id value. Gaps in
the existing id sequence are not filled. The id attribute value is unique in the
"""
The next available positive integer id value in this document. Gaps
in id sequence are filled. The id attribute value is unique in the
document, without regard to the element type it appears on.
"""
id_str_lst = self._element.xpath('//@id')
used_ids = [int(id_str) for id_str in id_str_lst if id_str.isdigit()]
if not used_ids:
return 1
return max(used_ids) + 1
used_ids = [int(id_str) for id_str in id_str_lst if id_str.isdigit() and int(id_str)>100000]
for n in range(100001, len(used_ids)+100002):
if n not in used_ids:
return n

@lazyproperty
def _document_part(self):
Expand Down