diff --git a/src/calibre/ebooks/rtf/rtfml.py b/src/calibre/ebooks/rtf/rtfml.py index 590beb85de..53ba7ecbd8 100644 --- a/src/calibre/ebooks/rtf/rtfml.py +++ b/src/calibre/ebooks/rtf/rtfml.py @@ -192,7 +192,7 @@ def dump_text(self, elem, stylizer, tag_stack=[]): if not isinstance(elem.tag, basestring) \ or namespace(elem.tag) != XHTML_NS: p = elem.getparent() - if isinstance(p.tag, basestring) and namespace(p.tag) == XHTML_NS \ + if p is not None and isinstance(p.tag, basestring) and namespace(p.tag) == XHTML_NS \ and elem.tail: return elem.tail return u'' diff --git a/src/calibre/ebooks/txt/txtml.py b/src/calibre/ebooks/txt/txtml.py index d71212fa8e..3ecb6940f8 100644 --- a/src/calibre/ebooks/txt/txtml.py +++ b/src/calibre/ebooks/txt/txtml.py @@ -156,7 +156,7 @@ def dump_text(self, elem, stylizer, end=''): if not isinstance(elem.tag, basestring) \ or namespace(elem.tag) != XHTML_NS: p = elem.getparent() - if isinstance(p.tag, basestring) and namespace(p.tag) == XHTML_NS \ + if p is not None and isinstance(p.tag, basestring) and namespace(p.tag) == XHTML_NS \ and elem.tail: return [elem.tail] return ['']