Skip to content
Myr

Custom Filters example inserts escaped <br>s

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The example nl2br custom filter inserts escaped `&lt;br&gt;` <br> tags as a `Markup.replace` method seems to be aware of modifications and pass `str`/`unicode` arguments through `escape`.

authored by Jörn Hees · committed by Jörn Hees · parent c97fa10 · Browse files · 1 file+1 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+1 added−1 removed

  • other:+1 added−1 removed

1 file+1 added−1 removed

modified:docs/api.rst+1 added-1 removed
605 unmodified lines
606 _paragraph_re = re.compile(r'(?:\r\n|\r|\n){2,}')607608 @evalcontextfilter609 def nl2br(eval_ctx, value):610 result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', '<br>\n')610 result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', Markup('<br>\n'))611 for p in _paragraph_re.split(escape(value)))612 if eval_ctx.autoescape:613 result = Markup(result)614 return result
181 unmodified lines