Skip to content

Commit

Permalink
Better error message when ToC editor is opened to an non-HTML file
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Dec 31, 2024
1 parent 392b5f5 commit b388a91
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/calibre/gui2/toc/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ def current_changed(self, item):
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"]')
Expand Down

0 comments on commit b388a91

Please sign in to comment.