Skip to content

Commit 4188ffd

Browse files
author
Steve Canny
committed
doc: add Document.paragraphs
1 parent a231eb1 commit 4188ffd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docx/document.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ def inline_shapes(self):
116116
"""
117117
return self._part.inline_shapes
118118

119+
@property
120+
def paragraphs(self):
121+
"""
122+
A list of |Paragraph| instances corresponding to the paragraphs in
123+
the document, in document order. Note that paragraphs within revision
124+
marks such as ``<w:ins>`` or ``<w:del>`` do not appear in this list.
125+
"""
126+
return self._body.paragraphs
127+
119128
@property
120129
def part(self):
121130
"""

tests/test_document.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def it_provides_access_to_its_inline_shapes(self, inline_shapes_fixture):
8989
inline_shapes = document.inline_shapes
9090
assert inline_shapes is inline_shapes_
9191

92+
def it_provides_access_to_its_paragraphs(self, paragraphs_fixture):
93+
document, paragraphs_ = paragraphs_fixture
94+
paragraphs = document.paragraphs
95+
assert paragraphs is paragraphs_
96+
9297
def it_provides_access_to_the_document_part(self, part_fixture):
9398
document, part_ = part_fixture
9499
assert document.part is part_
@@ -185,6 +190,12 @@ def inline_shapes_fixture(self, document_part_, inline_shapes_):
185190
document_part_.inline_shapes = inline_shapes_
186191
return document, inline_shapes_
187192

193+
@pytest.fixture
194+
def paragraphs_fixture(self, body_prop_, paragraphs_):
195+
document = Document(None, None)
196+
body_prop_.return_value.paragraphs = paragraphs_
197+
return document, paragraphs_
198+
188199
@pytest.fixture
189200
def part_fixture(self, document_part_):
190201
document = Document(None, document_part_)
@@ -224,6 +235,10 @@ def inline_shapes_(self, request):
224235
def paragraph_(self, request):
225236
return instance_mock(request, Paragraph)
226237

238+
@pytest.fixture
239+
def paragraphs_(self, request):
240+
return instance_mock(request, list)
241+
227242
@pytest.fixture
228243
def picture_(self, request):
229244
return instance_mock(request, InlineShape)

0 commit comments

Comments
 (0)