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

View File

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

View File

@ -12,7 +12,7 @@ import os, re, logging, copy, unicodedata
from weakref import WeakKeyDictionary from weakref import WeakKeyDictionary
from xml.dom import SyntaxErr as CSSSyntaxError from xml.dom import SyntaxErr as CSSSyntaxError
from cssutils.css import (CSSStyleRule, CSSPageRule, CSSFontFaceRule, from cssutils.css import (CSSStyleRule, CSSPageRule, CSSFontFaceRule,
cssproperties) cssproperties, CSSRule)
from cssutils import (profile as cssprofiles, parseString, parseStyle, log as from cssutils import (profile as cssprofiles, parseString, parseStyle, log as
cssutils_log, CSSParser, profiles, replaceUrls) cssutils_log, CSSParser, profiles, replaceUrls)
from lxml import etree from lxml import etree
@ -216,6 +216,8 @@ class Stylizer(object):
self.logger.warn('CSS @import of non-CSS file %r' % rule.href) self.logger.warn('CSS @import of non-CSS file %r' % rule.href)
continue continue
stylesheets.append(sitem.data) 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 # Make links to resources absolute, since these rules will
# be folded into a stylesheet at the root # be folded into a stylesheet at the root
replaceUrls(stylesheet, item.abshref, replaceUrls(stylesheet, item.abshref,