Fix rendering of long text fields that are to be interpeted as short text or plain text

Also fix rendering of "above" comment headings not working
This commit is contained in:
Kovid Goyal 2017-05-19 08:22:51 +05:30
parent d09f7605f1
commit 3fbddc692e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 23 additions and 10 deletions

View File

@ -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 = '<pre style="white-space:pre-wrap">%s</pre>' % prepare_string_for_xml(val)
elif ctype == 'short-text':
val = '<span">%s</span>' % 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)

View File

@ -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':