Is There A Better Way To Apply A Nl2br Filter With Jinja/flask?
I'm using Jinja with Flask (autoescape enabled) and I'm attempting to apply this filter import re from jinja2 import evalcontextfilter, Markup, escape _paragraph_re = re.compile(
Solution 1:
Simpler no, but how about only slightly more complicated? Try it with this regex:
(?:\r\n|\r(?!\n)|\n){2,}
The original regex matches \r\n
as a single line separator at first, but it's required to match two of them, so it backtracks and matches it as \r
followed by \n
. The negative lookahead, (?!\n)
, prevents it from matching \r
alone if the next character is \n
.
Post a Comment for "Is There A Better Way To Apply A Nl2br Filter With Jinja/flask?"