From dbd738e5f679fd9a256a6d707f6200f500aa6c02 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 7 Jul 2020 19:06:15 +0530 Subject: [PATCH] DOCX Output: When detecting empty list items that contain a nested list, ignore whitespace --- src/calibre/ebooks/docx/writer/from_html.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/docx/writer/from_html.py b/src/calibre/ebooks/docx/writer/from_html.py index f2618b1797..2e645fce6a 100644 --- a/src/calibre/ebooks/docx/writer/from_html.py +++ b/src/calibre/ebooks/docx/writer/from_html.py @@ -575,9 +575,12 @@ class Convert(object): self.images_manager.add_image(html_tag, block, stylizer, as_block=True) else: text = html_tag.text + is_list_item = tagname == 'li' + if text and is_list_item and not text.strip(): + text = '' # whitespace only, ignore if text: block.add_text(text, tag_style, ignore_leading_whitespace=True, is_parent_style=True, link=self.current_link, lang=self.current_lang) - elif tagname == 'li' and len(html_tag) and barename(html_tag[0].tag) in ('ul', 'ol') and len(html_tag[0]): + elif is_list_item and len(html_tag) and barename(html_tag[0].tag) in ('ul', 'ol') and len(html_tag[0]): block.force_not_empty = True def add_inline_tag(self, tagname, html_tag, tag_style, stylizer):