From 43011b9a979900fc21f99ec7d652d75d3c4e4b96 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 Oct 2017 12:39:04 +0530 Subject: [PATCH] DOCX Output: Fix comments/XML processing instructions in the middle of text causing text to be skipped. Fixes #1727599 [Private bug](https://bugs.launchpad.net/calibre/+bug/1727599) --- src/calibre/ebooks/docx/writer/from_html.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/docx/writer/from_html.py b/src/calibre/ebooks/docx/writer/from_html.py index 9ca1dab101..289ea8c886 100644 --- a/src/calibre/ebooks/docx/writer/from_html.py +++ b/src/calibre/ebooks/docx/writer/from_html.py @@ -522,8 +522,14 @@ class Convert(object): tag_style.set('border-%s-style' % edge, 'none') self.add_block_tag(tagname, html_tag, tag_style, stylizer, float_spec=float_spec) - for child in html_tag.iterchildren('*'): - self.process_tag(child, stylizer, float_spec=float_spec) + for child in html_tag.iterchildren(): + if isinstance(getattr(child, 'tag', None), basestring): + self.process_tag(child, stylizer, float_spec=float_spec) + else: # Comment/PI/etc. + tail = getattr(child, 'tail', None) + if tail: + block = self.create_block_from_parent(html_tag, stylizer) + block.add_text(tail, tag_style, is_parent_style=False, link=self.current_link, lang=self.current_lang) is_block = html_tag in self.blocks.open_html_blocks self.blocks.finish_tag(html_tag)