line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::WikiFormat; |
2
|
6
|
|
|
6
|
|
234099
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
423
|
|
3
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
365
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Template::Plugin::WikiFormat - TT wrapper for Text::WikiFormat |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
[% USE WikiFormat %] |
16
|
|
|
|
|
|
|
[% FILTER $WikiFormat %] |
17
|
|
|
|
|
|
|
... |
18
|
|
|
|
|
|
|
[% END %] |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This is a plugin used for wiki rendering inside Template Toolkit. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Parameters may be passed in through the USE directive, e.g. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
[% USE WikiFormat prefix = "http://www.mysite.com/?page=" %] |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This provides the 4 options supported by L, i.e. |
29
|
|
|
|
|
|
|
C, and the special option |
30
|
|
|
|
|
|
|
global_replace, which takes an array of arrays of from and to strings. The |
31
|
|
|
|
|
|
|
output from Text::WikiFormat is post processed by replacing each from regexp |
32
|
|
|
|
|
|
|
with the to regexp. Anything else passed in is interpreted as a tag (see the |
33
|
|
|
|
|
|
|
Gory Details section). |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 filter |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Accepts the wiki text to be rendered, and context. The tags and options are |
38
|
|
|
|
|
|
|
passed in through the context. See L. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
############################################################################# |
45
|
|
|
|
|
|
|
#Library Modules # |
46
|
|
|
|
|
|
|
############################################################################# |
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
6
|
|
33
|
use base 'Template::Plugin::Filter'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
6322
|
|
49
|
6
|
|
|
6
|
|
58895
|
use Text::WikiFormat; |
|
6
|
|
|
|
|
87932
|
|
|
6
|
|
|
|
|
49
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
############################################################################# |
54
|
|
|
|
|
|
|
#Interface Methods # |
55
|
|
|
|
|
|
|
############################################################################# |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub filter { |
58
|
5
|
|
|
5
|
1
|
33393
|
my ( $self, $text ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
5
|
|
|
|
|
17
|
my $conf = $self->{_CONFIG}; |
61
|
5
|
|
50
|
|
|
22
|
$conf ||= {}; |
62
|
5
|
|
|
|
|
24
|
my %tags = %$conf; |
63
|
5
|
|
|
|
|
11
|
my %opts; |
64
|
5
|
|
|
|
|
35
|
my %default = ( |
65
|
|
|
|
|
|
|
prefix => '', |
66
|
|
|
|
|
|
|
extended => 0, |
67
|
|
|
|
|
|
|
implicit_links => 1, |
68
|
|
|
|
|
|
|
absolute_links => 0, |
69
|
|
|
|
|
|
|
); |
70
|
5
|
|
|
|
|
19
|
for ( keys %default ) { |
71
|
20
|
|
100
|
|
|
86
|
$opts{$_} = $tags{$_} || $default{$_}; |
72
|
20
|
|
|
|
|
39
|
delete $tags{$_}; |
73
|
|
|
|
|
|
|
} |
74
|
5
|
|
|
|
|
12
|
my $replace; |
75
|
5
|
100
|
|
|
|
23
|
if ( exists $tags{global_replace} ) { |
76
|
1
|
|
|
|
|
4
|
$replace = $tags{global_replace}; |
77
|
1
|
|
|
|
|
4
|
delete $tags{global_replace}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
30
|
my $output = Text::WikiFormat::format( $text, \%tags, \%opts ); |
81
|
|
|
|
|
|
|
|
82
|
5
|
|
|
|
|
31693
|
for my $rep (@$replace) { |
83
|
1
|
|
|
|
|
3
|
my ( $from, $to ) = @$rep; |
84
|
1
|
|
|
|
|
104
|
eval("\$output =~ s($from)($to)sg"); |
85
|
|
|
|
|
|
|
} |
86
|
5
|
|
|
|
|
46
|
return $output; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |