0

I have just added a new Twig filter that give me HTML from a Textile Markup; so I return it raw.

It's embedded into a html paragraph and the .twig file look like this:

[..]
<p class="description">
    {{ description|textile|raw }}
</p>
[..]

Description variable contains another paragraph:

Some text

But the rendered content is this instead:

<p class="description"></p>
<p>
  Some text
</p>

and the variable is rendered outside of the container, with no apparent reason.

If I change the container to it works perfectly

<div class="description">
    <p>
        Some text
    </p>
</div>

Someone can give me some reason?

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
  • 3
    Paragraph tags are not allowed inside of other paragraph tags. http://www.w3.org/TR/html401/struct/text.html#h-9.3.1 – David Bradbury May 30 '14 at 17:56
  • Just so you know: Twig isn't doing this, your browser is. If you look at the actual source code instead of in a debugger it should show your nested paragraphs. – Wesley Murch May 30 '14 at 18:02
  • @WesleyMurch you are totally right! Just didn't know that the debugger could show a different source respect to the original one. Thanks for linking to the duplicate. – Kamafeather May 31 '14 at 21:19

1 Answers1

2

That's normal, because <p> elements are not allowed inside other <p> elements.

Technically, the content model of <p> elements is phrasing content, which doesn't include other <p> elements.

You can validate your markup in http://validator.w3.org/

Oriol
  • 274,082
  • 63
  • 437
  • 513