Skip to content

Commit fffa94f

Browse files
author
Steve Canny
committed
txt: use <w:br/> for line break instead of <w:cr/>
Word does not interpret <w:cr/> element in run as a line break, contrary to the behavior required by the ISO 29500 spec. Use <w:br/> element to implement line break when a line feed (‘\n’) or carriage return (‘\r’) character is encountered in text assigned to a run.
1 parent ba04f40 commit fffa94f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

docx/oxml/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def add_char(self, char):
420420
self._r.add_tab()
421421
elif char in '\r\n':
422422
self.flush()
423-
self._r.add_cr()
423+
self._r.add_br()
424424
else:
425425
self._bfr.append(char)
426426

tests/test_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def it_can_replace_its_content_with_a_string_of_text(
136136
('w:tc/w:p', 'foobar',
137137
'w:tc/w:p/w:r/w:t"foobar"'),
138138
('w:tc/w:p', 'fo\tob\rar\n',
139-
'w:tc/w:p/w:r/(w:t"fo",w:tab,w:t"ob",w:cr,w:t"ar",w:cr)'),
139+
'w:tc/w:p/w:r/(w:t"fo",w:tab,w:t"ob",w:br,w:t"ar",w:br)'),
140140
('w:tc/(w:tcPr, w:p, w:tbl, w:p)', 'foobar',
141141
'w:tc/(w:tcPr, w:p/w:r/w:t"foobar")'),
142142
])

tests/test_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ def text_get_fixture(self, request):
506506
@pytest.fixture(params=[
507507
('abc def', 'w:r/w:t"abc def"'),
508508
('abc\tdef', 'w:r/(w:t"abc", w:tab, w:t"def")'),
509-
('abc\ndef', 'w:r/(w:t"abc", w:cr, w:t"def")'),
510-
('abc\rdef', 'w:r/(w:t"abc", w:cr, w:t"def")'),
509+
('abc\ndef', 'w:r/(w:t"abc", w:br, w:t"def")'),
510+
('abc\rdef', 'w:r/(w:t"abc", w:br, w:t"def")'),
511511
])
512512
def text_set_fixture(self, request):
513513
new_text, expected_cxml = request.param

0 commit comments

Comments
 (0)