Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document.story property, contains Paragraph and Table in document order #395

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions docx/blkcntnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ def tables(self):
from .table import Table
return [Table(tbl, self) for tbl in self._element.tbl_lst]

@property
def story(self):
"""
A list containing paragraphs and tables in document order
"""
from .table import Table
from docx.oxml.text.paragraph import CT_P
from docx.oxml.table import CT_Tbl

def make_element(el, s):
if isinstance(el, CT_P):
return Paragraph(el, s)
elif isinstance(el, CT_Tbl):
return Table(el, s)

return [make_element(el, self) for el in self._element if isinstance(el, CT_P) or isinstance(el, CT_Tbl)]

def _add_paragraph(self):
"""
Return a paragraph newly added to the end of the content in this
Expand Down
7 changes: 7 additions & 0 deletions docx/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ def paragraphs(self):
"""
return self._body.paragraphs

@property
def story(self):
"""
A list of |Paragraph| and |Table| instances in document order
"""
return self._body.story

@property
def part(self):
"""
Expand Down