diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index aaf8361b99..16c822d263 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -241,7 +241,7 @@ class FB2MLizer(object): if not fb2_text or fb2_text[-1] != ' ': fb2_text.append(' ') - if hasattr(elem, 'text') and elem.text != None: + if hasattr(elem, 'text') and elem.text: if 'p' not in tag_stack: fb2_text.append('

%s

' % prepare_string_for_xml(elem.text)) else: @@ -255,7 +255,7 @@ class FB2MLizer(object): close_tag_list.insert(0, tag_stack.pop()) fb2_text += self.close_tags(close_tag_list) - if hasattr(elem, 'tail') and elem.tail != None: + if hasattr(elem, 'tail') and elem.tail: if 'p' not in tag_stack: fb2_text.append('

%s

' % prepare_string_for_xml(elem.tail)) else: diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py index 862f0ea0ae..27e88eb48b 100644 --- a/src/calibre/ebooks/pml/pmlml.py +++ b/src/calibre/ebooks/pml/pmlml.py @@ -257,7 +257,7 @@ class PMLMLizer(object): # margin # Proccess tags that contain text. - if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': + if hasattr(elem, 'text') and elem.text: text.append(self.remove_newlines(elem.text)) for item in elem: @@ -276,7 +276,7 @@ class PMLMLizer(object): #if style['page-break-after'] == 'always': # text.append('\\p') - if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '': + if hasattr(elem, 'tail') and elem.tail: text.append(self.remove_newlines(elem.tail)) return text diff --git a/src/calibre/ebooks/rb/rbml.py b/src/calibre/ebooks/rb/rbml.py index 945e21c994..c293880343 100644 --- a/src/calibre/ebooks/rb/rbml.py +++ b/src/calibre/ebooks/rb/rbml.py @@ -191,7 +191,7 @@ class RBMLizer(object): tag_stack.append(style_tag) # Proccess tags that contain text. - if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': + if hasattr(elem, 'text') and elem.text: text.append(prepare_string_for_xml(elem.text)) for item in elem: @@ -203,7 +203,7 @@ class RBMLizer(object): text += self.close_tags(close_tag_list) - if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '': + if hasattr(elem, 'tail') and elem.tail: text.append(prepare_string_for_xml(elem.tail)) return text diff --git a/src/calibre/ebooks/txt/txtml.py b/src/calibre/ebooks/txt/txtml.py index 59c3ea671a..45383675b4 100644 --- a/src/calibre/ebooks/txt/txtml.py +++ b/src/calibre/ebooks/txt/txtml.py @@ -94,7 +94,7 @@ class TXTMLizer(object): text = re.sub('(?<=.)%s(?=.)' % os.linesep, ' ', text) # Remove multiple spaces. - text = re.sub('[ ]+', ' ', text) + text = re.sub('[ ]{2,}', ' ', text) # Remove excessive newlines. text = re.sub('\n[ ]+\n', '\n\n', text) @@ -172,15 +172,15 @@ class TXTMLizer(object): # Are we in a paragraph block? if tag in BLOCK_TAGS or style['display'] in BLOCK_STYLES: in_block = True - if not end.endswith(u'\n\n') and hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': + if not end.endswith(u'\n\n') and hasattr(elem, 'text') and elem.text: text.append(u'\n\n') if tag in SPACE_TAGS: - if not end.endswith('u ') and hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': + if not end.endswith('u ') and hasattr(elem, 'text') and elem.text: text.append(u' ') # Process tags that contain text. - if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': + if hasattr(elem, 'text') and elem.text: text.append(elem.text) for item in elem: @@ -192,7 +192,7 @@ class TXTMLizer(object): if in_block: text.append(u'\n\n') - if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '': + if hasattr(elem, 'tail') and elem.tail: text.append(elem.tail) return text