| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::WikiConverter::PmWiki; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24204
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use base 'HTML::WikiConverter'; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
1939
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.51'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
HTML::WikiConverter::PmWiki - Convert HTML to PmWiki markup |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use HTML::WikiConverter; |
|
17
|
|
|
|
|
|
|
my $wc = new HTML::WikiConverter( dialect => 'PmWiki' ); |
|
18
|
|
|
|
|
|
|
print $wc->html2wiki( $html ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module contains rules for converting HTML into PmWiki markup. See |
|
23
|
|
|
|
|
|
|
L for additional usage details. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub rules { |
|
28
|
0
|
|
|
0
|
0
|
|
my %rules = ( |
|
29
|
|
|
|
|
|
|
hr => { replace => "\n----\n" }, |
|
30
|
|
|
|
|
|
|
br => { replace => \&_br }, |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
h1 => { start => '! ', block => 1, trim => 'both', line_format => 'single' }, |
|
33
|
|
|
|
|
|
|
h2 => { start => '!! ', block => 1, trim => 'both', line_format => 'single' }, |
|
34
|
|
|
|
|
|
|
h3 => { start => '!!! ', block => 1, trim => 'both', line_format => 'single' }, |
|
35
|
|
|
|
|
|
|
h4 => { start => '!!!! ', block => 1, trim => 'both', line_format => 'single' }, |
|
36
|
|
|
|
|
|
|
h5 => { start => '!!!!! ', block => 1, trim => 'both', line_format => 'single' }, |
|
37
|
|
|
|
|
|
|
h6 => { start => '!!!!!! ', block => 1, trim => 'both', line_format => 'single' }, |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
blockquote => { start => \&_blockquote_start, trim => 'both', block => 1, line_format => 'multi' }, |
|
40
|
|
|
|
|
|
|
pre => { line_prefix => ' ', block => 1 }, |
|
41
|
|
|
|
|
|
|
p => { block => 1, trim => 'both', line_format => 'multi' }, |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
b => { start => "'''", end => "'''", line_format => 'single' }, |
|
44
|
|
|
|
|
|
|
strong => { alias => 'b' }, |
|
45
|
|
|
|
|
|
|
i => { start => "''", end => "''", line_format => 'single' }, |
|
46
|
|
|
|
|
|
|
em => { alias => 'i' }, |
|
47
|
|
|
|
|
|
|
tt => { start => '@@', end => '@@', trim => 'both', line_format => 'single' }, |
|
48
|
|
|
|
|
|
|
code => { alias => 'tt' }, |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
big => { start => "'+", end => "+'", line_format => 'single' }, |
|
51
|
|
|
|
|
|
|
small => { start => "'-", end => "-'", line_format => 'single' }, |
|
52
|
|
|
|
|
|
|
sup => { start => "'^", end => "^'", line_format => 'single' }, |
|
53
|
|
|
|
|
|
|
sub => { start => "'_", end => "_'", line_format => 'single' }, |
|
54
|
|
|
|
|
|
|
ins => { start => '{+', end => '+}', line_format => 'single' }, |
|
55
|
|
|
|
|
|
|
del => { start => '{-', end => '-}', line_format => 'single' }, |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
ul => { line_format => 'multi', block => 1 }, |
|
58
|
|
|
|
|
|
|
ol => { alias => 'ul' }, |
|
59
|
|
|
|
|
|
|
li => { start => \&_li_start, trim => 'leading' }, |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
dl => { alias => 'ul' }, |
|
62
|
|
|
|
|
|
|
dt => { start => \&_li_start, line_format => 'single', trim => 'both' }, |
|
63
|
|
|
|
|
|
|
dd => { start => ': ' }, |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
a => { replace => \&_link }, |
|
66
|
|
|
|
|
|
|
img => { replace => \&_image }, |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
table => { start => \&_table_start, block => 1 }, |
|
69
|
|
|
|
|
|
|
tr => { start => "\n||", line_format => 'single' }, |
|
70
|
|
|
|
|
|
|
td => { start => \&_td_start, end => \&_td_end, trim => 'both' }, |
|
71
|
|
|
|
|
|
|
th => { alias => 'td' } |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return \%rules; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _br { |
|
78
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
79
|
0
|
0
|
|
|
|
|
return " [[<<]] " if $node->look_up( _tag => 'table' ); |
|
80
|
0
|
|
|
|
|
|
return " \\\\\n"; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _table_start { |
|
84
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
85
|
0
|
|
|
|
|
|
my @attrs = qw/ border cellpadding cellspacing width bgcolor align /; |
|
86
|
0
|
|
|
|
|
|
return '|| '.$self->get_attr_str( $node, @attrs ); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _td_start { |
|
90
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
91
|
0
|
0
|
|
|
|
|
my $prefix = $node->tag eq 'th' ? '!' : ''; |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
0
|
|
|
|
my $align = $node->attr('align') || 'left'; |
|
94
|
0
|
0
|
0
|
|
|
|
$prefix .= ' ' if $align eq 'center' or $align eq 'right'; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $prefix; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _td_end { |
|
100
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
101
|
0
|
|
0
|
|
|
|
my $colspan = $node->attr('colspan') || 1; |
|
102
|
0
|
|
|
|
|
|
my $suffix = ( '||' ) x $colspan; |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
0
|
|
|
|
my $align = $node->attr('align') || 'left'; |
|
105
|
0
|
0
|
0
|
|
|
|
$suffix = ' '.$suffix if $align eq 'center' or $align eq 'left'; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $suffix; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _blockquote_start { |
|
111
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
112
|
0
|
|
|
|
|
|
my @parent_bqs = $node->look_up( _tag => 'blockquote' ); |
|
113
|
0
|
|
|
|
|
|
my $depth = @parent_bqs; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $start = ( '-' ) x $depth; |
|
116
|
0
|
|
|
|
|
|
return "\n".$start.'>'; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _li_start { |
|
120
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
121
|
0
|
|
|
|
|
|
my @parent_lists = $node->look_up( _tag => qr/ul|ol|dl/ ); |
|
122
|
0
|
|
|
|
|
|
my $depth = @parent_lists; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $bullet = ''; |
|
125
|
0
|
0
|
|
|
|
|
$bullet = '*' if $node->parent->tag eq 'ul'; |
|
126
|
0
|
0
|
|
|
|
|
$bullet = '#' if $node->parent->tag eq 'ol'; |
|
127
|
0
|
0
|
|
|
|
|
$bullet = ':' if $node->parent->tag eq 'dl'; |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my $prefix = ( $bullet ) x $depth; |
|
130
|
0
|
|
|
|
|
|
return "\n".$prefix.' '; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _link { |
|
134
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
135
|
0
|
0
|
|
|
|
|
return $self->_anchor($node, $rules) if $node->attr('name'); |
|
136
|
|
|
|
|
|
|
|
|
137
|
0
|
|
0
|
|
|
|
my $url = $node->attr('href') || ''; |
|
138
|
0
|
|
0
|
|
|
|
my $text = $self->get_elem_contents($node) || ''; |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
return $url if $text eq $url; |
|
141
|
0
|
|
|
|
|
|
return "[[$url | $text]]"; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub _anchor { |
|
145
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
146
|
0
|
|
0
|
|
|
|
my $name = $node->attr('name') || ''; |
|
147
|
0
|
|
|
|
|
|
return "[[#$name]]"; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _image { |
|
151
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
152
|
0
|
|
0
|
|
|
|
return $node->attr('src') || ''; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub preprocess_node { |
|
156
|
0
|
|
|
0
|
0
|
|
my( $self, $node ) = @_; |
|
157
|
0
|
|
0
|
|
|
|
my $tag = $node->tag || ''; |
|
158
|
0
|
0
|
0
|
|
|
|
$self->_move_aname($node) if $tag eq 'a' and $node->attr('name'); |
|
159
|
0
|
0
|
|
|
|
|
$self->caption2para($node) if $tag eq 'caption'; |
|
160
|
0
|
0
|
0
|
|
|
|
if( $tag eq '~text' and $node->left and $node->left->tag and $node->left->tag eq 'br' and !$node->look_up(_tag => 'pre') ) { |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
( my $text = $node->attr('text') ) =~ s/^\s+//; |
|
162
|
0
|
|
|
|
|
|
$node->attr( text => $text ); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub _move_aname { |
|
167
|
0
|
|
|
0
|
|
|
my( $self, $node ) = @_; |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
0
|
|
|
|
my $name = $node->attr('name') || ''; |
|
170
|
0
|
|
|
|
|
|
$node->attr( name => undef ); |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $aname = new HTML::Element( 'a', name => $name ); |
|
173
|
0
|
|
|
|
|
|
$node->preinsert($aname); |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# Keep 'a href's around |
|
176
|
0
|
0
|
|
|
|
|
$node->replace_with_content->delete unless $node->attr('href'); |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHOR |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
David J. Iberri, C<< >> |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 BUGS |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
186
|
|
|
|
|
|
|
C, or through the web |
|
187
|
|
|
|
|
|
|
interface at |
|
188
|
|
|
|
|
|
|
L. |
|
189
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
|
190
|
|
|
|
|
|
|
progress on your bug as I make changes. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 SUPPORT |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
perldoc HTML::WikiConverter::PmWiki |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
You can also look for information at: |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=over 4 |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * Search CPAN |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
L |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Copyright 2006 David J. Iberri, all rights reserved. |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
225
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
1; |