mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
DOCX Output: Fix extra page breaks being inserted in some situations. See #1455502 (EPUB to DOCX Conversation)
This commit is contained in:
parent
cce2f70507
commit
47729eab47
@ -523,9 +523,16 @@ class Convert(object):
|
|||||||
if not is_first_tag and html_tag.tail and (not ignore_whitespace_tail or not html_tag.tail.isspace()):
|
if not is_first_tag and html_tag.tail and (not ignore_whitespace_tail or not html_tag.tail.isspace()):
|
||||||
# Ignore trailing space after a block tag, as otherwise it will
|
# Ignore trailing space after a block tag, as otherwise it will
|
||||||
# become a new empty paragraph
|
# become a new empty paragraph
|
||||||
block = self.blocks.current_or_new_block(html_tag.getparent(), stylizer.style(html_tag.getparent()))
|
block = self.create_block_from_parent(html_tag, stylizer)
|
||||||
block.add_text(html_tag.tail, stylizer.style(html_tag.getparent()), is_parent_style=True, link=self.current_link, lang=self.current_lang)
|
block.add_text(html_tag.tail, stylizer.style(html_tag.getparent()), is_parent_style=True, link=self.current_link, lang=self.current_lang)
|
||||||
|
|
||||||
|
def create_block_from_parent(self, html_tag, stylizer):
|
||||||
|
parent = html_tag.getparent()
|
||||||
|
block = self.blocks.current_or_new_block(parent, stylizer.style(parent))
|
||||||
|
# Do not inherit page-break-before from parent
|
||||||
|
block.page_break_before = False
|
||||||
|
return block
|
||||||
|
|
||||||
def add_block_tag(self, tagname, html_tag, tag_style, stylizer, is_table_cell=False, float_spec=None, is_list_item=False):
|
def add_block_tag(self, tagname, html_tag, tag_style, stylizer, is_table_cell=False, float_spec=None, is_list_item=False):
|
||||||
block = self.blocks.start_new_block(
|
block = self.blocks.start_new_block(
|
||||||
html_tag, tag_style, is_table_cell=is_table_cell, float_spec=float_spec, is_list_item=is_list_item)
|
html_tag, tag_style, is_table_cell=is_table_cell, float_spec=float_spec, is_list_item=is_list_item)
|
||||||
@ -545,14 +552,14 @@ class Convert(object):
|
|||||||
bmark = self.bookmark_for_anchor(anchor, html_tag)
|
bmark = self.bookmark_for_anchor(anchor, html_tag)
|
||||||
if tagname == 'br':
|
if tagname == 'br':
|
||||||
if html_tag.tail or html_tag is not tuple(html_tag.getparent().iterchildren('*'))[-1]:
|
if html_tag.tail or html_tag is not tuple(html_tag.getparent().iterchildren('*'))[-1]:
|
||||||
block = self.blocks.current_or_new_block(html_tag.getparent(), stylizer.style(html_tag.getparent()))
|
block = self.create_block_from_parent(html_tag, stylizer)
|
||||||
block.add_break(clear={'both':'all', 'left':'left', 'right':'right'}.get(tag_style['clear'], 'none'), bookmark=bmark)
|
block.add_break(clear={'both':'all', 'left':'left', 'right':'right'}.get(tag_style['clear'], 'none'), bookmark=bmark)
|
||||||
elif tagname == 'img':
|
elif tagname == 'img':
|
||||||
block = self.blocks.current_or_new_block(html_tag.getparent(), stylizer.style(html_tag.getparent()))
|
block = self.create_block_from_parent(html_tag, stylizer)
|
||||||
self.images_manager.add_image(html_tag, block, stylizer, bookmark=bmark)
|
self.images_manager.add_image(html_tag, block, stylizer, bookmark=bmark)
|
||||||
else:
|
else:
|
||||||
if html_tag.text:
|
if html_tag.text:
|
||||||
block = self.blocks.current_or_new_block(html_tag.getparent(), stylizer.style(html_tag.getparent()))
|
block = self.create_block_from_parent(html_tag, stylizer)
|
||||||
block.add_text(html_tag.text, tag_style, is_parent_style=False, bookmark=bmark, link=self.current_link, lang=self.current_lang)
|
block.add_text(html_tag.text, tag_style, is_parent_style=False, bookmark=bmark, link=self.current_link, lang=self.current_lang)
|
||||||
|
|
||||||
def bookmark_for_anchor(self, anchor, html_tag):
|
def bookmark_for_anchor(self, anchor, html_tag):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user