From 06d633b5d11dd208c58dbdd430c6a51075456908 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 30 Apr 2010 08:53:32 -0600 Subject: [PATCH] Workaround ADE bug in rendering of lists with a left margin set. Fixes #5415 (HTML to EPUB conversion breaks nested list display in ADE) --- src/calibre/ebooks/epub/output.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py index dc8905619d..fd96bfdb94 100644 --- a/src/calibre/ebooks/epub/output.py +++ b/src/calibre/ebooks/epub/output.py @@ -364,6 +364,12 @@ class EPUBOutput(OutputFormatPlugin): ''' from calibre.ebooks.oeb.base import XPath, XHTML, OEB_STYLES, barename, urlunquote + stylesheet = None + for item in self.oeb.manifest: + if item.media_type.lower() in OEB_STYLES: + stylesheet = item + break + # ADE cries big wet tears when it encounters an invalid fragment # identifier in the NCX toc. frag_pat = re.compile(r'[-A-Za-z0-9_:.]+$') @@ -460,11 +466,17 @@ class EPUBOutput(OutputFormatPlugin): elem.tail = special_chars.sub('', elem.tail) elem.tail = elem.tail.replace(u'\u2011', '-') - stylesheet = None - for item in self.oeb.manifest: - if item.media_type.lower() in OEB_STYLES: - stylesheet = item - break + if stylesheet is not None: + # ADE doesn't render lists correctly if they have left margins + from cssutils.css import CSSRule + for lb in XPath('//h:ul[@class]|//h:ol[@class]')(root): + sel = '.'+lb.get('class') + for rule in stylesheet.data.cssRules.rulesOfType(CSSRule.STYLE_RULE): + if sel == rule.selectorList.selectorText: + val = rule.style.removeProperty('margin-left') + pval = rule.style.getProperty('padding-left') + if val and not pval: + rule.style.setProperty('padding-left', val) if stylesheet is not None: stylesheet.data.add('a { color: inherit; text-decoration: inherit; '