Blaskovicz
Blaskovicz

Reputation: 6160

Extensible Markdown-like Module In Perl?

I'm building a Dancer application in perl.

My app listens for POST events, stores them in a database, does some calculations and then potentially POSTs to another http endpoint (which renders events in text/html); In the module I use to make the updates, I use HTML formatting like:

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

Is there a perl module out there that allows me to have extensible, markdown-like support?

eg:

replace

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

with

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

... in order to further de-couple my model and view.

Thanks in advance.

Upvotes: 2

Views: 429

Answers (2)

fany
fany

Reputation: 33

Have a look at the WikiText module and its submodules. 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;

… would produce:

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

BTW, if the @ in front of evaluated_with_a_custom_role is meant to be markup, you will have to escape it with a preceding backslash or use single quotes. In a double quoted string perl is going to interpolate the contents of the array @evalutated_with_a_custom_rule.

Upvotes: 0

Ross Attrill
Ross Attrill

Reputation: 2702

I am sure there are plenty of ways that you could do this such as:

  1. Using Template::Toolkit to replace your text with main_text being fed from a markdown template file.

  2. Using Text::Markdown to convert your resultant markdown with HTML which you can then serve back to the client.

Upvotes: 1

Related Questions