【问题标题】:How do I use an arbitrary external program as a filter in a perl program?如何在 perl 程序中使用任意外部程序作为过滤器?
【发布时间】:2016-07-31 05:17:04
【问题描述】:

我想使用当前 C 版本的 Fletcher Penny 的 Multi-markdown 作为模板工具包中的过滤器。我不清楚如何设置。

目前我没有把 TT 作为一个模块来调用,只是简单地编写模板,用 tpage 和 ttree 调用。

【问题讨论】:

    标签: perl template-toolkit


    【解决方案1】:

    Template-Toolkit 过滤器实际上很容易编写。

    模块:

    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;
    

    用法:

    [% USE Filter.MultiMarkdown %]
    
    [% FILTER markdown %]...[% END %]
      -or-
    [% ... | markdown %]
    

    【讨论】:

    • Text::Multimarkdown 是我现在使用的。唉,它以 Fletcher 程序的早期版本为模型,不产生兼容的代码,围绕着许多带有额外段落标签的东西。我将编辑我的问题以使其更清楚。
    • 答案还是一样。
    • 我现在正在使用一部即将死机的手机,所以我只是快速浏览了一下,但我认为最好将您的更改恢复到这个旧问题并提出一个新问题。
    • @PerlDuck——你是对的。我已删除该评论并将听取 ikegami 的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多