line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xatena::Node::Table; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
105
|
use strict; |
|
17
|
|
|
|
|
37
|
|
|
17
|
|
|
|
|
522
|
|
4
|
17
|
|
|
17
|
|
84
|
use warnings; |
|
17
|
|
|
|
|
35
|
|
|
17
|
|
|
|
|
597
|
|
5
|
17
|
|
|
17
|
|
83
|
use base qw(Text::Xatena::Node); |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
285
|
|
6
|
|
|
|
|
|
|
use constant { |
7
|
17
|
|
|
|
|
6658
|
TABLE => qr/^\|/, |
8
|
17
|
|
|
17
|
|
108
|
}; |
|
17
|
|
|
|
|
37
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub parse { |
11
|
299
|
|
|
299
|
0
|
464
|
my ($class, $s, $parent, $stack) = @_; |
12
|
299
|
100
|
|
|
|
751
|
if ($s->scan(TABLE)) { |
13
|
4
|
|
|
|
|
20
|
my $a = $class->new([ $s->matched->[0] ]); |
14
|
4
|
|
100
|
|
|
18
|
until ($s->eos || !$s->scan(TABLE)) { |
15
|
7
|
|
|
|
|
363
|
push @$a, $s->matched->[0]; |
16
|
|
|
|
|
|
|
} |
17
|
4
|
|
|
|
|
220
|
push @$parent, $a; |
18
|
4
|
|
|
|
|
31
|
return 1; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub as_struct { |
23
|
3
|
|
|
3
|
0
|
8
|
my ($self, $context) = @_; |
24
|
3
|
|
|
|
|
7
|
my $ret = []; |
25
|
3
|
|
|
|
|
17
|
my $children = $self->children; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
9
|
for my $line (@$children) { |
28
|
8
|
|
|
|
|
21
|
my $row = []; |
29
|
8
|
|
|
|
|
27
|
for my $col (split /\|/, $line) { |
30
|
32
|
|
|
|
|
279
|
my ($th, $content) = ($col =~ /^(\*)?(.*)$/); |
31
|
32
|
100
|
|
|
|
142
|
push @$row, +{ |
32
|
|
|
|
|
|
|
name => ($th ? 'th' : 'td'), |
33
|
|
|
|
|
|
|
content => $context->inline->format($content), |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
8
|
|
|
|
|
155
|
shift @$row; |
37
|
8
|
|
|
|
|
28
|
push @$ret, $row; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
23
|
$ret; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub as_html { |
44
|
3
|
|
|
3
|
0
|
7
|
my ($self, $context, %opts) = @_; |
45
|
3
|
|
|
|
|
8
|
$context->_tmpl(__PACKAGE__, q[ |
46
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
? for my $row (@$rows) { |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
? for my $col (@$row) { |
50
|
|
|
|
|
|
|
<{{= $col->{name} }}>{{= $col->{content} }}{{= $col->{name} }}> |
51
|
|
|
|
|
|
|
? } |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
? } |
54
|
|
|
|
|
|
|
| |
55
|
|
|
|
|
|
|
], { |
56
|
|
|
|
|
|
|
rows => $self->as_struct($context) |
57
|
|
|
|
|
|
|
}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |