package HTML::Template::Compiled::Plugin::HTML2;
# ABSTRACT: Do not escape all HTML entities
use strict;
use warnings;
use HTML::Template::Compiled;
HTML::Template::Compiled->register(__PACKAGE__);
use HTML::Entities;
our $VERSION = '0.01';
sub register{
my ($class) = @_;
my %plugs = (
escape => {
HTML_WITHOUT_NBSP => \&escape_html,
},
);
return \%plugs;
}
sub escape_html {
my ($str) = @_;
return $str unless defined $str;
$str = HTML::Entities::encode_entities( $str );
$str =~ s! ! !g;
$str =~ s!<br />!<br />!g;
#$str =~ s/&/&/g;
#$str =~ s/"/"/g;
#$str =~ s/'/'/g;
#$str =~ s/>/>/g;
#$str =~ s/</</g;
return $str;
}
1;
__END__
=pod
=head1 NAME
HTML::Template::Compiled::Plugin::HTML2 - Do not escape all HTML entities
=head1 VERSION
version 0.02
=head1 SYNOPSIS
my $template = '<%= test ESCAPE=HTML_WITHOUT_NBSP %>';
my $text = 'hello>';
my $tmpl = HTML::Template::Compiled->new(
scalarref => \$template,
plugin => [ 'HTML::Template::Compiled::Plugin::HTML2' ],
);
$tmpl->param( test => $text );
my $output = $tmpl->output;
is $output, 'hello>', '> => >';
my $template = '<%= test ESCAPE=HTML_WITHOUT_NBSP %>';
my $text = ' hello<br />';
my $tmpl = HTML::Template::Compiled->new(
scalarref => \$template,
plugin => [ 'HTML::Template::Compiled::Plugin::HTML2' ],
);
$tmpl->param( test => $text );
my $output = $tmpl->output;
is $output, ' hello<br />', 'test';
=head1 DESCRIPTION
=head1 AUTHOR
Renee Baecker <reneeb@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
=cut