| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::WikiConverter::Socialtext; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24565
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'HTML::WikiConverter'; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
2094
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
HTML::WikiConverter::Socialtext - Convert HTML to Socialtext markup |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use HTML::WikiConverter; |
|
17
|
|
|
|
|
|
|
my $wc = new HTML::WikiConverter( dialect => 'Socialtext'); |
|
18
|
|
|
|
|
|
|
print $wc->html2wiki( $html ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This module contains rules for converting HTML into Socialtext 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 => "\n" }, |
|
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
|
|
|
|
|
|
|
p => { block => 1, line_format => 'multi' }, |
|
40
|
|
|
|
|
|
|
b => { start => '*', end => '*', line_format => 'single', trim => 'both' }, |
|
41
|
|
|
|
|
|
|
strong => { alias => 'b' }, |
|
42
|
|
|
|
|
|
|
i => { start => '_', end => '_', line_format => 'single', trim => 'both' }, |
|
43
|
|
|
|
|
|
|
em => { alias => 'i' }, |
|
44
|
|
|
|
|
|
|
u => { start => '_', end => '_', line_format => 'single', trim => 'both' }, |
|
45
|
|
|
|
|
|
|
strike => { start => '-', end => '-', line_format => 'single', trim => 'both' }, |
|
46
|
|
|
|
|
|
|
s => { alias => 'strike' }, |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
tt => { start => '`', end => '`', trim => 'both', line_format => 'single' }, |
|
49
|
|
|
|
|
|
|
code => { alias => 'tt' }, |
|
50
|
|
|
|
|
|
|
pre => { start => "\n.pre\n", end => "\n.pre\n", line_prefix => '', line_format => 'blocks' }, |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
a => { replace => \&_link }, |
|
53
|
|
|
|
|
|
|
img => { replace => \&_image }, |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
table => { block => 1, line_format => 'multi', trim => 'none' }, |
|
56
|
|
|
|
|
|
|
tr => { end => " |\n" }, |
|
57
|
|
|
|
|
|
|
td => { start => '| ', end => ' ' }, |
|
58
|
|
|
|
|
|
|
th => { alias => 'td' }, |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
ul => { line_format => 'multi', block => 1 }, |
|
61
|
|
|
|
|
|
|
ol => { alias => 'ul' }, |
|
62
|
|
|
|
|
|
|
li => { start => \&_li_start, trim => 'leading' }, |
|
63
|
|
|
|
|
|
|
dl => { alias => 'ul' }, |
|
64
|
|
|
|
|
|
|
dt => { alias => 'li' }, |
|
65
|
|
|
|
|
|
|
dd => { alias => 'li' }, |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return \%rules; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _li_start { |
|
72
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
73
|
0
|
|
|
|
|
|
my @parent_lists = $node->look_up( _tag => qr/ul|ol|dl/ ); |
|
74
|
0
|
|
|
|
|
|
my $depth = @parent_lists; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $bullet = ''; |
|
77
|
0
|
0
|
|
|
|
|
$bullet = '*' if $node->parent->tag eq 'ul'; |
|
78
|
0
|
0
|
|
|
|
|
$bullet = '>' if $node->parent->tag eq 'dl'; |
|
79
|
0
|
0
|
|
|
|
|
$bullet = '#' if $node->parent->tag eq 'ol'; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $prefix = ( $bullet ) x $depth; |
|
82
|
0
|
|
|
|
|
|
return "\n$prefix "; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _link { |
|
86
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
87
|
0
|
|
0
|
|
|
|
my $url = $node->attr('href') || ''; |
|
88
|
0
|
|
0
|
|
|
|
my $text = $self->get_elem_contents($node) || ''; |
|
89
|
0
|
|
|
|
|
|
$text =~ s/\[(.*)\]/$1/g; |
|
90
|
0
|
0
|
|
|
|
|
if ( $text =~ /image:/ ) { return $text }; |
|
|
0
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $url_check; |
|
93
|
0
|
0
|
|
|
|
|
if ($url =~ /^index.cgi\?/) { |
|
94
|
0
|
|
|
|
|
|
$url_check = $url; |
|
95
|
0
|
|
|
|
|
|
$url_check =~ s/^index.cgi\?//g; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if( my $title = $url_check ) { |
|
99
|
0
|
|
|
|
|
|
my $title_clean = $self->_get_clean_name($title); |
|
100
|
0
|
|
|
|
|
|
my $text_clean = $self->_get_clean_name($text); |
|
101
|
0
|
0
|
|
|
|
|
return "[$text]" if $text_clean eq $title_clean; |
|
102
|
0
|
0
|
|
|
|
|
return "\"$text\"[$title]" if $text ne $title; |
|
103
|
|
|
|
|
|
|
} else { |
|
104
|
0
|
0
|
|
|
|
|
return $url if $text eq $url; |
|
105
|
0
|
|
|
|
|
|
return "\"$text\"<$url>"; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _get_clean_name { |
|
110
|
0
|
|
|
0
|
|
|
my ($self, $text) = @_; |
|
111
|
0
|
|
|
|
|
|
$text =~ s/[_\/\-']/ /g; |
|
112
|
0
|
|
|
|
|
|
$text =~ s/\%20/ /g; |
|
113
|
0
|
|
|
|
|
|
$text =~ s/(\w)/\l$1/g; |
|
114
|
0
|
|
|
|
|
|
return $text; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _image { |
|
118
|
0
|
|
|
0
|
|
|
my( $self, $node, $rules ) = @_; |
|
119
|
0
|
|
|
|
|
|
my $image_file = $node->attr('src'); |
|
120
|
0
|
0
|
|
|
|
|
if ( $image_file !~ /http/) { |
|
121
|
0
|
|
|
|
|
|
$image_file =~ s/.*\/([^\/]+)$/$1/g; |
|
122
|
0
|
|
|
|
|
|
$image_file =~ s/\?action=.*$//g; |
|
123
|
0
|
|
0
|
|
|
|
return '{image: ' . $image_file . '} ' || ''; |
|
124
|
|
|
|
|
|
|
} else { |
|
125
|
0
|
|
|
|
|
|
return $image_file; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub preprocess_node { |
|
130
|
0
|
|
|
0
|
0
|
|
my( $self, $node ) = @_; |
|
131
|
0
|
0
|
|
|
|
|
$self->strip_aname($node) if $node->tag eq 'a'; |
|
132
|
0
|
0
|
|
|
|
|
return unless $node->tag; |
|
133
|
0
|
0
|
|
|
|
|
$self->caption2para($node) if $node->tag eq 'caption'; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub postprocess_output { |
|
139
|
0
|
|
|
0
|
0
|
|
my( $self, $outref ) = @_; |
|
140
|
|
|
|
|
|
|
# We need to deal with the weird rules we have for tables and bullets |
|
141
|
|
|
|
|
|
|
# with postprocessing |
|
142
|
0
|
|
|
|
|
|
$$outref =~ s/\|\n\*/\| \*/gs; |
|
143
|
0
|
|
|
|
|
|
$$outref =~ s/\|\n\#/\| \#/gs; |
|
144
|
0
|
|
|
|
|
|
$$outref =~ s/\n +\| +/ \| /gs; |
|
145
|
0
|
|
|
|
|
|
$$outref =~ s/\n +\|\n/ \|\n/gs; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Kirsten L. Jones<< >> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 BUGS |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
155
|
|
|
|
|
|
|
C, or through the web |
|
156
|
|
|
|
|
|
|
interface at |
|
157
|
|
|
|
|
|
|
L. |
|
158
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
|
159
|
|
|
|
|
|
|
progress on your bug as I make changes. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SUPPORT |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
perldoc HTML::WikiConverter::Socialtext |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
You can also look for information at: |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 4 |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
L |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
L |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
L |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * Search CPAN |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Copyright 2006 Kirsten L. Jones, all rights reserved. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
194
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |