bradchoate / text-textile

Text::Textile -- Perl module for handling Textile format
20 stars 11 forks source link

Using filters consecutively don't work #22

Open MaxPerl opened 7 years ago

MaxPerl commented 7 years ago

If I use filters consecutively,then only the first filter is processed. All other filters are treated as tables- See this example:

use Text::Textile;

my $textile = new Text::Textile;

# define a hash of filters,
# here we just have one
$textile->filters(
    {
    test => sub {
          my ( $text, $param ) = (@_);
            # $text contains the string between the last
            # '|' and the '==', here I expect a number
            $text =~ s/(\d+)/http::\/\/localhost\/item\/view\/$1/;
           return $text;
           },
    video => sub {
            my ( $text, $r_param_list ) = (@_);
            # $text contains the string between the last
            # '|' and the '==', here I expect a number
            $text =~ s/(.*)###(.*)/\<video src\=\"$1\">$2<\/video\>/;
            return $text;
            },

    }
);

# Set the base URL as parameter (localhost for test)
$textile->filter_param( [ $base_url ] );

# generate the result
while ( my $line = <DATA>) { $lines = $lines.$line;}
#chomp @lines;
$dest = $textile->process($lines);

# $dest is the result
print "ERGEBNIS $dest\n";

__DATA__
==|video|/home/maximilian/video.mp2###Video ansehen==

==|video|/home/maximilian/video.mp2###Video ansehen==

==|item|12==