Show More
@@ -10,6 +10,8 import boards | |||||
10 |
|
10 | |||
11 |
|
11 | |||
12 | REFLINK_PATTERN = re.compile(r'\d+') |
|
12 | REFLINK_PATTERN = re.compile(r'\d+') | |
|
13 | MULTI_NEWLINES_PATTERN = re.compile(r'(\r?\n){2,}') | |||
|
14 | ONE_NEWLINE = '\n' | |||
13 |
|
15 | |||
14 |
|
16 | |||
15 | class TextFormatter(): |
|
17 | class TextFormatter(): | |
@@ -126,6 +128,14 def render_reflink(tag_name, value, opti | |||||
126 | return u'>>%s' % value |
|
128 | return u'>>%s' % value | |
127 |
|
129 | |||
128 |
|
130 | |||
|
131 | def preparse_text(text): | |||
|
132 | """ | |||
|
133 | Performs manual parsing before the bbcode parser is used. | |||
|
134 | """ | |||
|
135 | ||||
|
136 | return MULTI_NEWLINES_PATTERN.sub(ONE_NEWLINE, text) | |||
|
137 | ||||
|
138 | ||||
129 | def bbcode_extended(markup): |
|
139 | def bbcode_extended(markup): | |
130 | parser = bbcode.Parser() |
|
140 | parser = bbcode.Parser() | |
131 | parser.add_formatter('post', render_reflink, strip=True) |
|
141 | parser.add_formatter('post', render_reflink, strip=True) | |
@@ -139,7 +149,9 def bbcode_extended(markup): | |||||
139 | u'<span class="strikethrough">%(value)s</span>') |
|
149 | u'<span class="strikethrough">%(value)s</span>') | |
140 | parser.add_simple_formatter('code', |
|
150 | parser.add_simple_formatter('code', | |
141 | u'<pre><code>%(value)s</pre></code>') |
|
151 | u'<pre><code>%(value)s</pre></code>') | |
142 | return parser.format(markup) |
|
152 | ||
|
153 | text = preparse_text(markup) | |||
|
154 | return parser.format(text) | |||
143 |
|
155 | |||
144 | formatters = [ |
|
156 | formatters = [ | |
145 | QuotePattern, |
|
157 | QuotePattern, |
General Comments 0
You need to be logged in to leave comments.
Login now