Insert metadata as jacket page: Make the invisible tags used for searching across books format better, by giving them their own table row.

This commit is contained in:
Kovid Goyal 2014-10-23 10:51:55 +05:30
parent 9b5a4fd9fb
commit 9c93a6e06b
4 changed files with 9 additions and 26 deletions

View File

@ -36,6 +36,7 @@
{tags.alphabetical} -->
<td class="cbj_content">{tags}</td>
</tr>
<tr data-calibre-jacket-searchable-tags="1" style="color:white; display:none"><td colspan="2">{searchable_tags}</td></tr>
</table>
<div class="cbj_footer">{footer}</div>
</div>

View File

@ -263,10 +263,6 @@ class OutputProfile(Plugin):
#: Special periodical formatting needed in EPUB
epub_periodical_format = None
@classmethod
def tags_to_string(cls, tags):
from xml.sax.saxutils import escape
return escape(', '.join(tags))
class iPadOutput(OutputProfile):
@ -645,11 +641,6 @@ class KindleOutput(OutputProfile):
mobi_ems_per_blockquote = 2.0
@classmethod
def tags_to_string(cls, tags):
return u'%s <br/><span style="color:white">%s</span>' % (', '.join(tags),
'ttt '.join(tags)+'ttt ')
class KindleDXOutput(OutputProfile):
name = 'Kindle DX'
@ -667,11 +658,6 @@ class KindleDXOutput(OutputProfile):
ratings_char = u'\u2605'
mobi_ems_per_blockquote = 2.0
@classmethod
def tags_to_string(cls, tags):
return u'%s <br/><span style="color: white">%s</span>' % (', '.join(tags),
'ttt '.join(tags)+'ttt ')
class KindlePaperWhiteOutput(KindleOutput):
name = 'Kindle PaperWhite'
@ -706,12 +692,6 @@ class KindleFireOutput(KindleDXOutput):
dpi = 169.0
comic_screen_size = (570, 1016)
@classmethod
def tags_to_string(cls, tags):
# The idiotic fire doesn't obey the color:white directive
from xml.sax.saxutils import escape
return escape(', '.join(tags))
class IlliadOutput(OutputProfile):
name = 'Illiad'

View File

@ -310,8 +310,8 @@ class MobiMLizer(object):
return
style = stylizer.style(elem)
# <mbp:frame-set/> does not exist lalalala
if style['display'] in ('none', 'oeb-page-head', 'oeb-page-foot') \
or style['visibility'] == 'hidden':
if ((style['display'] in ('none', 'oeb-page-head', 'oeb-page-foot') or style['visibility'] == 'hidden') and
elem.get('data-calibre-jacket-searchable-tags', None) != '1'):
id_ = elem.get('id', None)
if id_:
# Keep anchors so people can use display:none

View File

@ -159,9 +159,10 @@ class Series(unicode):
class Tags(unicode):
def __new__(self, tags, output_profile):
tags = tags or ()
t = unicode.__new__(self, output_profile.tags_to_string(tags))
t.alphabetical = output_profile.tags_to_string(sorted(tags, key=sort_key))
tags = [escape(x) for x in tags or ()]
t = unicode.__new__(self, ', '.join(tags))
t.alphabetical = ', '.join(sorted(tags, key=sort_key))
t.tags_list = tags
return t
def render_jacket(mi, output_profile,
@ -217,7 +218,8 @@ def render_jacket(mi, output_profile,
rating_label=_('Rating'), rating=rating,
tags_label=_('Tags'), tags=tags,
comments=comments,
footer=''
footer='',
searchable_tags=' '.join(escape(t)+'ttt' for t in tags.tags_list),
)
for key in mi.custom_field_keys():
try: