I'm aware of both safe and escape filters in jinja, but I couldn't find a solution for my problem.
I have the following string :
mystring = """<script>alert('I'm unsafe')</script>
I just entered a new line
Two new lines now!"""
I want to use it in a <p> tag showing the newlines properly :
<p>{{mystring | replace('\n', '<br>')}}</p>
This doesn't work as Jinja2 automatically escapes HTML tags, but if I do :
<p>{{mystring | replace('\n', '<br>') | safe }}</p>
It will then be unsafe.
What I have tried is :
<p>{{mystring | escape | replace('\n', '<br>') | safe }}</p>
But the above doesn't work, the <br>s are still escaped for some reason
How can I have the <br> tags not be escaped?