Consider the following HTML string:
<code>{% set html = '<h2>Neo praemitto velit.</h2><p>Caecus metuo proprius.</p><p>At nobis plaga tego.</p>' %}
</code>
<code>{% set html = '<h2>Neo praemitto velit.</h2><p>Caecus metuo proprius.</p><p>At nobis plaga tego.</p>' %}
</code>
{% set html = '<h2>Neo praemitto velit.</h2><p>Caecus metuo proprius.</p><p>At nobis plaga tego.</p>' %}
I run striptags()
on that string:
<code>{{ html|striptags() }}
</code>
<code>{{ html|striptags() }}
</code>
{{ html|striptags() }}
Current output:
Neo praemitto velit.Caecus metuo proprius.At nobis plaga tego.
Expected output:
Neo praemitto velit. Caecus metuo proprius. At nobis plaga tego.
Question:
Is there an easy way to keep spaces in between the multiple closing and opening <p>
and other block-level tags (like <h2>
, etc.) that imply a line break?
I could probably do a search/replace afterwards with a regex to find .
followed by any non whitespace character and add the space myself but that sounds like overkill. How would you do it?
I am using Twig 3.8.0 if that matters.