diff --git a/src/calibre/ebooks/pml/pmlconverter.py b/src/calibre/ebooks/pml/pmlconverter.py index 099a23c544..3484be5927 100644 --- a/src/calibre/ebooks/pml/pmlconverter.py +++ b/src/calibre/ebooks/pml/pmlconverter.py @@ -71,8 +71,8 @@ class PML_HTMLizer(object): 'ra': ('', ''), 'c': ('
', '
'), 'r': ('
', '
'), - 't': ('
', '
'), - 'T': ('
', '
'), + 't': ('
', '
'), + 'T': ('
', '
'), 'i': ('', ''), 'u': ('', ''), 'd': ('', ''), diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py index 2e00ad6ae3..4310fb39ad 100644 --- a/src/calibre/ebooks/pml/pmlml.py +++ b/src/calibre/ebooks/pml/pmlml.py @@ -182,9 +182,14 @@ class PMLMLizer(object): # Remove excessive spaces 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\n', text) + if self.opts.remove_paragraph_spacing: + text = re.sub('\n{2,}', '\n', text) + text = re.sub('(?imu)^(?P.+)$', lambda mo: mo.group('text') if re.search(r'\\[XxCm]', mo.group('text')) else ' %s' % mo.group('text'), text) + else: + text = re.sub('\n{4,}', '\n\n\n', text) + return text @@ -204,12 +209,10 @@ class PMLMLizer(object): tag_count = 0 # 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: if 'block' not in tag_stack: tag_count += 1 tag_stack.append('block') - if self.opts.remove_paragraph_spacing: - text.append('\\t') # Process tags that need special processing and that do not have inner # text. Usually these require an argument @@ -289,14 +292,10 @@ class PMLMLizer(object): close_tag_list.insert(0, tag_stack.pop()) text += self.close_tags(close_tag_list) if tag in SEPARATE_TAGS: - text.append('\n') - if not self.opts.remove_paragraph_spacing: - text.append('\n') + text.append('\n\n') - if 'block' not in tag_stack and text and text[-1] != '\n': - text.append('\n') - if not self.opts.remove_paragraph_spacing: - text.append('\n') + if 'block' not in tag_stack: + text.append('\n\n') #if style['page-break-after'] == 'always': # text.append('\\p')