Skip to content

Commit 08fe8b9

Browse files
author
Steve Canny
committed
text: add Paragraph.style getter
1 parent aa83e77 commit 08fe8b9

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

docx/text.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ def runs(self):
3535
"""
3636
return tuple([Run(r) for r in self._p.r_elms])
3737

38+
@property
39+
def style(self):
40+
"""
41+
Paragraph style for this paragraph. Read/Write.
42+
"""
43+
style = self._p.style
44+
return style if style is not None else 'Normal'
45+
3846

3947
class Run(object):
4048
"""

tests/test_text.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ def it_can_add_a_run_to_itself(self, Run_):
5050
Run_.assert_called_once_with(r_elm)
5151
assert r is Run_.return_value
5252

53+
def it_knows_its_paragraph_style(self):
54+
cases = (
55+
(Mock(name='p_elm', style='foobar'), 'foobar'),
56+
(Mock(name='p_elm', style=None), 'Normal'),
57+
)
58+
for p_elm, expected_style in cases:
59+
p = Paragraph(p_elm)
60+
assert p.style == expected_style
61+
5362

5463
class DescribeRun(object):
5564

0 commit comments

Comments
 (0)