ODT Input: Add workaround for ADE to fix centering of block level images when converting to EPUB

This commit is contained in:
Kovid Goyal 2011-09-27 10:51:56 -06:00
parent 0920ef4dd3
commit 915e9f0a34

View File

@ -42,14 +42,31 @@ class Extract(ODF2XHTML):
div.getparent().tag = XHTML('div')
# Remove the position:relative as it causes problems with some epub
# renderers
imgpath = XPath('//h:div[contains(@style, "position:relative")]/h:img[@style]')
# renderers. Remove display: block on an image inside a div as it is
# redundant and prevents text-align:center from working in ADE
imgpath = XPath('//h:div/h:img[@style]')
for img in imgpath(root):
div = img.getparent()
if len(div) == 1:
style = div.attrib['style'].replace('position:relative', '')
if style.startswith(';'): style = style[1:]
div.attrib['style'] = style
if img.attrib.get('style', '') == 'display: block;':
del img.attrib['style']
# A div/div/img construct causes text-align:center to not work in ADE
# so set the display of the second div to inline. This should have no
# effect (apart from minor vspace issues) in a compliant HTML renderer
# but it fixes the centering of the image via a text-align:center on
# the first div in ADE
imgpath = XPath('descendant::h:div/h:div/h:img')
for img in imgpath(root):
div2 = img.getparent()
div1 = div2.getparent()
if len(div1) == len(div2) == 1:
style = div2.attrib['style']
div2.attrib['style'] = 'display:inline;'+style
def filter_css(self, root, log):
style = root.xpath('//*[local-name() = "style" and @type="text/css"]')