Perl中可扩展的Markdown模块?

时间:2012-11-27 03:22:22

标签: html perl markdown perl-module dancer

我正在perl中构建一个Dancer应用程序。

我的应用程序侦听POST事件,将它们存储在数据库中,执行一些计算,然后可能POST到另一个http端点(以text / html呈现事件);在我用来进行更新的模块中,我使用HTML格式,如:

$helper->post_update({
    text => 'some text that is escaped',
    main_text => 'unescaped text, <i>with html</i>',
    ...
});

是否有一个perl模块可以让我拥有可扩展的降价支持?

例如:

替换

$newtext = "<b>this is bold</b> <i>this is italic</i> <span class="something">@evalutated_with_a_custom_rule</span> ... etc";

$newtext = Markdown::Module->run_rules("*this is bold* _this is italic_ @evalutated_with_a_custom_rule ... etc");

...为了进一步解除我的模型和视图。

提前致谢。

2 个答案:

答案 0 :(得分:1)

我相信有很多方法可以做到这一点,例如:

  1. 使用Template::Toolkit将文本替换为从markdown模板文件中提供的main_text。

  2. 使用Text::Markdown将您的结果降价转换为HTML,然后您可以将其投放回客户端。

答案 1 :(得分:0)

查看WikiText module及其子模块。 E.g。

use WikiText::Socialtext;
my $wikitext = '*this is bold* _this is italic_ @evalutated_with_a_custom_rule ... etc';
my $html = WikiText::Socialtext->new($wikitext)->to_html;

......会产生:

<p><strong>this is bold</strong> <em>this is italic</em> @evalutated_with_a_custom_rule</p>

顺便说一句,如果@前面的evaluated_with_a_custom_role是标记,则必须使用前面的反斜杠或使用单引号将其转义。在双引号字符串中,perl将插入数组@evalutated_with_a_custom_rule的内容。