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] != ' ':
|
if not fb2_text or fb2_text[-1] != ' ':
|
||||||
fb2_text.append(' ')
|
fb2_text.append(' ')
|
||||||
|
|
||||||
if hasattr(elem, 'text') and elem.text != None:
|
if hasattr(elem, 'text') and elem.text:
|
||||||
if 'p' not in tag_stack:
|
if 'p' not in tag_stack:
|
||||||
fb2_text.append('<p>%s</p>' % prepare_string_for_xml(elem.text))
|
fb2_text.append('<p>%s</p>' % prepare_string_for_xml(elem.text))
|
||||||
else:
|
else:
|
||||||
@ -255,7 +255,7 @@ class FB2MLizer(object):
|
|||||||
close_tag_list.insert(0, tag_stack.pop())
|
close_tag_list.insert(0, tag_stack.pop())
|
||||||
fb2_text += self.close_tags(close_tag_list)
|
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:
|
if 'p' not in tag_stack:
|
||||||
fb2_text.append('<p>%s</p>' % prepare_string_for_xml(elem.tail))
|
fb2_text.append('<p>%s</p>' % prepare_string_for_xml(elem.tail))
|
||||||
else:
|
else:
|
||||||
|
@ -257,7 +257,7 @@ class PMLMLizer(object):
|
|||||||
# margin
|
# margin
|
||||||
|
|
||||||
# Proccess tags that contain text.
|
# 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))
|
text.append(self.remove_newlines(elem.text))
|
||||||
|
|
||||||
for item in elem:
|
for item in elem:
|
||||||
@ -276,7 +276,7 @@ class PMLMLizer(object):
|
|||||||
#if style['page-break-after'] == 'always':
|
#if style['page-break-after'] == 'always':
|
||||||
# text.append('\\p')
|
# 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))
|
text.append(self.remove_newlines(elem.tail))
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
@ -191,7 +191,7 @@ class RBMLizer(object):
|
|||||||
tag_stack.append(style_tag)
|
tag_stack.append(style_tag)
|
||||||
|
|
||||||
# Proccess tags that contain text.
|
# 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))
|
text.append(prepare_string_for_xml(elem.text))
|
||||||
|
|
||||||
for item in elem:
|
for item in elem:
|
||||||
@ -203,7 +203,7 @@ class RBMLizer(object):
|
|||||||
|
|
||||||
text += self.close_tags(close_tag_list)
|
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))
|
text.append(prepare_string_for_xml(elem.tail))
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
@ -94,7 +94,7 @@ class TXTMLizer(object):
|
|||||||
text = re.sub('(?<=.)%s(?=.)' % os.linesep, ' ', text)
|
text = re.sub('(?<=.)%s(?=.)' % os.linesep, ' ', text)
|
||||||
|
|
||||||
# Remove multiple spaces.
|
# Remove multiple spaces.
|
||||||
text = re.sub('[ ]+', ' ', text)
|
text = re.sub('[ ]{2,}', ' ', text)
|
||||||
|
|
||||||
# Remove excessive newlines.
|
# Remove excessive newlines.
|
||||||
text = re.sub('\n[ ]+\n', '\n\n', text)
|
text = re.sub('\n[ ]+\n', '\n\n', text)
|
||||||
@ -172,15 +172,15 @@ class TXTMLizer(object):
|
|||||||
# Are we in a paragraph block?
|
# Are we in a paragraph block?
|
||||||
if tag in BLOCK_TAGS or style['display'] in BLOCK_STYLES:
|
if tag in BLOCK_TAGS or style['display'] in BLOCK_STYLES:
|
||||||
in_block = True
|
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')
|
text.append(u'\n\n')
|
||||||
|
|
||||||
if tag in SPACE_TAGS:
|
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' ')
|
text.append(u' ')
|
||||||
|
|
||||||
# Process tags that contain text.
|
# 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)
|
text.append(elem.text)
|
||||||
|
|
||||||
for item in elem:
|
for item in elem:
|
||||||
@ -192,7 +192,7 @@ class TXTMLizer(object):
|
|||||||
if in_block:
|
if in_block:
|
||||||
text.append(u'\n\n')
|
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)
|
text.append(elem.tail)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user