line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WikiText::WikiByte::Emitter; |
2
|
3
|
|
|
3
|
|
2513
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
104
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2600
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub new { |
6
|
46
|
|
|
46
|
0
|
939
|
my $class = shift; |
7
|
46
|
|
66
|
|
|
399
|
return bless { |
8
|
|
|
|
|
|
|
@_, |
9
|
|
|
|
|
|
|
last_event => '', |
10
|
|
|
|
|
|
|
}, ref($class) || $class; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
10
|
|
|
10
|
0
|
14
|
my $self = shift; |
15
|
10
|
|
|
|
|
32
|
$self->{output} = ''; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub content { |
19
|
10
|
|
|
10
|
0
|
13
|
my $self = shift; |
20
|
10
|
|
|
|
|
233
|
return $self->{output}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub insert { |
24
|
36
|
|
|
36
|
0
|
59
|
my $self = shift; |
25
|
36
|
|
|
|
|
46
|
my $ast = shift; |
26
|
36
|
50
|
|
|
|
71
|
if ($self->{last_event} eq 'text') { |
27
|
0
|
|
|
|
|
0
|
chomp $self->{output}; |
28
|
0
|
|
0
|
|
|
0
|
my $subtext = $ast->{output} || ''; |
29
|
0
|
|
|
|
|
0
|
$subtext =~ s/^ //; |
30
|
0
|
|
|
|
|
0
|
$self->{output} .= $subtext; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
36
|
|
100
|
|
|
152
|
$self->{output} .= $ast->{output} || ''; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub begin_node { |
38
|
36
|
|
|
36
|
0
|
50
|
my $self = shift; |
39
|
36
|
|
|
|
|
38
|
my $node = shift; |
40
|
36
|
|
|
|
|
53
|
my $tag = $node->{type}; |
41
|
36
|
|
|
|
|
54
|
$tag =~ s/-.*//; |
42
|
36
|
|
|
|
|
67
|
my $attributes = _get_attributes($node); |
43
|
36
|
|
|
|
|
98
|
$self->{output} .= "+$tag$attributes\n"; |
44
|
36
|
|
|
|
|
102
|
$self->{last_event} = 'begin'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub end_node { |
48
|
36
|
|
|
36
|
0
|
57
|
my $self = shift; |
49
|
36
|
|
|
|
|
38
|
my $node = shift; |
50
|
36
|
|
|
|
|
47
|
my $tag = $node->{type}; |
51
|
|
|
|
|
|
|
|
52
|
36
|
|
|
|
|
50
|
$self->{last_event} = 'end'; |
53
|
|
|
|
|
|
|
|
54
|
36
|
100
|
|
|
|
639
|
return if $self->{output} =~ s/^\+$tag\b(.*\n)\z/=$tag$1/m; |
55
|
|
|
|
|
|
|
|
56
|
34
|
|
|
|
|
63
|
$tag =~ s/-.*//; |
57
|
34
|
|
|
|
|
322
|
$self->{output} .= "-$tag\n"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub text_node { |
61
|
38
|
|
|
38
|
0
|
46
|
my $self = shift; |
62
|
38
|
|
|
|
|
54
|
my $text = shift; |
63
|
38
|
|
|
|
|
48
|
$text =~ s/\n/\n /g; |
64
|
38
|
50
|
|
|
|
80
|
if ($self->{last_event} eq 'text') { |
65
|
0
|
|
|
|
|
0
|
chomp $self->{output}; |
66
|
0
|
|
|
|
|
0
|
$self->{output} .= "$text\n"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else { |
69
|
38
|
|
|
|
|
103
|
$self->{output} .= " $text\n"; |
70
|
|
|
|
|
|
|
} |
71
|
38
|
|
|
|
|
115
|
$self->{last_event} = 'text'; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _get_attributes { |
75
|
36
|
|
|
36
|
|
37
|
my $node = shift; |
76
|
36
|
50
|
|
|
|
234
|
return "" unless exists $node->{attributes}; |
77
|
0
|
|
|
|
|
|
return join "", map { |
78
|
0
|
|
|
|
|
|
qq{ $_="${\ $node->{attributes}->{$_}}"} |
|
0
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
} sort keys %{$node->{attributes}}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |