diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -10,6 +10,8 @@ import boards REFLINK_PATTERN = re.compile(r'\d+') +MULTI_NEWLINES_PATTERN = re.compile(r'(\r?\n){2,}') +ONE_NEWLINE = '\n' class TextFormatter(): @@ -126,6 +128,14 @@ def render_reflink(tag_name, value, opti return u'>>%s' % value +def preparse_text(text): + """ + Performs manual parsing before the bbcode parser is used. + """ + + return MULTI_NEWLINES_PATTERN.sub(ONE_NEWLINE, text) + + def bbcode_extended(markup): parser = bbcode.Parser() parser.add_formatter('post', render_reflink, strip=True) @@ -139,7 +149,9 @@ def bbcode_extended(markup): u'%(value)s') parser.add_simple_formatter('code', u'
%(value)s
')
- return parser.format(markup)
+
+ text = preparse_text(markup)
+ return parser.format(text)
formatters = [
QuotePattern,