mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Only parse the default css stylesheet on demand
This commit is contained in:
parent
e2072ae005
commit
539a4d0355
@ -25,10 +25,17 @@ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, CSS_MIME, OEB_STYLES
|
|||||||
from calibre.ebooks.oeb.base import XPNSMAP, xpath, urlnormalize
|
from calibre.ebooks.oeb.base import XPNSMAP, xpath, urlnormalize
|
||||||
from calibre.ebooks.oeb.profile import PROFILES
|
from calibre.ebooks.oeb.profile import PROFILES
|
||||||
|
|
||||||
html_css = open(P('templates/html.css'), 'rb').read()
|
_html_css_stylesheet = None
|
||||||
|
|
||||||
|
def html_css_stylesheet():
|
||||||
|
global _html_css_stylesheet
|
||||||
|
if _html_css_stylesheet is None:
|
||||||
|
html_css = open(P('templates/html.css'), 'rb').read()
|
||||||
|
_html_css_stylesheet = cssutils.parseString(html_css)
|
||||||
|
_html_css_stylesheet.namespaces['h'] = XHTML_NS
|
||||||
|
return _html_css_stylesheet
|
||||||
|
|
||||||
XHTML_CSS_NAMESPACE = '@namespace "%s";\n' % XHTML_NS
|
XHTML_CSS_NAMESPACE = '@namespace "%s";\n' % XHTML_NS
|
||||||
HTML_CSS_STYLESHEET = cssutils.parseString(html_css)
|
|
||||||
HTML_CSS_STYLESHEET.namespaces['h'] = XHTML_NS
|
|
||||||
|
|
||||||
INHERITED = set(['azimuth', 'border-collapse', 'border-spacing',
|
INHERITED = set(['azimuth', 'border-collapse', 'border-spacing',
|
||||||
'caption-side', 'color', 'cursor', 'direction', 'elevation',
|
'caption-side', 'color', 'cursor', 'direction', 'elevation',
|
||||||
@ -120,7 +127,7 @@ class Stylizer(object):
|
|||||||
item = oeb.manifest.hrefs[path]
|
item = oeb.manifest.hrefs[path]
|
||||||
basename = os.path.basename(path)
|
basename = os.path.basename(path)
|
||||||
cssname = os.path.splitext(basename)[0] + '.css'
|
cssname = os.path.splitext(basename)[0] + '.css'
|
||||||
stylesheets = [HTML_CSS_STYLESHEET]
|
stylesheets = [html_css_stylesheet()]
|
||||||
head = xpath(tree, '/h:html/h:head')
|
head = xpath(tree, '/h:html/h:head')
|
||||||
if head:
|
if head:
|
||||||
head = head[0]
|
head = head[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user