Code with custom formater, which demonstrates the problem:
import bbcode
parser = bbcode.Parser()
def render_code(name, value, options, parent, context):
if options:
lang = parser._replace(options.keys()[0], parser.REPLACE_ESCAPE)
highlight_class = "lang-%s" % lang
else:
highlight_class = 'no-highlight'
return '<code class="%s">%s</code>' % (highlight_class, value)
parser.add_formatter(
"code", render_code,
render_embedded=False,
transform_newlines=False,
replace_links=False,
replace_cosmetic=False,
)
markup = """text before code:
[code python]
def test():
print "test (c)", 'test'
code = 123
a = [code]
b = 42
[/code] after code"""
print parser.format(markup)
Output:
text before code:<br /><code class="lang-python">def test():
print "test (c)", 'test'
code = 123
a = [code]
b = 42
[/code] after code</code>
Expected:
text before code:<br /><code class="lang-python">def test():
print "test (c)", 'test'
code = 123
a = [code]
b = 42
</code> after code
Code with custom formater, which demonstrates the problem:
Output:
Expected:
Postmarkup has the same issue.