From b0d3fe6677102c82232a02f990a7a5d488c68de4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 Mar 2024 14:09:35 +0530 Subject: [PATCH] DOCX Output: Preserve space before soft hyphen --- src/calibre/ebooks/docx/writer/from_html.py | 6 ++++++ 1 file changed, 6 insertions(+) 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)