DOCX Output: Preserve space before soft hyphen

This commit is contained in:
Kovid Goyal 2024-03-02 14:09:35 +05:30
parent 21b4869f22
commit b0d3fe6677
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -116,6 +116,12 @@ class TextRun:
if text: if text:
for x in self.soft_hyphen_pat.split(text): for x in self.soft_hyphen_pat.split(text):
if x == '\u00ad': if x == '\u00ad':
# trailing spaces in <w:t> before a soft hyphen are
# ignored, so put them in a preserve whitespace
# element with a single space.
if not preserve_whitespace and len(r) and r[-1].text and r[-1].text.endswith(' '):
r[-1].text = r[-1].text.rstrip()
add_text(' ', True)
makeelement(r, 'w:softHyphen') makeelement(r, 'w:softHyphen')
elif x: elif x:
add_text(x, preserve_whitespace) add_text(x, preserve_whitespace)