Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use an arbitrary external program as a filter in a perl program?

I would like to use the current C version of Fletcher Penny's Multi-markdown as a filter in Template Toolkit. It's not clear to me how to set this up.

At present I'm not calling TT as a module, but simply writing templates that are called with tpage and ttree.

like image 429
Sherwood Botsford Avatar asked Mar 03 '26 20:03

Sherwood Botsford


1 Answers

Template-Toolkit filters are actually quite easy to write.

Module:

package Template::Plugin::Filter::MultiMarkdown;

use strict;
use warnings;

our @ISA = 'Template::Plugin::Filter';

sub init {
    my $self = shift;
    $self->install_filter('markdown');
    return $self;
}

sub filter {
    my ($self, $text) = @_;
    ... Code that transforms $text and returns the transformed text ...
}

1;

Usage:

[% USE Filter.MultiMarkdown %]

[% FILTER markdown %]...[% END %]
  -or-
[% ... | markdown %]
like image 78
ikegami Avatar answered Mar 05 '26 10:03

ikegami