From d596ed03416df89fdfc74b0935917d5a443f9b36 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 11 Jun 2009 11:52:07 -0700 Subject: [PATCH] Fix #2576 (chm files) and handle empty TOCs in the conversion pipeline --- src/calibre/ebooks/__init__.py | 2 +- src/calibre/ebooks/oeb/base.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index d2d6fc94e1..a084cdd0f8 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -25,7 +25,7 @@ class DRMError(ValueError): BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'htm', 'xhtm', 'html', 'xhtml', 'pdf', 'pdb', 'prc', 'mobi', 'azw', 'doc', 'epub', 'fb2', 'djvu', 'lrx', 'cbr', 'cbz', 'oebzip', - 'rb', 'imp', 'odt'] + 'rb', 'imp', 'odt', 'chm'] class HTMLRenderer(object): diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index e2a4875399..244acf7627 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -1327,7 +1327,9 @@ class TOC(object): return len(list(self.iter())) - 1 def next_play_order(self): - return max([x.play_order for x in self.iter()])+1 + entries = [x.play_order for x in self.iter()] + base = max(entries) if entries else 0 + return base+1 def has_href(self, href): for x in self.iter():