mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2666 (zipped html can't be converted to epub - failing on css values)
This commit is contained in:
parent
32b024475e
commit
2abf0d2f0e
@ -217,7 +217,7 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
Perform various markup transforms to get the output to render correctly
|
||||
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 functools import partial
|
||||
XPath = partial(_XPath, namespaces=XPNSMAP)
|
||||
@ -276,12 +276,6 @@ class EPUBOutput(OutputFormatPlugin):
|
||||
for tag in XPath('//h:img[@src]')(root):
|
||||
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]')
|
||||
for elem in root.iterdescendants():
|
||||
if getattr(elem, 'text', False):
|
||||
@ -291,5 +285,19 @@ 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:
|
||||
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')
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user