Conversion: Fix the obsolete HTML align=center markup (produced by Microsoft Word) not working for tables. Fixes #1569583 [table alignment lost on conversion](https://bugs.launchpad.net/calibre/+bug/1569583)

This commit is contained in:
Kovid Goyal 2016-04-13 07:14:57 +05:30
parent 602902476d
commit d8bfb8c8b1

View File

@ -344,6 +344,20 @@ class CSSFlattener(object):
if 'align' in node.attrib: if 'align' in node.attrib:
if tag != 'img': if tag != 'img':
cssdict['text-align'] = node.attrib['align'] cssdict['text-align'] = node.attrib['align']
if cssdict['text-align'] == 'center':
# align=center causes tables to be center aligned,
# which text-align does not. And the ever trustworthy Word
# uses this construct in its HTML output. See
# https://bugs.launchpad.net/bugs/1569583
if tag == 'table':
if 'margin-left' not in cssdict and 'margin-right' not in cssdict:
cssdict['margin-left'] = cssdict['margin-right'] = 'auto'
else:
for table in node.iterchildren(XHTML("table")):
ts = stylizer.style(table)
if ts.get('margin-left') is None and ts.get('margin-right') is None:
ts.set('margin-left', 'auto')
ts.set('margin-right', 'auto')
else: else:
val = node.attrib['align'] val = node.attrib['align']
if val in ('middle', 'bottom', 'top'): if val in ('middle', 'bottom', 'top'):