The example nl2br custom filter inserts escaped `<br>` <br> tags as a `Markup.replace` method seems to be aware of modifications and pass `str`/`unicode` arguments through `escape`.
@evalcontextfilter
def nl2br(eval_ctx, value):
- result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', '<br>\n')
+ result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', Markup('<br>\n'))
for p in _paragraph_re.split(escape(value)))
if eval_ctx.autoescape:
result = Markup(result)