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:
Kovid Goyal 2013-05-31 23:07:25 +05:30
parent d930de8753
commit 26a9b30db1

View File

@ -226,7 +226,16 @@ class ItemEdit(QWidget):
name = self.current_name = unicode(item.data(Qt.DisplayRole).toString()) name = self.current_name = unicode(item.data(Qt.DisplayRole).toString())
path = self.container.name_to_abspath(name) path = self.container.name_to_abspath(name)
# Ensure encoding map is populated # 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' encoding = self.container.encoding_map.get(name, None) or 'utf-8'
load_html(path, self.view, codec=encoding, load_html(path, self.view, codec=encoding,