mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement --extra-css
This commit is contained in:
parent
6ec37ff715
commit
b34854b6e4
@ -116,6 +116,7 @@ def add_pipeline_options(parser, plumber):
|
||||
'font_size_mapping',
|
||||
'line_height',
|
||||
'linearize_tables',
|
||||
'extra_css',
|
||||
]
|
||||
),
|
||||
|
||||
|
@ -219,6 +219,14 @@ OptionRecommendation(name='chapter_mark',
|
||||
'to mark chapters.')
|
||||
),
|
||||
|
||||
OptionRecommendation(name='extra_css',
|
||||
recommended_value=None, level=OptionRecommendation.LOW,
|
||||
help=_('Either the path to a CSS stylesheet or raw CSS. '
|
||||
'This CSS will be appended to the style rules from '
|
||||
'the source file, so it can be used to override those '
|
||||
'rules.')
|
||||
),
|
||||
|
||||
|
||||
|
||||
OptionRecommendation(name='read_metadata_from_opf',
|
||||
@ -487,6 +495,9 @@ OptionRecommendation(name='language',
|
||||
else:
|
||||
fkey = map(float, fkey.split(','))
|
||||
|
||||
if self.opts.extra_css and os.path.exists(self.opts.extra_css):
|
||||
self.opts.extra_css = open(self.opts.extra_css, 'rb').read()
|
||||
|
||||
flattener = CSSFlattener(fbase=fbase, fkey=fkey,
|
||||
lineh=self.opts.line_height,
|
||||
untable=self.opts.linearize_tables)
|
||||
|
@ -106,7 +106,7 @@ class CSSSelector(etree.XPath):
|
||||
class Stylizer(object):
|
||||
STYLESHEETS = WeakKeyDictionary()
|
||||
|
||||
def __init__(self, tree, path, oeb, profile=PROFILES['PRS505']):
|
||||
def __init__(self, tree, path, oeb, profile=PROFILES['PRS505'], extra_css=''):
|
||||
self.oeb = oeb
|
||||
self.profile = profile
|
||||
self.logger = oeb.logger
|
||||
@ -135,6 +135,11 @@ class Stylizer(object):
|
||||
(path, item.href))
|
||||
continue
|
||||
stylesheets.append(sitem.data)
|
||||
if extra_css:
|
||||
text = XHTML_CSS_NAMESPACE + extra_css
|
||||
stylesheet = parser.parseString(text, href=cssname)
|
||||
stylesheet.namespaces['h'] = XHTML_NS
|
||||
stylesheets.append(stylesheet)
|
||||
rules = []
|
||||
index = 0
|
||||
self.stylesheets = set()
|
||||
|
@ -116,7 +116,8 @@ class CSSFlattener(object):
|
||||
profile = self.context.source
|
||||
for item in self.oeb.spine:
|
||||
html = item.data
|
||||
stylizer = Stylizer(html, item.href, self.oeb, profile)
|
||||
stylizer = Stylizer(html, item.href, self.oeb, profile,
|
||||
extra_css=self.context.extra_css)
|
||||
self.stylizers[item] = stylizer
|
||||
|
||||
def baseline_node(self, node, stylizer, sizes, csize):
|
||||
|
Loading…
x
Reference in New Issue
Block a user