From 26a9b30db1ae5e430c8857661a976dbf5e78a3e8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 May 2013 23:07:25 +0530 Subject: [PATCH] ToC Editor: handle files with

inside ToC Editor: Handle ebooks that have

tags inside the tags. Instead of erroring out, the

tags are automatically moved into . Fixes #1186298 [Problem with the Edit ToC feature](https://bugs.launchpad.net/calibre/+bug/1186298) --- src/calibre/gui2/toc/location.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/toc/location.py b/src/calibre/gui2/toc/location.py index 6636079732..58f69ea159 100644 --- a/src/calibre/gui2/toc/location.py +++ b/src/calibre/gui2/toc/location.py @@ -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,