| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::WikiConverter::DokuWiki; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24304
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base 'HTML::WikiConverter'; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
2239
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.53'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
HTML::WikiConverter::DokuWiki - Convert HTML to DokuWiki markup |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use HTML::WikiConverter; |
|
17
|
|
|
|
|
|
|
my $wc = new HTML::WikiConverter( dialect => 'DokuWiki' ); |
|
18
|
|
|
|
|
|
|
print $wc->html2wiki( $html ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module contains rules for converting HTML into DokuWiki |
|
23
|
|
|
|
|
|
|
markup. See L for additional usage details. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
In addition to the regular set of attributes recognized by the |
|
28
|
|
|
|
|
|
|
L constructor, this dialect also accepts the |
|
29
|
|
|
|
|
|
|
following attributes: |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 camel_case |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Boolean indicating whether CamelCase links are enabled in the target DokuWiki |
|
34
|
|
|
|
|
|
|
instance. Enabling CamelCase links will turn HTML like this |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
CamelCase links are fun. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
into this DokuWiki markup: |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
CamelCase links are fun. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Disabling CamelCase links (the default) would convert that HTML into |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
[[CamelCase]] links are fun. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub attributes { { |
|
49
|
0
|
|
|
0
|
0
|
|
camel_case => { default => 0 } |
|
50
|
|
|
|
|
|
|
} } |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub rules { |
|
53
|
0
|
|
|
0
|
0
|
|
my %rules = ( |
|
54
|
|
|
|
|
|
|
b => { start => '**', end => '**' }, |
|
55
|
|
|
|
|
|
|
strong => { alias => 'b' }, |
|
56
|
|
|
|
|
|
|
i => { start => '//', end => '//' }, |
|
57
|
|
|
|
|
|
|
em => { alias => 'i' }, |
|
58
|
|
|
|
|
|
|
u => { start => '__', end => '__' }, |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
tt => { start => '"', end => '"' }, |
|
61
|
|
|
|
|
|
|
code => { alias => 'tt' }, |
|
62
|
|
|
|
|
|
|
a => { replace => \&_link }, |
|
63
|
|
|
|
|
|
|
img => { replace => \&_image }, |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
pre => { line_format => 'blocks', line_prefix => ' ', block => 1 }, |
|
66
|
|
|
|
|
|
|
blockquote => { start => "\n", line_prefix => '>', block => 1, line_format => 'multi', trim => 'leading' }, |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
p => { block => 1, trim => 'both', line_format => 'multi' }, |
|
69
|
|
|
|
|
|
|
br => { replace => "\\\\ " }, |
|
70
|
|
|
|
|
|
|
hr => { replace => "\n----\n" }, |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sup => { preserve => 1 }, |
|
73
|
|
|
|
|
|
|
sub => { preserve => 1 }, |
|
74
|
|
|
|
|
|
|
del => { preserve => 1 }, |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
ul => { line_format => 'multi', block => 1, line_prefix => ' ' }, |
|
77
|
|
|
|
|
|
|
ol => { alias => 'ul' }, |
|
78
|
|
|
|
|
|
|
li => { line_format => 'multi', start => \&_li_start, trim => 'leading' }, |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
table => { block => 1 }, |
|
81
|
|
|
|
|
|
|
tr => { start => "\n", line_format => 'single' }, |
|
82
|
|
|
|
|
|
|
td => { start => \&_td_start, end => \&_td_end, trim => 'both' }, |
|
83
|
|
|
|
|
|
|
th => { alias => 'td' }, |
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
for( 1..5 ) { |
|
87
|
0
|
|
|
|
|
|
my $str = ( '=' ) x (7 - $_ ); |
|
88
|
0
|
|
|
|
|
|
$rules{"h$_"} = { start => "$str ", end => " $str", block => 1, trim => 'both', line_format => 'single' }; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
0
|
|
|
|
|
|
$rules{h6} = { start => '== ', end => ' ==', block => 1, trim => 'both', line_format => 'single' }; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return \%rules; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub postprocess_output { |
|
96
|
0
|
|
|
0
|
0
|
|
my( $self, $outref ) = @_; |
|
97
|
0
|
|
|
|
|
|
$$outref =~ s~^>+\s+~~gm; # rm empty blockquote prefixes |
|
98
|
0
|
|
|
|
|
|
$$outref =~ s~^(>+)~$1 ~gm; # add space after prefix for clarity |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _li_start { |
|
102
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
103
|
0
|
|
|
|
|
|
my @parent_lists = $node->look_up( _tag => qr/ul|ol/ ); |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $bullet = ''; |
|
106
|
0
|
0
|
|
|
|
|
$bullet = '*' if $node->parent->tag eq 'ul'; |
|
107
|
0
|
0
|
|
|
|
|
$bullet = '-' if $node->parent->tag eq 'ol'; |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return "\n$bullet "; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _link { |
|
113
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
114
|
0
|
|
0
|
|
|
|
my $url = $node->attr('href') || ''; |
|
115
|
0
|
|
0
|
|
|
|
my $text = $self->get_elem_contents($node) || ''; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if( my $title = $self->get_wiki_page($url) ) { |
|
118
|
|
|
|
|
|
|
# [[MiXed cAsE]] ==> MiXed cAsE |
|
119
|
0
|
|
|
|
|
|
$title =~ s/_/ /g; |
|
120
|
0
|
0
|
0
|
|
|
|
return $text if $self->camel_case and lc $title eq lc $text and $self->is_camel_case($text); |
|
|
|
|
0
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
return "[[$text]]" if lc $text eq lc $title; |
|
122
|
0
|
|
|
|
|
|
return "[[$title|$text]]"; |
|
123
|
|
|
|
|
|
|
} else { |
|
124
|
0
|
0
|
|
|
|
|
return $url if $url eq $text; |
|
125
|
0
|
|
|
|
|
|
return "[[$url|$text]]"; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _image { |
|
130
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
131
|
0
|
|
0
|
|
|
|
my $src = $node->attr('src') || ''; |
|
132
|
0
|
0
|
|
|
|
|
return '' unless $src; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
0
|
|
|
|
my $w = $node->attr('width') || 0; |
|
135
|
0
|
|
0
|
|
|
|
my $h = $node->attr('height') || 0; |
|
136
|
0
|
0
|
0
|
|
|
|
if( $w and $h ) { |
|
|
|
0
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
$src .= "?${w}x${h}"; |
|
138
|
|
|
|
|
|
|
} elsif( $w ) { |
|
139
|
0
|
|
|
|
|
|
$src .= "?${w}"; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
0
|
|
|
|
my $class = $node->attr('class') || ''; |
|
143
|
0
|
0
|
0
|
|
|
|
my $padleft = $class eq 'mediaright' || $class eq 'mediacenter' ? ' ' : ''; |
|
144
|
0
|
0
|
0
|
|
|
|
my $padright = $class eq 'medialeft' || $class eq 'mediacenter' ? ' ' : ''; |
|
145
|
0
|
|
|
|
|
|
$src = "$padleft$src$padright"; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# All images considered external |
|
148
|
0
|
|
0
|
|
|
|
my $caption = $node->attr('title') || $node->attr('alt') || ''; |
|
149
|
0
|
0
|
|
|
|
|
return "{{$src|$caption}}" if $caption; |
|
150
|
0
|
|
|
|
|
|
return "{{$src}}"; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _td_start { |
|
154
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
155
|
0
|
0
|
|
|
|
|
my $prefix = $node->tag eq 'th' ? '^' : '|'; |
|
156
|
0
|
|
|
|
|
|
$prefix .= ' '; |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
0
|
|
|
|
my $class = $node->attr('class') || ''; |
|
159
|
0
|
0
|
0
|
|
|
|
$prefix .= ' ' if $class eq 'rightalign' or $class eq 'centeralign'; |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return $prefix; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _td_end { |
|
165
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $end = ' '; |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
0
|
|
|
|
my $class = $node->attr('class') || ''; |
|
170
|
0
|
0
|
0
|
|
|
|
$end .= ' ' if $class eq 'leftalign' or $class eq 'centeralign'; |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
0
|
|
|
|
my $colspan = $node->attr('colspan') || 1; |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
|
my @right_cells = grep { $_->tag && $_->tag =~ /th|td/ } $node->right; |
|
|
0
|
|
|
|
|
|
|
|
175
|
0
|
0
|
0
|
|
|
|
return $end if $colspan == 1 and @right_cells; |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
|
my $suffix = $node->tag eq 'th' ? '^' : '|'; |
|
178
|
0
|
|
|
|
|
|
$suffix = ( $suffix ) x $colspan; |
|
179
|
0
|
|
|
|
|
|
return $end.$suffix; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 AUTHOR |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
David J. Iberri, C<< >> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 BUGS |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
189
|
|
|
|
|
|
|
C, or through the web |
|
190
|
|
|
|
|
|
|
interface at |
|
191
|
|
|
|
|
|
|
L. |
|
192
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
|
193
|
|
|
|
|
|
|
progress on your bug as I make changes. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 SUPPORT |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
perldoc HTML::WikiConverter::DokuWiki |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
You can also look for information at: |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=over 4 |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
L |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
L |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * Search CPAN |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
L |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=back |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Copyright 2006 David J. Iberri, all rights reserved. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
228
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
1; |