From d045698289899e09e87f275c98413ec07ee6f785 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 30 Apr 2024 14:34:29 +0530 Subject: [PATCH] DOCX Input: Fix text elements containing only whitespace being incorrectly ignored. Fixes #2063301 [Incorrect conversion docx to epub](https://bugs.launchpad.net/calibre/+bug/2063301) --- src/calibre/ebooks/docx/to_html.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index ee5fb6d3d6..a41daae32e 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -671,8 +671,11 @@ class Convert: ctext = child.text if space != 'preserve': # Remove leading and trailing whitespace. Word ignores - # leading and trailing whitespace without preserve - ctext = ctext.strip(' \n\r\t') + # leading and trailing whitespace without preserve unless + # the element is only whitespace. + stripped = ctext.strip(' \n\r\t') + if stripped: + ctext = stripped # Only use a with white-space:pre-wrap if this element # actually needs it, i.e. if it has more than one # consecutive space or it has newlines or tabs.