1

Topic: Keeping nested UL untouched

Hi.

I use htmLawed 1.1.8. I have this code

  require_once 'htmLawed.php';
  $s = '<ul><li>Fruits</li><ul><li>Apple</li><li>Peach</li></ul></ul>';
  echo "$s";
  echo "<hr/>";
  echo htmLawed($s,array('safe'=>1));

But the problem is htmLawed remove the second ul probably because it is nested, but it is valid html so how can I change htmLawed option to not remove these nested UL?

2

Re: Keeping nested UL untouched

Only 'li' can be a direct child of 'ul' or 'ol' (W3C standard specification for lists (http://www.w3.org/TR/html401/struct/lists.html#h-10.2)). Thus, a nested list needs to be within an item of the parent list for the HTM to be valid; ...<li>Fruits</li><ul><li>... should be ...<li>Fruits</li><li><ul><li>....

htmLawed's behavior you see is therefore expected as the input has invalid markup. Currently it can't auto-correct the input by adding the 'li'. You may want to add code to correct the input before it is passed to htmLawed. E.g.,

$s = preg_replace('`(</li>)([^<]*)(<[u|o])`i', '$1<li>$2$3', $s);

Edited 7th Oct 2011: see this post for a better regex code.