mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ignore unparsable CSS in @style attributes.
This commit is contained in:
parent
3c402a26b0
commit
f65418b92f
@ -17,6 +17,7 @@ import types
|
|||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
from itertools import izip
|
from itertools import izip
|
||||||
|
from xml.dom import SyntaxErr as CSSSyntaxError
|
||||||
import cssutils
|
import cssutils
|
||||||
from cssutils.css import CSSStyleRule, CSSPageRule, CSSStyleDeclaration, \
|
from cssutils.css import CSSStyleRule, CSSPageRule, CSSStyleDeclaration, \
|
||||||
CSSValueList, cssproperties
|
CSSValueList, cssproperties
|
||||||
@ -291,11 +292,15 @@ class Style(object):
|
|||||||
|
|
||||||
def _apply_style_attr(self):
|
def _apply_style_attr(self):
|
||||||
attrib = self._element.attrib
|
attrib = self._element.attrib
|
||||||
if 'style' in attrib:
|
if 'style' not in attrib:
|
||||||
css = attrib['style'].split(';')
|
return
|
||||||
css = filter(None, map(lambda x: x.strip(), css))
|
css = attrib['style'].split(';')
|
||||||
|
css = filter(None, (x.strip() for x in css))
|
||||||
|
try:
|
||||||
style = CSSStyleDeclaration('; '.join(css))
|
style = CSSStyleDeclaration('; '.join(css))
|
||||||
self._style.update(self._stylizer.flatten_style(style))
|
except CSSSyntaxError:
|
||||||
|
return
|
||||||
|
self._style.update(self._stylizer.flatten_style(style))
|
||||||
|
|
||||||
def _has_parent(self):
|
def _has_parent(self):
|
||||||
return (self._element.getparent() is not None)
|
return (self._element.getparent() is not None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user