Template::Plugin::HTML::Strip - HTML::Strip filter for Template Toolkit


Template-Plugin-HTML-Strip documentation Contained in the Template-Plugin-HTML-Strip distribution.

Index


Code Index:

NAME

Top

Template::Plugin::HTML::Strip - HTML::Strip filter for Template Toolkit

SYNOPSIS

Top

  [% USE HTML.Strip %]

  [% FILTER html_strip %]
  <title>People for the Preservation of Presentational Markup</title>
  <h1>HTML::Strip - A cause for concern?</h1>
  [% END %]

  [% USE HTML.Strip 'strip'
      striptags   = [ 'script' 'iframe' ]
      emit_spaces = 0
  %]

  [% FILTER strip %]
  <p>A call to arms against the removal of our elements!</p>
  [% END %]

DESCRIPTION

Top

This module is a Template Toolkit dynamic filter, which uses HTML::Strip to remove markup (primarily HTML, but also SGML, XML, etc) from filtered content during template processing.

By default, the installed filter's name is 'html_strip'. This can be changed by specifying a new name as the first positional argument during plugin usage:

  [% USE HTML.Strip 'strip' %]

  [% '<div>Our very existence is under threat.</div>' | strip %]

The filter can optionally take configuration options, which will be passed to HTML::Strip's constructor method:

  [% USE HTML.Strip
      striptags   = [ 'applet' 'strong' ]
      emit_spaces = 0
  %]

  [% FILTER html_strip %]
  <strong>Are we next!?</strong>
  [% END %]

For more details on available configuration options, please refer to HTML::Strip.

METHODS

Top

init

Creates a dynamic filter and installs the filter under the value provided for the first positional argument, otherwise uses 'html_strip'.

filter

Receives a reference to the plugin object, along with the text to be filtered and configuration options. Using HTML::Strip, returns the filtered (stripped) text.

SEE ALSO

Top

Template, HTML::Strip

AUTHOR

Top

Geoff Simmons <gsimmons@cpan.org>

COPYRIGHT AND LICENSE

Top


Template-Plugin-HTML-Strip documentation Contained in the Template-Plugin-HTML-Strip distribution.

package Template::Plugin::HTML::Strip;

use 5.006;
use strict;

our $VERSION = '0.01';

use Template::Plugin::Filter;
use base 'Template::Plugin::Filter';
use HTML::Strip;

my $FILTER_NAME = 'html_strip';

sub init {
    my $self = shift;

    $self->{_DYNAMIC} = 1;
    $self->install_filter($self->{_ARGS}->[0] || $FILTER_NAME);

    return $self;
}

sub filter {
    my ($self, $text, undef, $config) = @_;
    $config = $self->merge_config($config);

    my $hs = HTML::Strip->new(%$config);
    return $hs->parse($text);
}

1;

__END__