diff --git a/src/calibre/srv/metadata.py b/src/calibre/srv/metadata.py index 782bcbcccb..23eb18e9d8 100644 --- a/src/calibre/srv/metadata.py +++ b/src/calibre/srv/metadata.py @@ -12,7 +12,6 @@ from functools import partial from threading import Lock from urllib import quote -from calibre import prepare_string_for_xml from calibre.constants import config_dir from calibre.db.categories import Tag from calibre.ebooks.metadata.sources.identify import urls_from_identifiers @@ -41,6 +40,7 @@ def encode_datetime(dateval): empty_val = ((), '', {}) +passthrough_comment_types = {'long-text', 'short-text'} def add_field(field, db, book_id, ans, field_metadata): @@ -56,11 +56,7 @@ def add_field(field, db, book_id, ans, field_metadata): ctype = field_metadata.get('display', {}).get('interpret_as', 'html') if ctype == 'markdown': val = markdown(val) - elif ctype == 'long-text': - val = '
%s
' % prepare_string_for_xml(val) - elif ctype == 'short-text': - val = '%s' % prepare_string_for_xml(val) - else: + elif ctype not in passthrough_comment_types: val = comments_to_html(val) elif datatype == 'composite' and field_metadata['display'].get('contains_html'): val = comments_to_html(val) diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index 81a015d62b..7d9d180748 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -144,7 +144,7 @@ def render_metadata(mi, table, book_id, field_list=None): # {{{ table.lastChild.lastChild.appendChild(document.createTextNode(v)) table.appendChild(E.tr(E.td(name + ':'), E.td())) - if is_html: + if is_html and /[<>]/.test(val + ''): table.lastChild.lastChild.appendChild(adjusting_sandboxed_html(val + '')) else: if not join: @@ -154,6 +154,7 @@ def render_metadata(mi, table, book_id, field_list=None): # {{{ add_val(v) if v is not val[-1]: table.lastChild.lastChild.appendChild(document.createTextNode(join)) + return table.lastChild.lastChild def process_composite(field, fm, name, val): if fm.display and fm.display.contains_html: @@ -243,10 +244,26 @@ def render_metadata(mi, table, book_id, field_list=None): # {{{ datatype = fm.datatype val = mi[field] if field is 'comments' or datatype is 'comments': - if fm.display?.heading_position is 'side': + if not val: + return + ias = fm.display?.interpret_as or 'html' + hp = fm.display?.heading_position or 'hide' + if ias is 'long-text': + if hp is 'side': + add_row(name, val).style.whiteSpace = 'pre-wrap' + return + val = E.pre(val, style='white-space:pre-wrap').outerHTML + elif ias is 'short-text': + if hp is 'side': + add_row(name, val) + return + val = E.span(val).outerHTML + if hp is 'side': add_row(name, val, is_html=True) - else: - comments[field] = val + return + if hp is 'above': + val = E.h3(name).outerHTML + val + comments[field] = val return func = None if datatype is 'composite':