line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::WikiConverter::TikiWiki; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24116
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'HTML::WikiConverter'; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
1315
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.50'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
HTML::WikiConverter::TikiWiki - Convert HTML to TikiWiki markup |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use HTML::WikiConverter; |
17
|
|
|
|
|
|
|
my $wc = new HTML::WikiConverter( dialect => 'TikiWiki' ); |
18
|
|
|
|
|
|
|
print $wc->html2wiki( $html ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module contains rules for converting HTML into TikiWiki |
23
|
|
|
|
|
|
|
markup. See L for additional usage details. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Formatting rule documentation: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
* Markup: http://doc.tikiwiki.org/tiki-index.php?page_ref_id=268 |
28
|
|
|
|
|
|
|
* Images: http://doc.tikiwiki.org/tiki-index.php?page_ref_id=277 |
29
|
|
|
|
|
|
|
* Links: http://doc.tikiwiki.org/tiki-index.php?page_ref_id=270 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Unsupported formatting rules: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
* text boxes |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub rules { |
38
|
0
|
|
|
0
|
0
|
|
my %rules = ( |
39
|
|
|
|
|
|
|
b => { start => '__', end => '__' }, |
40
|
|
|
|
|
|
|
strong => { alias => 'b' }, |
41
|
|
|
|
|
|
|
i => { start => "''", end => "''" }, |
42
|
|
|
|
|
|
|
em => { alias => 'i' }, |
43
|
|
|
|
|
|
|
center => { start => '::', end => '::' }, |
44
|
|
|
|
|
|
|
code => { start => '-+', end => '+-' }, |
45
|
|
|
|
|
|
|
tt => { alias => 'code' }, |
46
|
|
|
|
|
|
|
u => { start => '===', end => '===' }, |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
a => { replace => \&_link }, |
49
|
|
|
|
|
|
|
img => { replace => \&_image }, |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
p => { block => 1, trim => 'both', line_format => 'multi' }, |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
ul => { line_format => 'multi', block => 1 }, |
54
|
|
|
|
|
|
|
li => { start => \&_li_start, trim => 'leading' }, |
55
|
|
|
|
|
|
|
ol => { alias => 'ul' }, |
56
|
|
|
|
|
|
|
dl => { alias => 'ul' }, |
57
|
|
|
|
|
|
|
dt => { alias => 'li' }, |
58
|
|
|
|
|
|
|
dd => { alias => 'li' }, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return \%rules; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _li_start { |
65
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
66
|
0
|
|
|
|
|
|
my @parent_lists = $node->look_up( _tag => qr/ul|ol|dl/ ); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $bullet = ''; |
69
|
0
|
0
|
|
|
|
|
$bullet = '*' if $node->parent->tag eq 'ul'; |
70
|
0
|
0
|
|
|
|
|
$bullet = '#' if $node->parent->tag eq 'ol'; |
71
|
0
|
0
|
|
|
|
|
$bullet = ':' if $node->parent->tag eq 'dl'; |
72
|
0
|
0
|
0
|
|
|
|
$bullet = ';' if $node->parent->tag eq 'dl' and $node->tag eq 'dt'; |
73
|
0
|
|
|
|
|
|
$bullet = ( $bullet ) x scalar @parent_lists; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
my $prefix = $node->tag eq 'dd' ? ' ' : "\n"; |
76
|
0
|
|
|
|
|
|
return $prefix.$bullet.' '; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _image { |
80
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
81
|
0
|
|
0
|
|
|
|
my $src = $node->attr('src') || ''; |
82
|
0
|
0
|
|
|
|
|
return '' unless $src; |
83
|
0
|
|
|
|
|
|
my $img_attrs = $self->get_attr_str( $node, qw/ src width height align desc link / ); |
84
|
0
|
|
|
|
|
|
$img_attrs =~ s/"//g; # no quotes allowed! #" emacs |
85
|
0
|
|
|
|
|
|
return "{img $img_attrs}"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _link { |
89
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
90
|
0
|
|
0
|
|
|
|
my $url = $node->attr('href') || ''; |
91
|
0
|
|
0
|
|
|
|
my $text = $self->get_elem_contents($node) || ''; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if( my $title = $self->get_wiki_page($url) ) { |
94
|
0
|
|
|
|
|
|
$title =~ s/_/ /g; |
95
|
0
|
0
|
0
|
|
|
|
return $text if lc $title eq lc $text and $self->is_camel_case($text); |
96
|
0
|
0
|
|
|
|
|
return "(($text))" if lc $text eq lc $title; |
97
|
0
|
|
|
|
|
|
return "(($title|$text))"; |
98
|
|
|
|
|
|
|
} else { |
99
|
0
|
0
|
|
|
|
|
return "[$url]" if $url eq $text; |
100
|
0
|
|
|
|
|
|
return "[$url|$text]"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
David J. Iberri, C<< >> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 BUGS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
111
|
|
|
|
|
|
|
C, or through the web |
112
|
|
|
|
|
|
|
interface at |
113
|
|
|
|
|
|
|
L. |
114
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
115
|
|
|
|
|
|
|
progress on your bug as I make changes. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SUPPORT |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
perldoc HTML::WikiConverter::TikiWiki |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
You can also look for information at: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over 4 |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * CPAN Ratings |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * Search CPAN |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Copyright 2006 David J. Iberri, all rights reserved. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
150
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |