Search code examples
phphtmlhtmlpurifier

Limit children/nesting type with HTMLPurifier


How would I configure HTMLPurifier to prevent elements from having certain children? (or even another php solution would work)

For example I would like to prevent things like the following:

<p><p>text</p></p>
<ul><li><ul><li>text</li></ul></li></ul>

and would like them to convert to

<p>text</p>
<ul><li>text<li></ul>

I have looked up the documentation and found that EscapeInvalidChildren is depreciated. Are there any new alternatives?


Solution

  • Set the excludes attribute on the relevant HTMLPurifier_ElementDef. You'll have to use the http://htmlpurifier.org/docs/enduser-customize.html hands on the necessary objects.