I'm getting a multiline plain text from my backend.
For example:
Lorem ipsum dolor sit amet, <strong>consectetur</strong> adipiscing elit.
Nunc porta velit ut nunc pretium, quis auctor nunc placerat.
In quis porta neque.
Fusce dapibus faucibus mi ut egestas.
<p>Phasellus egestas magna posuere, bibendum dui quis, lacinia nisl.</p>
I want to render it with AngularJS as an HTML paragraphs.
So this example will become:
<p>Lorem ipsum dolor sit amet, <strong>consectetur</strong> adipiscing elit.</p>
<p>Nunc porta velit ut nunc pretium, quis auctor nunc placerat.
In quis porta neque.
Fusce dapibus faucibus mi ut egestas.</p>
<p><p>Phasellus egestas magna posuere, bibendum dui quis, lacinia nisl.</p></p>
Please notice, that all HTML code that existed in the initial plain text must be securely escaped (including existing <p>
's) so I can't just apply my filter and do escaping afterwards.
I see it as a 3 steps process:
- Escape HTML inclusions in initial text.
- Apply filter to break multiline text to paragraphs.
- Output text without further escaping.
But I'm not sure what is the best method of implementing each step.
Could you guide me with the right approach vector? Thank you!