mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
EPUB output: Strip any @page rules from input CSS as they are almost always unsuitable for reader devices.
This commit is contained in:
parent
28733939cd
commit
e95bbf5ec2
@ -528,6 +528,7 @@ class Processor(Parser):
|
|||||||
|
|
||||||
LINKS_PATH = XPath('//a[@href]')
|
LINKS_PATH = XPath('//a[@href]')
|
||||||
PIXEL_PAT = re.compile(r'([-]?\d+|[-]?\d*\.\d+)px')
|
PIXEL_PAT = re.compile(r'([-]?\d+|[-]?\d*\.\d+)px')
|
||||||
|
PAGE_PAT = re.compile(r'@page[^{]*?{[^}]*?}')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
Parser.__init__(self, *args, **kwargs)
|
Parser.__init__(self, *args, **kwargs)
|
||||||
@ -697,7 +698,9 @@ class Processor(Parser):
|
|||||||
return ''
|
return ''
|
||||||
return '%fpt'%(72 * val/dpi)
|
return '%fpt'%(72 * val/dpi)
|
||||||
|
|
||||||
return cls.PIXEL_PAT.sub(rescale, css)
|
css = cls.PIXEL_PAT.sub(rescale, css)
|
||||||
|
css = cls.PAGE_PAT.sub('', css)
|
||||||
|
return css
|
||||||
|
|
||||||
def extract_css(self, parsed_sheets):
|
def extract_css(self, parsed_sheets):
|
||||||
'''
|
'''
|
||||||
@ -732,8 +735,13 @@ class Processor(Parser):
|
|||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
self.log_error('Failed to open stylesheet: %s'%file)
|
self.log_error('Failed to open stylesheet: %s'%file)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
try:
|
try:
|
||||||
parsed_sheets[file] = self.css_parser.parseString(css)
|
parsed_sheets[file] = self.css_parser.parseString(css)
|
||||||
|
except ValueError:
|
||||||
|
parsed_sheets[file] = \
|
||||||
|
self.css_parser.parseString(\
|
||||||
|
css.decode('utf8', 'replace'))
|
||||||
except:
|
except:
|
||||||
parsed_sheets[file] = css.decode('utf8', 'replace')
|
parsed_sheets[file] = css.decode('utf8', 'replace')
|
||||||
self.log_warning('Failed to parse stylesheet: %s'%file)
|
self.log_warning('Failed to parse stylesheet: %s'%file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user