# Copyright 2003 Stepan Riha. This code cannot be redistributed without
# permission from www.nonplus.net.
#
# Version History
#
#	1.0 - June 19 2003
#	Initial release
#

use strict;
use warnings;
require MT::Template::Context;
package MT::plugins::MTOptimizeHTML;

my $VERSION = '1.0';

MT::Template::Context->add_tag(OptimizeHTMLVersion => sub { $VERSION } );
MT::Template::Context->add_container_tag(OptimizeHTML => \&MTOptimizeHTML );

sub MTOptimizeHTML {
	my ($ctx, $args, $cond) = @_;
	require HTML::Clean;
	defined(my $html = $ctx->stash('builder')->build($ctx, $ctx->stash('tokens'), $cond))
		or return;
	## Pick legit default options
	my %options = ( shortertags=>0, blink=>0, entities=>0, dequote=>0, htmldefaults=>0 );
	## Add options from args
	foreach (qw( whitespace shortertags blink contenttype comments entities dequote defcolor javascript htmldefaults lowercasetags meta emptytags )) {
		$options{$_} = $args->{$_} if defined $args->{$_};
	}
	my $h = HTML::Clean->new(\$html);
	$h->strip(\%options);
	return ${$h->data};
}

1;
