mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ToC Editor: handle files with <p> inside <head>
ToC Editor: Handle ebooks that have <p> tags inside the <head> tags. Instead of erroring out, the <p> tags are automatically moved into <body>. Fixes #1186298 [Problem with the Edit ToC feature](https://bugs.launchpad.net/calibre/+bug/1186298)
This commit is contained in:
parent
d930de8753
commit
26a9b30db1
@ -226,7 +226,16 @@ class ItemEdit(QWidget):
|
||||
name = self.current_name = unicode(item.data(Qt.DisplayRole).toString())
|
||||
path = self.container.name_to_abspath(name)
|
||||
# Ensure encoding map is populated
|
||||
self.container.parsed(name)
|
||||
root = self.container.parsed(name)
|
||||
nasty = root.xpath('//*[local-name()="head"]/*[local-name()="p"]')
|
||||
if nasty:
|
||||
body = root.xpath('//*[local-name()="body"]')
|
||||
if not body:
|
||||
return error_dialog(self, _('Bad markup'),
|
||||
_('This book has severely broken markup, it\'s ToC cannot be edited.'), show=True)
|
||||
for x in reversed(nasty):
|
||||
body[0].insert(0, x)
|
||||
self.container.commit_item(name, keep_parsed=True)
|
||||
encoding = self.container.encoding_map.get(name, None) or 'utf-8'
|
||||
|
||||
load_html(path, self.view, codec=encoding,
|
||||
|
Loading…
x
Reference in New Issue
Block a user