From d0a952ac3ad59c07a081f6637cd5373840ea8df3 Mon Sep 17 00:00:00 2001
From: asbjorn grandt \2
).
body = re.sub(r'\s*
]*>\s*', r'
', body)
- # Find all bexisting blocks with p, pre and blockquote tags, we need to leave those alone.
+ # Find all bexisting blocks with p, pre and blockquote tags, we need to shields break tags inside those.
+ # This is for "lenient" mode, however it is also used to clear break tags before and after the block elements.
blocksRegex = re.compile(r'(\s*
\s*)*\s*<(pre|p|blockquote)([^>]*)>(.+?)\2>\s*(\s*
\s*)*', re.DOTALL)
body = blocksRegex.sub(r'\n<\2\3>\4\2>\n', body)
+ # if aggressive mode = true
+ # blocksRegex = re.compile(r'(\s*
\s*)*\s*<(pre)([^>]*)>(.+?)\2>\s*(\s*
\s*)*', re.DOTALL)
+ # In aggressive mode, we also check breakes inside blockquotes, meaning we can get orphaned paragraph tags.
+ # body = re.sub(r']*)>(.+?)
', r'
', body, re.DOTALL)
+ # end aggressive mode
+
blocks = blocksRegex.finditer(body)
# For our replacements to work, we need to work backwards, so we reverse the iterator.
blocksList = []
@@ -194,9 +201,9 @@ def replace_br_with_p(body):
body = re.sub(r'\s*(<\/\s*p>\s*){2,}', r'
]*)>\s*', r'
', body) + body = re.sub(r'\s*
]*)>\s*', r'\n
', body) # superflous cleaning, remove whitespaces leading closing p tags. These does not affect formatting. - body = re.sub(r'\s*
', r'', body) + body = re.sub(r'\s*\s*', r'\n', body) # Remove empty tag pairs body = re.sub(r'\s*<(\S+)[^>]*>\s*\1>', r'', body) @@ -204,7 +211,7 @@ def replace_br_with_p(body): body = body.replace(u'{br /}', u'