From 26f61556d111f97da3612df01c71e9c3c8990397 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 18 Jul 2017 11:48:21 +0530 Subject: [PATCH] Make foreground color of sandboxed html in the book list the same as the theme color --- src/pyj/book_list/custom_list.pyj | 4 ++-- src/pyj/book_list/details_list.pyj | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pyj/book_list/custom_list.pyj b/src/pyj/book_list/custom_list.pyj index fc339e3961..632e7d76f6 100644 --- a/src/pyj/book_list/custom_list.pyj +++ b/src/pyj/book_list/custom_list.pyj @@ -6,7 +6,7 @@ from __python__ import bound_methods, hash_literals from elementmaker import E from gettext import gettext as _ -from book_list.details_list import THUMBNAIL_MAX_HEIGHT +from book_list.details_list import THUMBNAIL_MAX_HEIGHT, sandbox_css from book_list.library_data import library_data from date import format_date from dom import build_rule, clear, set_css, svgicon @@ -234,7 +234,7 @@ def render_template_text(template, book_id, metadata): html += f'
{val}
' if html: - comments = sandboxed_html(html, 'html { overflow: hidden }') + comments = sandboxed_html(html, sandbox_css()) ans.appendChild(comments) return ans diff --git a/src/pyj/book_list/details_list.pyj b/src/pyj/book_list/details_list.pyj index 64176b1c11..aae8df26a3 100644 --- a/src/pyj/book_list/details_list.pyj +++ b/src/pyj/book_list/details_list.pyj @@ -5,9 +5,10 @@ from __python__ import bound_methods, hash_literals from elementmaker import E from gettext import gettext as _ +from book_list.theme import get_color from dom import build_rule, clear, set_css, svgicon from session import get_interface_data -from utils import fmt_sidx, sandboxed_html, safe_set_inner_html +from utils import fmt_sidx, safe_set_inner_html, sandboxed_html DETAILS_LIST_CLASS = 'book-list-details-list' ITEM_CLASS = DETAILS_LIST_CLASS + '-item' @@ -62,6 +63,12 @@ def on_img_load(img, load_type): set_css(div, border='dashed 1px currentColor', border_radius=BORDER_RADIUS+'px') +def sandbox_css(): + if not sandbox_css.ans: + sandbox_css.ans = 'html {{ overflow: hidden; color: {} }}'.format(get_color('window-foreground')) + return sandbox_css.ans + + def create_item(book_id, metadata, create_image, show_book_details): authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown') img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load) @@ -69,7 +76,7 @@ def create_item(book_id, metadata, create_image, show_book_details): img.dataset.title, img.dataset.authors = metadata.title, authors img_div = E.div(img, class_='details-list-left') extra_data = E.div() - comments = sandboxed_html(metadata.comments, 'html { overflow: hidden }') + comments = sandboxed_html(metadata.comments, sandbox_css()) if not metadata.comments: comments.style.display = 'none' comments.style.marginTop = '1ex'