line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WikiText::HTML::Emitter; |
2
|
3
|
|
|
3
|
|
1913
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
103
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
14
|
use base 'WikiText::Emitter'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
783
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
2697
|
use CGI::Util; |
|
3
|
|
|
|
|
18005
|
|
|
3
|
|
|
|
|
2463
|
|
7
|
|
|
|
|
|
|
|
8
|
22
|
50
|
|
22
|
0
|
164
|
sub break_lines {@_>1?($_[0]->{break_lines}=$_[1]):$_[0]->{break_lines}} |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $type_tags = { |
11
|
|
|
|
|
|
|
b => 'strong', |
12
|
|
|
|
|
|
|
i => 'em', |
13
|
|
|
|
|
|
|
wikilink => 'a', |
14
|
|
|
|
|
|
|
hyperlink => 'a', |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub uri_escape { |
18
|
0
|
|
|
0
|
0
|
0
|
$_ = shift; |
19
|
0
|
|
|
|
|
0
|
s/ /\%20/g; |
20
|
0
|
|
|
|
|
0
|
return $_; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub begin_node { |
24
|
20
|
|
|
20
|
0
|
26
|
my $self = shift; |
25
|
20
|
|
|
|
|
24
|
my $node = shift; |
26
|
20
|
|
|
|
|
29
|
my $type = $node->{type}; |
27
|
20
|
|
66
|
|
|
74
|
my $tag = $type_tags->{$type} || $type; |
28
|
|
|
|
|
|
|
# XXX For tables maybe... |
29
|
|
|
|
|
|
|
# $tag =~ s/-.*//; |
30
|
20
|
50
|
|
|
|
179
|
$self->{output} .= |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
31
|
|
|
|
|
|
|
($tag =~ /^(br|hr)$/) |
32
|
|
|
|
|
|
|
? "<$tag />\n" |
33
|
|
|
|
|
|
|
: ($type eq "hyperlink") |
34
|
|
|
|
|
|
|
? $self->begin_hyperlink($node) |
35
|
|
|
|
|
|
|
: ($type eq "wikilink") |
36
|
|
|
|
|
|
|
? $self->begin_wikilink($node) |
37
|
|
|
|
|
|
|
: "<$tag>" . |
38
|
|
|
|
|
|
|
($tag =~ /^(ul|ol|table|tr)$/ ? "\n" : ""); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub begin_hyperlink { |
42
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
43
|
0
|
|
|
|
|
0
|
my $node = shift; |
44
|
0
|
|
|
|
|
0
|
my $tag = $node->{type}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
my $link = $node->{attributes}{target}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
return qq{}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub begin_wikilink { |
52
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
53
|
0
|
|
|
|
|
0
|
my $node = shift; |
54
|
0
|
|
|
|
|
0
|
my $tag = $node->{type}; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
0
|
my $link = $self->{callbacks}{wikilink} |
57
|
|
|
|
|
|
|
? $self->{callbacks}{wikilink}->($node) |
58
|
|
|
|
|
|
|
: CGI::Util::escape($node->{attributes}{target}); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
my $class = $node->{attributes}{class}; |
61
|
0
|
0
|
|
|
|
0
|
$class = $class ? qq{ class="$class"} : ''; |
62
|
0
|
|
|
|
|
0
|
return qq{}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub end_node { |
66
|
20
|
|
|
20
|
0
|
23
|
my $self = shift; |
67
|
20
|
|
|
|
|
21
|
my $node = shift; |
68
|
20
|
|
|
|
|
35
|
my $type = $node->{type}; |
69
|
20
|
|
66
|
|
|
129
|
my $tag = $type_tags->{$type} || $type; |
70
|
20
|
|
|
|
|
37
|
$tag =~ s/-.*//; |
71
|
20
|
50
|
|
|
|
52
|
return if ($tag =~ /^(br|hr)$/); |
72
|
20
|
100
|
|
|
|
228
|
$self->{output} .= "$tag>" . |
73
|
|
|
|
|
|
|
($tag =~ /^(p|hr|ul|ol|li|h\d|table|tr|td|pre)$/ ? "\n" : ""); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub text_node { |
77
|
22
|
|
|
22
|
0
|
31
|
my $self = shift; |
78
|
22
|
|
|
|
|
30
|
my $text = shift; |
79
|
22
|
50
|
|
|
|
47
|
if ($self->break_lines) { |
80
|
0
|
|
|
|
|
0
|
$text =~ s/\n/ \n/g; |
81
|
|
|
|
|
|
|
} |
82
|
22
|
|
|
|
|
87
|
$self->{output} .= "$text"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |