mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
FB2,PML,RB,TXT Output: Fix removing of extra spaces too aggresive
This commit is contained in:
parent
47eb8c1f3e
commit
b9ae515df6
@ -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('<p>%s</p>' % 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('<p>%s</p>' % prepare_string_for_xml(elem.tail))
|
||||
else:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user