Fix #2666 (zipped html can't be converted to epub - failing on css values)

This commit is contained in:
Kovid Goyal 2009-06-19 08:10:39 -07:00
parent 32b024475e
commit 2abf0d2f0e

View File

@ -217,7 +217,7 @@ class EPUBOutput(OutputFormatPlugin):
Perform various markup transforms to get the output to render correctly Perform various markup transforms to get the output to render correctly
in the quirky ADE. in the quirky ADE.
''' '''
from calibre.ebooks.oeb.base import XPNSMAP, XHTML from calibre.ebooks.oeb.base import XPNSMAP, XHTML, OEB_STYLES
from lxml.etree import XPath as _XPath from lxml.etree import XPath as _XPath
from functools import partial from functools import partial
XPath = partial(_XPath, namespaces=XPNSMAP) XPath = partial(_XPath, namespaces=XPNSMAP)
@ -276,12 +276,6 @@ class EPUBOutput(OutputFormatPlugin):
for tag in XPath('//h:img[@src]')(root): for tag in XPath('//h:img[@src]')(root):
tag.set('src', tag.get('src', '').replace('&', '')) tag.set('src', tag.get('src', '').replace('&', ''))
stylesheet = self.oeb.manifest.hrefs['stylesheet.css']
stylesheet.data.add('a { color: inherit; text-decoration: inherit; '
'cursor: default; }')
stylesheet.data.add('a[href] { color: blue; '
'text-decoration: underline; cursor:pointer; }')
special_chars = re.compile(u'[\u200b\u00ad]') special_chars = re.compile(u'[\u200b\u00ad]')
for elem in root.iterdescendants(): for elem in root.iterdescendants():
if getattr(elem, 'text', False): if getattr(elem, 'text', False):
@ -291,5 +285,19 @@ class EPUBOutput(OutputFormatPlugin):
elem.tail = special_chars.sub('', elem.tail) elem.tail = special_chars.sub('', elem.tail)
elem.tail = elem.tail.replace(u'\u2011', '-') 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:
stylesheet.data.add('a { color: inherit; text-decoration: inherit; '
'cursor: default; }')
stylesheet.data.add('a[href] { color: blue; '
'text-decoration: underline; cursor:pointer; }')
else:
self.oeb.log.warn('No stylesheet found')