Textile is a
a simple syntax for nudging plain text into structurally sound and stylistically rich web content. The functionality is provided via CPAN module
Text::Textile.
Now I want to include a shortcut for a link to a page to view an item to which I have the key. As documentation is rather thin I provide the snippet to demonstrate the use of a filter.
Example source text:
See ==|item|12== for details
This shall be replaced with:
See <a href="http://localhost:3000/item/view/12">Item 12</a> for details
Filters are stored in a hash with their name as key and a coderef to be called when the text is to be processed. Special parameters can be passed with the filter_param method, e.g. a base URL in my case.
I hope the example is self-explaining enough.
Edit: sorry, preview is missing
use warnings;
use strict;
use Text::Textile;
my $textile = new Text::Textile;
# to be used as a parameter
my $base_url = 'http://localhost:3000';
# This is my source text
my $source = '==|item|12==';
# define a hash of filters,
# here we just have one
$textile->filters(
{ item => sub {
my ( $text, $r_param_list ) = (@_);
my $url = $param->[0];
# $text contains the string between the last
# '|' and the '==', here I expect a number
$text =~ s/(\d+)/$url\/item\/view\/$1/;
return $text;
}
}
);
# Set the base URL as parameter (localhost for test)
$textile->filter_param( [ $base_url ] );
# generate the result
$dest = $textile->process($source);
# $dest is the result
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.