Conversion: Fix the word @page in a comment inside a stylesheet with no following {} causing the rest of the stylesheet to be ignored.

This commit is contained in:
Kovid Goyal 2014-08-09 09:25:57 +05:30
parent 2d9d124fd6
commit 8ba51d0303
3 changed files with 6 additions and 3 deletions

View file

@ -282,7 +282,6 @@ def __call__(self, html, format, length=1):
class CSSPreProcessor(object):
PAGE_PAT = re.compile(r'@page[^{]*?{[^}]*?}')
# Remove some of the broken CSS Microsoft products
# create
MS_PAT = re.compile(r'''
@ -304,7 +303,6 @@ def ms_sub(self, match):
def __call__(self, data, add_namespace=False):
from calibre.ebooks.oeb.base import XHTML_CSS_NAMESPACE
data = self.PAGE_PAT.sub('', data)
data = self.MS_PAT.sub(self.ms_sub, data)
if not add_namespace:
return data

View file

@ -913,6 +913,7 @@ def _parse_txt(self, data):
def _parse_css(self, data):
from cssutils import CSSParser, log, resolveImports
from cssutils.css import CSSRule
log.setLevel(logging.WARN)
log.raiseExceptions = False
self.oeb.log.debug('Parsing', self.href, '...')
@ -924,6 +925,8 @@ def _parse_css(self, data):
data = parser.parseString(data, href=self.href, validate=False)
data = resolveImports(data)
data.namespaces['h'] = XHTML_NS
for rule in tuple(data.cssRules.rulesOfType(CSSRule.PAGE_RULE)):
data.cssRules.remove(rule)
return data
def _fetch_css(self, path):

View file

@ -12,7 +12,7 @@
from weakref import WeakKeyDictionary
from xml.dom import SyntaxErr as CSSSyntaxError
from cssutils.css import (CSSStyleRule, CSSPageRule, CSSFontFaceRule,
cssproperties)
cssproperties, CSSRule)
from cssutils import (profile as cssprofiles, parseString, parseStyle, log as
cssutils_log, CSSParser, profiles, replaceUrls)
from lxml import etree
@ -216,6 +216,8 @@ def __init__(self, tree, path, oeb, opts, profile=None,
self.logger.warn('CSS @import of non-CSS file %r' % rule.href)
continue
stylesheets.append(sitem.data)
for rule in tuple(stylesheet.cssRules.rulesOfType(CSSRule.PAGE_RULE)):
stylesheet.cssRules.remove(rule)
# Make links to resources absolute, since these rules will
# be folded into a stylesheet at the root
replaceUrls(stylesheet, item.abshref,