mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ODT Input: Add workaround for ADE to fix centering of block level images when converting to EPUB
This commit is contained in:
parent
0920ef4dd3
commit
915e9f0a34
@ -42,14 +42,31 @@ class Extract(ODF2XHTML):
|
|||||||
div.getparent().tag = XHTML('div')
|
div.getparent().tag = XHTML('div')
|
||||||
|
|
||||||
# Remove the position:relative as it causes problems with some epub
|
# Remove the position:relative as it causes problems with some epub
|
||||||
# renderers
|
# renderers. Remove display: block on an image inside a div as it is
|
||||||
imgpath = XPath('//h:div[contains(@style, "position:relative")]/h:img[@style]')
|
# redundant and prevents text-align:center from working in ADE
|
||||||
|
imgpath = XPath('//h:div/h:img[@style]')
|
||||||
for img in imgpath(root):
|
for img in imgpath(root):
|
||||||
div = img.getparent()
|
div = img.getparent()
|
||||||
if len(div) == 1:
|
if len(div) == 1:
|
||||||
style = div.attrib['style'].replace('position:relative', '')
|
style = div.attrib['style'].replace('position:relative', '')
|
||||||
if style.startswith(';'): style = style[1:]
|
if style.startswith(';'): style = style[1:]
|
||||||
div.attrib['style'] = style
|
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):
|
def filter_css(self, root, log):
|
||||||
style = root.xpath('//*[local-name() = "style" and @type="text/css"]')
|
style = root.xpath('//*[local-name() = "style" and @type="text/css"]')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user