diff --git a/src/calibre/ebooks/docx/writer/from_html.py b/src/calibre/ebooks/docx/writer/from_html.py index 7bd5628d8d..af8b9db1f2 100644 --- a/src/calibre/ebooks/docx/writer/from_html.py +++ b/src/calibre/ebooks/docx/writer/from_html.py @@ -116,6 +116,12 @@ class TextRun: if text: for x in self.soft_hyphen_pat.split(text): if x == '\u00ad': + # trailing spaces in 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') elif x: add_text(x, preserve_whitespace)