Better error message when ToC editor is opened to an non-HTML file

This commit is contained in:
Kovid Goyal 2024-12-31 09:10:40 +05:30
parent 392b5f5771
commit b388a91180
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -397,6 +397,8 @@ class ItemEdit(QWidget):
name = self.current_name = str(item.data(Qt.ItemDataRole.DisplayRole) or '')
# Ensure encoding map is populated
root = self.container.parsed(name)
if not hasattr(root, 'xpath'):
return error_dialog(self, _('Not an HTML file'), _('The file {} is not marked as an HTML file in the OPF and cannot be displayed').format(name))
nasty = root.xpath('//*[local-name()="head"]/*[local-name()="p"]')
if nasty:
body = root.xpath('//*[local-name()="body"]')