mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-21 19:36:03 +01:00
FB2 Output: Remove section regexp what do nothing and rearrange regexps
This commit is contained in:
parent
d7a4e10c60
commit
e7175e802b
1 changed files with 7 additions and 9 deletions
|
|
@ -85,6 +85,9 @@ def clean_text(self, text):
|
|||
# Put the paragraph following a paragraph on a separate line.
|
||||
text = re.sub(r'(?mu)</p>\s*<p>', '</p>\n<p>', text)
|
||||
|
||||
if self.opts.insert_blank_line:
|
||||
text = re.sub(r'(?mu)</p>', '</p><empty-line/>', text)
|
||||
|
||||
# Clean up title endings.
|
||||
text = re.sub(r'(?mu)\s+</title>', '</title>', text)
|
||||
# Remove empty title elements.
|
||||
|
|
@ -92,6 +95,10 @@ def clean_text(self, text):
|
|||
# Put the paragraph following a title on a separate line.
|
||||
text = re.sub(r'(?mu)</title>\s*<p>', '</title>\n<p>', text)
|
||||
|
||||
# Put line breaks between paragraphs on a separate line.
|
||||
text = re.sub(r'(?mu)</(p|title)>\s*<empty-line/>', r'</\1>\n<empty-line/>', text)
|
||||
text = re.sub(r'(?mu)<empty-line/>\s*<p>', '<empty-line/>\n<p>', text)
|
||||
|
||||
# Remove empty sections.
|
||||
text = re.sub(r'(?mu)<section>\s*</section>', '', text)
|
||||
# Clean up sections starts and ends.
|
||||
|
|
@ -99,15 +106,6 @@ def clean_text(self, text):
|
|||
text = re.sub(r'(?mu)<section>\s*', '<section>\n', text)
|
||||
text = re.sub(r'(?mu)\s*</section>', '\n</section>', text)
|
||||
text = re.sub(r'(?mu)</section>\s*', '</section>\n', text)
|
||||
# Put the section following a section on a separate line.
|
||||
text = re.sub(r'(?mu)</section>\s*<section>', '</section>\n<section>', text)
|
||||
|
||||
if self.opts.insert_blank_line:
|
||||
text = re.sub(r'(?mu)</p>', '</p><empty-line/>', text)
|
||||
|
||||
# Put line breaks between paragraphs on a separate line.
|
||||
text = re.sub(r'(?mu)</(p|title)>\s*<empty-line/>', r'</\1>\n<empty-line/>', text)
|
||||
text = re.sub(r'(?mu)<empty-line/>\s*<p>', '<empty-line/>\n<p>', text)
|
||||
|
||||
return text
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue