Fix handling of comments in the jacket template

This commit is contained in:
Kovid Goyal 2011-11-19 14:52:57 +05:30
parent 2d6d6eb76f
commit 055b17c68a
2 changed files with 13 additions and 4 deletions

View File

@ -38,9 +38,12 @@
<hr class="cbj_kindle_banner_hr" />
<!--
In addition you can add code to show the values of custom columns here.
The value is available as _column_name and the title as _column_name_label.
For example, if you have a custom column with label #genre, you can add it to
this template with _genre_label and _genre. Note that the # is replaced by an underscore.
The value is available as _column_name and the title as
_column_name_label. For example, if you have a custom column with
label #genre, you can add it to this template with _genre_label and
_genre. Note that the # is replaced by an underscore. For example
<div><b>{_genre_label}:</b> {_genre}</div>
-->
<div class="cbj_comments">{comments}</div>

View File

@ -16,6 +16,7 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup
from calibre.ebooks.oeb.base import XPath, XHTML_NS, XHTML
from calibre.library.comments import comments_to_html
from calibre.utils.date import is_date_undefined
from calibre.ebooks.chardet import strip_encoding_declarations
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
@ -180,10 +181,14 @@ def render_jacket(mi, output_profile,
except:
pass
args['_genre_label'] = args.get('_genre_label', '')
args['_genre'] = args.get('_genre', '')
generated_html = P('jacket/template.xhtml',
data=True).decode('utf-8').format(**args)
# Post-process the generated html to strip out empty header items
soup = BeautifulSoup(generated_html)
if not series:
series_tag = soup.find(attrs={'class':'cbj_series'})
@ -206,7 +211,8 @@ def render_jacket(mi, output_profile,
if hr_tag is not None:
hr_tag.extract()
return soup.renderContents(None)
return strip_encoding_declarations(
soup.renderContents('utf-8').decode('utf-8'))
from calibre.ebooks.oeb.base import RECOVER_PARSER