mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:Allow extra_css to override template styles
This commit is contained in:
parent
102aa48708
commit
94b3ba12f8
@ -103,12 +103,15 @@ Pre/post processing of downloaded HTML
|
|||||||
|
|
||||||
.. automember:: BasicNewsRecipe.preprocess_regexps
|
.. automember:: BasicNewsRecipe.preprocess_regexps
|
||||||
|
|
||||||
|
.. automember:: BasicNewsRecipe.template_css
|
||||||
|
|
||||||
.. automethod:: BasicNewsRecipe.preprocess_html
|
.. automethod:: BasicNewsRecipe.preprocess_html
|
||||||
|
|
||||||
.. automethod:: BasicNewsRecipe.postprocess_html
|
.. automethod:: BasicNewsRecipe.postprocess_html
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Convenience methods
|
Convenience methods
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -206,6 +206,32 @@ class BasicNewsRecipe(object, LoggingInterface):
|
|||||||
#: will remove everythong from `<!--Article ends here-->` to `</body>`.
|
#: will remove everythong from `<!--Article ends here-->` to `</body>`.
|
||||||
preprocess_regexps = []
|
preprocess_regexps = []
|
||||||
|
|
||||||
|
#: The CSS that is used to styles the templates, i.e., the navigation bars and
|
||||||
|
#: the Tables of Contents. Rather than overriding this variable, you should
|
||||||
|
#: use :member:`extra_css` in your recipe to customize look and feel.
|
||||||
|
template_css = u'''
|
||||||
|
.article_date {
|
||||||
|
font-size: x-small; color: gray; font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article_description {
|
||||||
|
font-size: small; font-family: sans; text-indent: 0pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.article {
|
||||||
|
font-weight: bold; font-size: large;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.feed {
|
||||||
|
font-weight: bold; font-size: large;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar {
|
||||||
|
font-family:monospace; font-size:8pt
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
# See the built-in profiles for examples of these settings.
|
# See the built-in profiles for examples of these settings.
|
||||||
|
|
||||||
def get_cover_url(self):
|
def get_cover_url(self):
|
||||||
@ -471,11 +497,13 @@ class BasicNewsRecipe(object, LoggingInterface):
|
|||||||
|
|
||||||
|
|
||||||
def _postprocess_html(self, soup, first_fetch, job_info):
|
def _postprocess_html(self, soup, first_fetch, job_info):
|
||||||
if self.extra_css is not None:
|
head = soup.find('head')
|
||||||
head = soup.find('head')
|
if not head:
|
||||||
if head:
|
head = soup.find('body')
|
||||||
style = BeautifulSoup(u'<style type="text/css" title="override_css">%s</style>'%self.extra_css).find('style')
|
if not head:
|
||||||
head.insert(len(head.contents), style)
|
head = soup.find(True)
|
||||||
|
style = BeautifulSoup(u'<style type="text/css" title="override_css">%s</style>'%(self.template_css +'\n\n'+self.extra_css)).find('style')
|
||||||
|
head.insert(len(head.contents), style)
|
||||||
if first_fetch and job_info:
|
if first_fetch and job_info:
|
||||||
url, f, a, feed_len = job_info
|
url, f, a, feed_len = job_info
|
||||||
body = soup.find('body')
|
body = soup.find('body')
|
||||||
|
@ -8,28 +8,9 @@ from calibre import preferred_encoding, strftime
|
|||||||
|
|
||||||
class Template(MarkupTemplate):
|
class Template(MarkupTemplate):
|
||||||
|
|
||||||
STYLE = u'''\
|
|
||||||
.article_date {
|
|
||||||
font-size: x-small; color: gray; font-family: monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
.article_description {
|
|
||||||
font-size: small; font-family: sans; text-indent: 0pt;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.article {
|
|
||||||
font-weight: bold; font-size: large;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.feed {
|
|
||||||
font-weight: bold; font-size: large;
|
|
||||||
}
|
|
||||||
|
|
||||||
'''
|
|
||||||
|
|
||||||
def generate(self, *args, **kwargs):
|
def generate(self, *args, **kwargs):
|
||||||
if not kwargs.has_key('style'):
|
if not kwargs.has_key('style'):
|
||||||
kwargs['style'] = self.STYLE
|
kwargs['style'] = ''
|
||||||
for key in kwargs.keys():
|
for key in kwargs.keys():
|
||||||
if isinstance(kwargs[key], basestring) and not isinstance(kwargs[key], unicode):
|
if isinstance(kwargs[key], basestring) and not isinstance(kwargs[key], unicode):
|
||||||
kwargs[key] = unicode(kwargs[key], 'utf-8', 'replace')
|
kwargs[key] = unicode(kwargs[key], 'utf-8', 'replace')
|
||||||
@ -52,7 +33,7 @@ class NavBarTemplate(Template):
|
|||||||
|
|
||||||
>
|
>
|
||||||
<body>
|
<body>
|
||||||
<div class="navbar" style="text-align:${'center' if center else 'left'}; font-family:monospace; font-size:8pt">
|
<div class="navbar" style="text-align:${'center' if center else 'left'};">
|
||||||
<hr py:if="bottom" />
|
<hr py:if="bottom" />
|
||||||
<p py:if="bottom" style="text-align:left">
|
<p py:if="bottom" style="text-align:left">
|
||||||
This article was downloaded by <b>${__appname__}</b> from <a href="${url}">${url}</a>
|
This article was downloaded by <b>${__appname__}</b> from <a href="${url}">${url}</a>
|
||||||
@ -104,7 +85,7 @@ class IndexTemplate(Template):
|
|||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<title>${title}</title>
|
<title>${title}</title>
|
||||||
<style type="text/css">
|
<style py:if="style" type="text/css">
|
||||||
${style}
|
${style}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@ -144,7 +125,7 @@ class FeedTemplate(Template):
|
|||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<title>${feed.title}</title>
|
<title>${feed.title}</title>
|
||||||
<style type="text/css">
|
<style py:if="style" type="text/css">
|
||||||
${style}
|
${style}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user