This commit is contained in:
Kovid Goyal 2015-03-25 14:41:14 +05:30
parent 355fc6f84b
commit 45681fef78
2 changed files with 40 additions and 25 deletions

View File

@ -200,7 +200,7 @@ class Convert(object):
if block_style.is_hidden:
return
if html_block.tag.endswith('}img'):
b = Block(self.styles_manager, html_block, stylizer.style(html_block))
b = Block(self.styles_manager, html_block, None)
self.blocks.append(b)
self.images_manager.add_image(html_block, b, stylizer)
else:
@ -218,15 +218,15 @@ class Convert(object):
else:
self.process_inline(child, self.blocks[-1], stylizer)
if ignore_tail is False and html_block.tail and html_block.tail.strip():
b = docx_block
if b is not self.blocks[-1]:
b = Block(self.styles_manager, html_block, block_style)
self.blocks.append(b)
b.add_text(html_block.tail, stylizer.style(html_block.getparent()), is_parent_style=True)
if block_style['page-break-after'] == 'avoid':
self.blocks[-1].keep_next = True
if ignore_tail is False and html_block.tail and html_block.tail.strip():
style = stylizer.style(html_block.getparent())
b = Block(self.styles_manager, html_block.getparent(), style)
self.blocks.append(b)
b.add_text(html_block.tail, style, is_parent_style=True)
def process_inline(self, html_child, docx_block, stylizer):
tag = barename(html_child.tag)
style = stylizer.style(html_child)

View File

@ -236,6 +236,21 @@ class BlockStyle(DOCXStyle):
)
def __init__(self, css, html_block, is_first_block=False):
if css is None:
self.page_break_before = self.keep_lines = False
for edge in border_edges:
setattr(self, 'padding_' + edge, 0)
setattr(self, 'margin_' + edge, 0)
setattr(self, 'css_margin_' + edge, '')
setattr(self, 'border_%s_width' % edge, 2)
setattr(self, 'border_%s_color' % edge, None)
setattr(self, 'border_%s_style' % edge, 'none')
self.text_indent = 0
self.css_text_indent = None
self.line_height = 280
self.background_color = None
self.text_align = 'left'
else:
self.page_break_before = html_block.tag.endswith('}body') or (not is_first_block and css['page-break-before'] == 'always')
self.keep_lines = css['page-break-inside'] == 'avoid'
for edge in border_edges: