diff --git a/docx/blkcntnr.py b/docx/blkcntnr.py index d57a0cd0f..e6985c7aa 100644 --- a/docx/blkcntnr.py +++ b/docx/blkcntnr.py @@ -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 diff --git a/docx/document.py b/docx/document.py index ba94a7990..3cfcfb443 100644 --- a/docx/document.py +++ b/docx/document.py @@ -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): """