mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Conversion: When inserting a metadata jacket, format the series number
using roman numerals. This behavior can be disabled by using a custom jacket template, as described here: http://manual.calibre-ebook.com/customize.html#overriding-icons-templates-et-cetera See #1342916 (Roman Numerals not show on book jacket)
This commit is contained in:
parent
f4f77827e7
commit
302d131ec2
@ -11,7 +11,9 @@
|
|||||||
<td class="cbj_title" colspan="2">{title}</td>
|
<td class="cbj_title" colspan="2">{title}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="cbj_series" colspan="2">{series}</td>
|
<!-- If you do not want the series number to be formatted using roman numerals
|
||||||
|
change {series.roman} to {series} -->
|
||||||
|
<td class="cbj_series" colspan="2">{series.roman}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="cbj_author" colspan="2">{author}</td>
|
<td class="cbj_author" colspan="2">{author}</td>
|
||||||
|
@ -19,6 +19,7 @@ from calibre.ebooks.oeb.base import XPath, XHTML_NS, XHTML, xml2text, urldefrag
|
|||||||
from calibre.library.comments import comments_to_html
|
from calibre.library.comments import comments_to_html
|
||||||
from calibre.utils.date import is_date_undefined
|
from calibre.utils.date import is_date_undefined
|
||||||
from calibre.ebooks.chardet import strip_encoding_declarations
|
from calibre.ebooks.chardet import strip_encoding_declarations
|
||||||
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
|
|
||||||
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
||||||
|
|
||||||
@ -142,10 +143,23 @@ def get_rating(rating, rchar, e_rchar):
|
|||||||
ans = ("%s%s") % (rchar * int(num), e_rchar * (5 - int(num)))
|
ans = ("%s%s") % (rchar * int(num), e_rchar * (5 - int(num)))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
class Series(unicode):
|
||||||
|
|
||||||
|
def __new__(self, series, series_index):
|
||||||
|
series = roman = escape(series or u'')
|
||||||
|
if series and series_index is not None:
|
||||||
|
roman = _('Book {1} of <em>{0}</em>').format(
|
||||||
|
escape(series), escape(fmt_sidx(series_index, use_roman=True)))
|
||||||
|
series = escape(series + ' [%s]'%fmt_sidx(series_index, use_roman=False))
|
||||||
|
s = unicode.__new__(self, series)
|
||||||
|
s.roman = roman
|
||||||
|
return s
|
||||||
|
|
||||||
def render_jacket(mi, output_profile,
|
def render_jacket(mi, output_profile,
|
||||||
alt_title=_('Unknown'), alt_tags=[], alt_comments='',
|
alt_title=_('Unknown'), alt_tags=[], alt_comments='',
|
||||||
alt_publisher=(''), rescale_fonts=False):
|
alt_publisher=(''), rescale_fonts=False):
|
||||||
css = P('jacket/stylesheet.css', data=True).decode('utf-8')
|
css = P('jacket/stylesheet.css', data=True).decode('utf-8')
|
||||||
|
template = P('jacket/template.xhtml', data=True).decode('utf-8')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
title_str = mi.title if mi.title else alt_title
|
title_str = mi.title if mi.title else alt_title
|
||||||
@ -153,12 +167,7 @@ def render_jacket(mi, output_profile,
|
|||||||
title_str = _('Unknown')
|
title_str = _('Unknown')
|
||||||
title = '<span class="title">%s</span>' % (escape(title_str))
|
title = '<span class="title">%s</span>' % (escape(title_str))
|
||||||
|
|
||||||
series = escape(mi.series if mi.series else '')
|
series = Series(mi.series, mi.series_index)
|
||||||
if mi.series and mi.series_index is not None:
|
|
||||||
series += escape(' [%s]'%mi.format_series_index())
|
|
||||||
if not mi.series:
|
|
||||||
series = ''
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
publisher = mi.publisher if mi.publisher else alt_publisher
|
publisher = mi.publisher if mi.publisher else alt_publisher
|
||||||
except:
|
except:
|
||||||
@ -227,8 +236,7 @@ def render_jacket(mi, output_profile,
|
|||||||
args['_genre'] = args.get('_genre', '{_genre}')
|
args['_genre'] = args.get('_genre', '{_genre}')
|
||||||
|
|
||||||
formatter = SafeFormatter()
|
formatter = SafeFormatter()
|
||||||
generated_html = formatter.format(P('jacket/template.xhtml',
|
generated_html = formatter.format(template, **args)
|
||||||
data=True).decode('utf-8'), **args)
|
|
||||||
|
|
||||||
# Post-process the generated html to strip out empty header items
|
# Post-process the generated html to strip out empty header items
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user