line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::KwikiFormat; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32265
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
205
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Text::KwikiFormat - Translate Kwiki formatted text into HTML |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.01 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Text::KwikiFormat; |
22
|
|
|
|
|
|
|
my $html = Text::KwikiFormat::format('some kwiki text'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module allows you to convert Kwiki text using the L |
27
|
|
|
|
|
|
|
module. In the current version, it only passes the input to the formatter and |
28
|
|
|
|
|
|
|
spits out the converted HTML content as it. Customization is not supported. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
For people interested in using L to convert the Kwiki text, see the |
31
|
|
|
|
|
|
|
module L. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
500
|
use Kwiki 0.39; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 EXPORT |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
You can also import a customized subroutine with default options set up, pretty much the |
40
|
|
|
|
|
|
|
same way as in L. Currently, only two keys are |
41
|
|
|
|
|
|
|
supported: |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=over 4 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item * C, the KwikiLink prefix |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item * C, an alias for the imported function (defaults 'C') |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=back |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Examples: |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# import 'kwikiformat' |
54
|
|
|
|
|
|
|
use Text::KwikiFormat 'kwikiformat'; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# ... the same thing |
57
|
|
|
|
|
|
|
use Text::KwikiFormat as => 'kwikiFormat'; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# import 'wikiformat' with a custom prefix |
60
|
|
|
|
|
|
|
use Text::KwikiFormat prefix => 'http://www.example.com/'; |
61
|
|
|
|
|
|
|
my $text = wikiformat 'some kwiki text'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub import { |
66
|
|
|
|
|
|
|
my $class = shift; |
67
|
|
|
|
|
|
|
return unless @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my %args = |
70
|
|
|
|
|
|
|
@_ == 1? (as => shift): (as => 'wikiformat', @_); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $name = delete $args{as}; |
73
|
|
|
|
|
|
|
my $caller = caller(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
no strict 'refs'; |
76
|
|
|
|
|
|
|
*{$caller. "::$name"} = sub { |
77
|
|
|
|
|
|
|
my ($text, $newtags, $opts) = @_; |
78
|
|
|
|
|
|
|
$opts ||= {}; |
79
|
|
|
|
|
|
|
Text::KwikiFormat::format($text, $newtags, { %$opts, %args }); |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This module supports only one interface subroutine C. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 format($text, $newtags, $opts) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The first argument C<$text> is the text to convert. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The second argument is not used. I keep it here to comply with the |
92
|
|
|
|
|
|
|
L calling convention. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
The options are specified as a hash reference via the third argument C<$opts>. |
95
|
|
|
|
|
|
|
Currently, only one option is supported: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over 4 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * prefix |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This is the path to the Wiki. The actual linked item itself will be appended |
102
|
|
|
|
|
|
|
to the prefix. This is useful to create full URIs: |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
{ prefix => 'http://example.com/kwiki.pl?page=' } |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub format { |
111
|
|
|
|
|
|
|
my ($text, $newtags, $opts) = @_; |
112
|
|
|
|
|
|
|
my %options = ( |
113
|
|
|
|
|
|
|
prefix => '', |
114
|
|
|
|
|
|
|
ref $opts eq 'HASH' ? %$opts: (), |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $hub = Kwiki->new->hub; |
118
|
|
|
|
|
|
|
$hub->config->add_config({ database_directory => '' }); |
119
|
|
|
|
|
|
|
$hub->config->script_name($options{prefix}); |
120
|
|
|
|
|
|
|
return $hub->formatter->text_to_html($text); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 LIMITATIONS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
The current version does one and only one thing: send the input to Kwiki and |
126
|
|
|
|
|
|
|
fetch the output AS IS. To customize the output format, one needs to subclass |
127
|
|
|
|
|
|
|
all the necessary Kwiki::Formatter::* modules and rework the HTML output, which |
128
|
|
|
|
|
|
|
is a lot of work. (I will reconsider implementing that based on the number of |
129
|
|
|
|
|
|
|
RT tickets asking for this feature.) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Ruey-Cheng Chen, C<< >> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 BUGS |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Please report any bugs or feature requests to C
|
138
|
|
|
|
|
|
|
rt.cpan.org>, or through the web interface at |
139
|
|
|
|
|
|
|
L. I will be |
140
|
|
|
|
|
|
|
notified, and then you'll automatically be notified of progress on your bug as |
141
|
|
|
|
|
|
|
I make changes. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Copyright 2012 Ruey-Cheng Chen. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
148
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
149
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; # End of Text::KwikiFormat |