line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::WikiFormat; |
2
|
6
|
|
|
6
|
|
139860
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
240
|
|
3
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
388
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
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
|
|
30
|
use base 'Template::Plugin::Filter'; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
8314
|
|
49
|
6
|
|
|
6
|
|
36317
|
use Text::WikiFormat; |
|
6
|
|
|
|
|
57348
|
|
|
6
|
|
|
|
|
41
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
############################################################################# |
54
|
|
|
|
|
|
|
#Interface Methods # |
55
|
|
|
|
|
|
|
############################################################################# |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub filter { |
58
|
5
|
|
|
5
|
1
|
12789
|
my ( $self, $text ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
5
|
|
|
|
|
13
|
my $conf = $self->{_CONFIG}; |
61
|
5
|
|
50
|
|
|
17
|
$conf ||= {}; |
62
|
5
|
|
|
|
|
21
|
my %tags = %$conf; |
63
|
5
|
|
|
|
|
8
|
my %opts; |
64
|
5
|
|
|
|
|
22
|
my %default = ( |
65
|
|
|
|
|
|
|
prefix => '', |
66
|
|
|
|
|
|
|
extended => 0, |
67
|
|
|
|
|
|
|
implicit_links => 1, |
68
|
|
|
|
|
|
|
absolute_links => 0, |
69
|
|
|
|
|
|
|
); |
70
|
5
|
|
|
|
|
16
|
for ( keys %default ) { |
71
|
20
|
|
100
|
|
|
71
|
$opts{$_} = $tags{$_} || $default{$_}; |
72
|
20
|
|
|
|
|
30
|
delete $tags{$_}; |
73
|
|
|
|
|
|
|
} |
74
|
5
|
|
|
|
|
9
|
my $replace; |
75
|
5
|
100
|
|
|
|
19
|
if ( exists $tags{global_replace} ) { |
76
|
1
|
|
|
|
|
3
|
$replace = $tags{global_replace}; |
77
|
1
|
|
|
|
|
3
|
delete $tags{global_replace}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
21
|
my $output = Text::WikiFormat::format( $text, \%tags, \%opts ); |
81
|
|
|
|
|
|
|
|
82
|
5
|
|
|
|
|
7772
|
for my $rep (@$replace) { |
83
|
1
|
|
|
|
|
3
|
my ( $from, $to ) = @$rep; |
84
|
1
|
|
|
|
|
70
|
eval("\$output =~ s($from)($to)sg"); |
85
|
|
|
|
|
|
|
} |
86
|
5
|
|
|
|
|
35
|
return $output; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |