Skip to content

Commit 7e5471e

Browse files
author
Steve Canny
committed
style: add _ParaStyle.next_paragraph_style setter
1 parent 3119a45 commit 7e5471e

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

docx/styles/style.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ def next_paragraph_style(self):
248248
return self
249249
return StyleFactory(next_style_elm)
250250

251+
@next_paragraph_style.setter
252+
def next_paragraph_style(self, style):
253+
if style is None or style.style_id == self.style_id:
254+
self._element._remove_next()
255+
else:
256+
self._element.get_or_add_next().val = style.style_id
257+
251258
@property
252259
def paragraph_format(self):
253260
"""

features/sty-style-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Feature: Get and set style properties
9292
| Foobar | Sub Normal |
9393

9494

95-
@wip
9695
Scenario Outline: Set next paragraph style
9796
Given a style having next paragraph style set to <setting>
9897
When I assign <new-value> to style.next_paragraph_style

tests/styles/test_style.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ def it_knows_its_next_paragraph_style(self, next_get_fixture):
468468
style, expected_value = next_get_fixture
469469
assert style.next_paragraph_style == expected_value
470470

471+
def it_can_change_its_next_paragraph_style(self, next_set_fixture):
472+
style, next_style, expected_xml = next_set_fixture
473+
style.next_paragraph_style = next_style
474+
assert style.element.xml == expected_xml
475+
471476
def it_provides_access_to_its_paragraph_format(self, parfmt_fixture):
472477
style, ParagraphFormat_, paragraph_format_ = parfmt_fixture
473478
paragraph_format = style.paragraph_format
@@ -502,6 +507,27 @@ def next_get_fixture(self, request):
502507
next_style = style
503508
return style, next_style
504509

510+
@pytest.fixture(params=[
511+
('H', 'B', 'w:style{w:type=paragraph,w:styleId=H}/w:next{w:val=B}'),
512+
('H', None, 'w:style{w:type=paragraph,w:styleId=H}'),
513+
('H', 'H', 'w:style{w:type=paragraph,w:styleId=H}'),
514+
])
515+
def next_set_fixture(self, request):
516+
style_name, next_style_name, style_cxml = request.param
517+
styles = element(
518+
'w:styles/('
519+
'w:style{w:type=paragraph,w:styleId=H},'
520+
'w:style{w:type=paragraph,w:styleId=B})'
521+
)
522+
style_elms = {'H': styles[0], 'B': styles[1]}
523+
style = _ParagraphStyle(style_elms[style_name])
524+
next_style = (
525+
None if next_style_name is None else
526+
_ParagraphStyle(style_elms[next_style_name])
527+
)
528+
expected_xml = xml(style_cxml)
529+
return style, next_style, expected_xml
530+
505531
@pytest.fixture
506532
def parfmt_fixture(self, ParagraphFormat_, paragraph_format_):
507533
style = _ParagraphStyle(element('w:style'))

0 commit comments

Comments
 (0)