E-book viewer: Fix regression in handling of <br> tags. Fixes #3945 (Ebook-viewer/EPUB Line-spacing problem with Hard Line Breaks)

This commit is contained in:
Kovid Goyal 2009-11-06 08:59:06 -07:00
parent 72ceac8117
commit 51e95261e2

View File

@ -458,6 +458,12 @@ class DocumentView(QWebView):
def path(self):
return os.path.abspath(unicode(self.url().toLocalFile()))
def self_closing_sub(self, match):
tag = match.group(1)
if tag.lower().strip() == 'br':
return match.group()
return '<%s %s></%s>'%(match.group(1), match.group(2), match.group(1))
def load_path(self, path, pos=0.0):
self.initial_pos = pos
mt = getattr(path, 'mime_type', None)
@ -466,7 +472,7 @@ class DocumentView(QWebView):
html = open(path, 'rb').read().decode(path.encoding, 'replace')
html = EntityDeclarationProcessor(html).processed_html
if 'xhtml' in mt:
html = self.self_closing_pat.sub(r'<\1 \2></\1>', html)
html = self.self_closing_pat.sub(self.self_closing_sub, html)
#self.setContent(QByteArray(html.encode(path.encoding)), mt, QUrl.fromLocalFile(path))
self.setHtml(html, QUrl.fromLocalFile(path))
self.turn_off_internal_scrollbars()