From 9473599b2889002bc130df7562a9e2673c4ede77 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 Jan 2023 14:06:02 +0530 Subject: [PATCH] Book details panel: Fix HTML comment tags in the comments breaking display of book details. Fixes #2000881 [Description Format Breaking Book View Display](https://bugs.launchpad.net/calibre/+bug/2000881) Apparently QTextBrowser flakes out when it sees comments. --- src/calibre/gui2/book_details.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 3971129a4a..8e6628af25 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -5,7 +5,7 @@ import os import re from collections import namedtuple -from functools import partial +from functools import partial, lru_cache from qt.core import ( QAction, QApplication, QClipboard, QColor, QDialog, QEasingCurve, QIcon, QKeySequence, QMenu, QMimeData, QPainter, QPen, QPixmap, QSplitter, @@ -197,6 +197,11 @@ def init_find_in_grouped_search(menu, field, value, book_info): '{}:"={}"'.format(g, value.replace('"', r'\"')), '')) +@lru_cache(maxsize=2) +def comments_pat(): + return re.compile(r'', re.DOTALL) + + def render_html(mi, vertical, widget, all_fields=False, render_data_func=None, pref_name='book_display_fields'): # {{{ from calibre.gui2.ui import get_gui func = render_data_func or partial(render_data, @@ -227,6 +232,8 @@ def render_html(mi, vertical, widget, all_fields=False, render_data_func=None, p comments = '' if comment_fields: comments = '\n'.join('
%s
' % x for x in comment_fields) + # Comments cause issues with rendering in QTextBrowser + comments = comments_pat().sub('', comments) right_pane = comments if vertical: