2 package IkiWiki::Plugin::htmlbalance;
4 # htmlbalance: Parse and re-serialize HTML to ensure balanced tags
6 # Copyright 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/>
7 # Licensed under the GNU GPL, version 2, or any later version published by the
8 # Free Software Foundation
15 hook(type => "getsetup", id => "htmlbalance", call => \&getsetup);
16 hook(type => "sanitize", id => "htmlbalance", call => \&sanitize);
19 sub getsetup () { #{{{
27 sub sanitize (@) { #{{{
32 use HTML::TreeBuilder;
33 use XML::Atom::Util qw(encode_xml);
38 return $params{content};
41 my $tree = HTML::TreeBuilder->new_from_content($params{content});
42 my @nodes = $tree->disembowel();
43 foreach my $node (@nodes) {
45 $ret .= $node->as_XML();
50 $ret .= encode_xml($node);