line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::WikiConverter::WikkaWiki; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
41679
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'HTML::WikiConverter'; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
708
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6432
|
use URI; |
|
1
|
|
|
|
|
42198
|
|
|
1
|
|
|
|
|
816
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.50'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
HTML::WikiConverter::WikkaWiki - Convert HTML to WikkaWiki markup |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use HTML::WikiConverter; |
18
|
|
|
|
|
|
|
my $wc = new HTML::WikiConverter( dialect => 'WikkaWiki' ); |
19
|
|
|
|
|
|
|
print $wc->html2wiki( $html ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This module contains rules for converting HTML into WikkaWiki |
24
|
|
|
|
|
|
|
markup. See L for additional usage details. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub rules { |
29
|
0
|
|
|
0
|
0
|
|
my %rules = ( |
30
|
|
|
|
|
|
|
b => { start => '**', end => '**' }, |
31
|
|
|
|
|
|
|
strong => { alias => 'b' }, |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
i => { start => '//', end => '//' }, |
34
|
|
|
|
|
|
|
em => { alias => 'i' }, |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
u => { start => '__', end => '__' }, |
37
|
|
|
|
|
|
|
tt => { start => '##', end => '##' }, |
38
|
|
|
|
|
|
|
code => { alias => 'tt' }, |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
strike => { start => '++', end => '++' }, |
41
|
|
|
|
|
|
|
kbd => { start => '#%', end => '#%' }, |
42
|
|
|
|
|
|
|
center => { start => '@@', end => '@@' }, |
43
|
|
|
|
|
|
|
br => { replace => '---' }, |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# table |
46
|
|
|
|
|
|
|
tr => { line_format => 'single', start => '|| ', end => "\n" }, |
47
|
|
|
|
|
|
|
td => { end => ' || ' }, |
48
|
|
|
|
|
|
|
th => { alias => 'td' }, |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
ul => { line_format => 'multi', block => 1 }, |
51
|
|
|
|
|
|
|
ol => { alias => 'ul' }, |
52
|
|
|
|
|
|
|
li => { line_format => 'multi', start => \&_li_start, trim => 'leading' }, |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
img => { replace => \&_image }, |
55
|
|
|
|
|
|
|
a => { replace => \&_link }, |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
p => { block => 1, trim => 'both', line_format => 'multi' }, |
58
|
|
|
|
|
|
|
hr => { replace => "\n----\n" }, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
for( 1..5 ) { |
62
|
0
|
|
|
|
|
|
my $str = ( '=' ) x (7 - $_ ); |
63
|
0
|
|
|
|
|
|
$rules{"h$_"} = { start => "$str ", end => " $str", block => 1, trim => 'both', line_format => 'single' }; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
$rules{h6} = { alias => 'h5' }; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return \%rules; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# {{image class="center" alt="DVD logo" title="An Image Link" url="images/dvdvideo.gif" link="RecentChanges"}} |
71
|
|
|
|
|
|
|
sub _image { |
72
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
73
|
0
|
0
|
|
|
|
|
return '' unless $node->attr('src'); |
74
|
0
|
|
|
|
|
|
$node->attr( src => URI->new($node->attr('src'))->rel($self->base_uri) ); |
75
|
0
|
|
|
|
|
|
my $attr_str = $self->get_attr_str( $node, qw/ alt title src wikka_link / ); |
76
|
0
|
|
|
|
|
|
return "{{image $attr_str}}"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _li_start { |
80
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
81
|
0
|
|
|
|
|
|
my @parent_lists = $node->look_up( _tag => qr/ul|ol/ ); |
82
|
0
|
|
|
|
|
|
my $depth = @parent_lists; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
my $bullet = $node->parent->tag eq 'ol' ? '1)' : '-'; |
85
|
0
|
|
|
|
|
|
my $indent = ( '~' ) x $depth; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return "\n".$indent.$bullet.' '; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _link { |
91
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
92
|
0
|
|
0
|
|
|
|
my $url = $node->attr('href') || ''; |
93
|
0
|
|
0
|
|
|
|
my $text = $self->get_elem_contents($node) || ''; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if( my $title = $self->get_wiki_page($url) ) { |
96
|
0
|
|
|
|
|
|
$title =~ s/_/ /g; |
97
|
0
|
0
|
0
|
|
|
|
return $text if lc $title eq lc $text and $self->is_camel_case($text); |
98
|
0
|
|
|
|
|
|
return "[[$title $text]]"; |
99
|
|
|
|
|
|
|
} else { |
100
|
0
|
0
|
|
|
|
|
return $url if $url eq $text; |
101
|
0
|
|
|
|
|
|
return "[[$url $text]]"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub preprocess_node { |
106
|
0
|
|
|
0
|
0
|
|
my( $self, $node ) = @_; |
107
|
|
|
|
|
|
|
# FIXME: What if img isn't the only thing under this anchor tag? |
108
|
0
|
0
|
0
|
|
|
|
return unless $node->tag eq 'img' and $node->parent->tag eq 'a'; |
109
|
0
|
|
|
|
|
|
$node->attr( wikka_link => $node->parent->attr('href') ); |
110
|
0
|
|
|
|
|
|
$node->parent->replace_with_content()->delete; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 AUTHOR |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
David J. Iberri, C<< >> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 BUGS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
120
|
|
|
|
|
|
|
C, or through the web |
121
|
|
|
|
|
|
|
interface at |
122
|
|
|
|
|
|
|
L. |
123
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
124
|
|
|
|
|
|
|
progress on your bug as I make changes. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SUPPORT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
perldoc HTML::WikiConverter::WikkaWiki |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
You can also look for information at: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over 4 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * CPAN Ratings |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * Search CPAN |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Copyright 2006 David J. Iberri, all rights reserved. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
159
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |