From eadb87711321d7cb9a68b0cffb1ea907ee9c04e6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 13 Dec 2013 18:51:31 +0530 Subject: [PATCH] WHen pretty printing the OPF, do not sort the manifest items if there are comments in the manifest, as this would break the link between the comments and the content --- src/calibre/ebooks/oeb/polish/pretty.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/polish/pretty.py b/src/calibre/ebooks/oeb/polish/pretty.py index 4cf4e4e4c9..c0944d4755 100644 --- a/src/calibre/ebooks/oeb/polish/pretty.py +++ b/src/calibre/ebooks/oeb/polish/pretty.py @@ -78,7 +78,10 @@ def pretty_opf(root): return (cat, i) for manifest in root.xpath('//opf:manifest', namespaces=OPF_NAMESPACES): - children = sorted(manifest, key=manifest_key) + try: + children = sorted(manifest, key=manifest_key) + except AttributeError: + continue # There are comments so dont sort since that would mess up the comments for x in reversed(children): manifest.insert(0, x)