line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Livedoor::Wiki::Plugin::Block::Table; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
142
|
|
4
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
199
|
|
5
|
5
|
|
|
5
|
|
26
|
use base qw(Text::Livedoor::Wiki::Plugin::Block); |
|
5
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
4315
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub check { |
9
|
178
|
|
|
178
|
1
|
298
|
my $self = shift; |
10
|
178
|
|
|
|
|
248
|
my $line = shift; |
11
|
178
|
|
|
|
|
341
|
my $args = shift; |
12
|
178
|
|
|
|
|
301
|
my $id = $args->{id}; |
13
|
178
|
|
|
|
|
319
|
my $on_next = $args->{on_next}; |
14
|
|
|
|
|
|
|
|
15
|
178
|
|
|
|
|
271
|
my $row = ''; |
16
|
178
|
100
|
|
|
|
2599
|
if ( ($row) = $line =~ /^\|(.*)(\||\|\s)$/ ) { |
|
|
100
|
|
|
|
|
|
17
|
58
|
100
|
|
|
|
308
|
unless ($on_next) { |
18
|
41
|
|
|
|
|
112
|
$row =~ s/\|$/\| /; |
19
|
41
|
|
|
|
|
155
|
$row =~ s/\|\|/\| \|/; |
20
|
41
|
|
|
|
|
151
|
$row =~ s/\|\|/\| \|/; |
21
|
|
|
|
|
|
|
} |
22
|
58
|
|
|
|
|
316
|
my @rows = split( /\|/, $row , -1); |
23
|
58
|
|
|
|
|
916
|
return { id => $id , rows => \@rows }; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif ( ($row) = $line =~ /^,(.*)(,|,\s)$/ ) { |
27
|
7
|
100
|
|
|
|
22
|
unless ($on_next) { |
28
|
5
|
|
|
|
|
216
|
$row =~ s/,$/, /; |
29
|
5
|
|
|
|
|
15
|
$row =~ s/,,/, ,/; |
30
|
5
|
|
|
|
|
14
|
$row =~ s/,,/, ,/; |
31
|
|
|
|
|
|
|
} |
32
|
7
|
|
|
|
|
29
|
my @rows = split( ',', $row , -1); |
33
|
7
|
|
|
|
|
200
|
return { id => $id , rows => \@rows }; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
113
|
|
|
|
|
493
|
return; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#{{{ get |
41
|
|
|
|
|
|
|
sub get { |
42
|
25
|
|
|
25
|
1
|
60
|
my $self = shift; |
43
|
25
|
|
|
|
|
51
|
my $block = shift; |
44
|
25
|
|
|
|
|
54
|
my $inline = shift; |
45
|
25
|
|
|
|
|
121
|
my $items = shift; |
46
|
25
|
|
|
|
|
579
|
my $id = $items->[0]{id}; |
47
|
25
|
|
|
|
|
105
|
my $rows = $self->trs($items); |
48
|
25
|
|
|
|
|
63
|
my $data = ''; |
49
|
25
|
|
|
|
|
57
|
for my $row ( @$rows ) { |
50
|
42
|
|
|
|
|
83
|
$data .= " |
\n";
51
|
42
|
|
|
|
|
93
|
for my $col (@$row) { |
52
|
100
|
|
|
|
|
211
|
$data .= qq|<$col->{tag}|; |
53
|
100
|
|
|
|
|
191
|
for ( qw/colspan rowspan/ ) { |
54
|
200
|
100
|
100
|
|
|
1456
|
$data .= qq| $_="$col->{$_}"| if $col->{$_} && $col->{$_} > 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
100
|
|
|
|
|
181
|
my $style = ''; |
58
|
100
|
|
|
|
|
117
|
for my $option ( @{$col->{options}} ) { |
|
100
|
|
|
|
|
268
|
|
59
|
17
|
|
|
|
|
61
|
$style .= qq|$option->{key}:$option->{value};|; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
100
|
|
|
|
|
663
|
my $text = $inline->parse($col->{inline}); |
63
|
100
|
100
|
|
|
|
263
|
$data .= qq| style="$style"| if $style; |
64
|
100
|
|
|
|
|
160
|
$data .= q|>|; |
65
|
100
|
100
|
|
|
|
353
|
$data .= $text ne '' ? $text : ' '; |
66
|
100
|
|
|
|
|
530
|
$data .= qq|$col->{tag}>\n|; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
42
|
|
|
|
|
127
|
$data .= " |
\n";
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
25
|
|
|
|
|
399
|
return qq|\n|; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
sub trs { |
75
|
25
|
|
|
25
|
1
|
56
|
my $self = shift; |
76
|
25
|
|
|
|
|
79
|
my $items = shift; |
77
|
25
|
|
|
|
|
60
|
my @rows = (); |
78
|
25
|
|
|
|
|
55
|
my $rowspan = {}; |
79
|
|
|
|
|
|
|
|
80
|
25
|
|
|
|
|
79
|
for ( reverse @$items ) { |
81
|
42
|
|
|
|
|
81
|
my $remove_cell = {}; |
82
|
42
|
|
|
|
|
75
|
my $colspan_total = 0; |
83
|
42
|
|
|
|
|
170
|
my $row = $self->row($_->{rows}); |
84
|
42
|
|
|
|
|
164
|
for ( my $j = 0; $j < scalar @$row ; $j++ ) { |
85
|
109
|
|
|
|
|
244
|
$colspan_total += $row->[$j]->{colspan} - 1; |
86
|
109
|
100
|
|
|
|
772
|
if( $row->[$j]{inline} =~ /^\^$/ ) { |
87
|
9
|
|
|
|
|
32
|
$rowspan->{$j + $colspan_total }{cnt}++; |
88
|
9
|
|
|
|
|
33
|
$remove_cell->{$j} = 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
100
|
100
|
|
|
|
700
|
if ( $rowspan->{$j + $colspan_total }{cnt} ) { |
92
|
8
|
|
|
|
|
29
|
$row->[$j]->{rowspan} = $rowspan->{$j + $colspan_total }{cnt} + 1; |
93
|
8
|
|
|
|
|
30
|
$rowspan->{$j + $colspan_total}{cnt} = 0; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
42
|
|
|
|
|
79
|
my @new_row = (); |
98
|
42
|
|
|
|
|
76
|
for ( my $j = 0 ; $j < scalar @{$row} ; $j++ ) { |
|
151
|
|
|
|
|
478
|
|
99
|
109
|
100
|
|
|
|
570
|
push @new_row , $row->[$j] unless $remove_cell->{$j}; |
100
|
|
|
|
|
|
|
} |
101
|
42
|
|
|
|
|
259
|
push @rows , \@new_row; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
25
|
|
|
|
|
76
|
@rows = reverse @rows; |
105
|
25
|
|
|
|
|
199
|
return \@rows; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
sub row { |
108
|
42
|
|
|
42
|
1
|
82
|
my $self = shift; |
109
|
42
|
|
|
|
|
188
|
my $cells = shift; |
110
|
42
|
|
|
|
|
186
|
my $on_force_th = 0; |
111
|
42
|
|
|
|
|
181
|
my @row = (); |
112
|
42
|
|
|
|
|
67
|
my $colspan=1; |
113
|
42
|
|
|
|
|
87
|
for my $cell ( @$cells ) { |
114
|
115
|
|
|
|
|
161
|
my @options = (); |
115
|
115
|
|
|
|
|
141
|
my $tag = 'td'; |
116
|
115
|
|
|
|
|
405
|
$cell =~ s/^\s+//; |
117
|
115
|
|
|
|
|
289
|
$cell =~ s/\s+$//; |
118
|
|
|
|
|
|
|
|
119
|
115
|
100
|
|
|
|
567
|
if( $cell =~ /^>$/ ) { |
120
|
6
|
|
|
|
|
8
|
$colspan++; |
121
|
6
|
|
|
|
|
14
|
next; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
# th |
124
|
109
|
100
|
|
|
|
503
|
if( $cell =~ /^\!/ ) { |
|
|
100
|
|
|
|
|
|
125
|
2
|
|
|
|
|
3
|
$tag = 'th'; |
126
|
2
|
|
|
|
|
7
|
$cell =~ s/^\!//; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
# force th |
129
|
|
|
|
|
|
|
elsif( $cell =~ /^~/ ) { |
130
|
3
|
|
|
|
|
7
|
$on_force_th = 1; |
131
|
3
|
|
|
|
|
12
|
$cell =~ s/^~//; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
109
|
100
|
|
|
|
208
|
if( $on_force_th ) { |
135
|
7
|
|
|
|
|
12
|
$tag = 'th'; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
109
|
|
|
|
|
174
|
my $data = {}; |
139
|
109
|
|
|
|
|
231
|
while(1){ |
140
|
126
|
100
|
|
|
|
418
|
if ( my( $style , $value , $left ) = $cell =~ /^(BGCOLOR|COLOR|SIZE|LEFT|CENTER|RIGHT)\s*(?:\(([A-Za-z0-9\-\#]*)\))?\s*:\s*(.*)/i) { |
141
|
17
|
|
|
|
|
32
|
$cell = $left; |
142
|
17
|
|
|
|
|
34
|
$style = lc $style; |
143
|
17
|
100
|
|
|
|
122
|
if( $style eq 'bgcolor' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
144
|
5
|
|
|
|
|
11
|
$style = 'background-color'; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
elsif( $style =~ /left|center|right/ ) { |
147
|
4
|
|
|
|
|
9
|
$value = $style; |
148
|
4
|
|
|
|
|
11
|
$style = 'text-align'; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
elsif( $style eq 'size' ) { |
151
|
3
|
|
|
|
|
7
|
$style = 'font-size'; |
152
|
3
|
|
|
|
|
7
|
$value .= 'px'; |
153
|
|
|
|
|
|
|
} |
154
|
17
|
|
|
|
|
91
|
push @options , { key => $style , value => $value } ; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
else { |
157
|
109
|
|
|
|
|
191
|
last; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
109
|
|
|
|
|
697
|
%$data = ( %$data , ( inline => $cell , options => \@options , tag => $tag , colspan => $colspan ) ); |
161
|
109
|
|
|
|
|
188
|
push @row , $data; |
162
|
|
|
|
|
|
|
|
163
|
109
|
100
|
|
|
|
398
|
if( $colspan > 1 ) { |
164
|
5
|
|
|
|
|
14
|
$colspan = 1; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
42
|
|
|
|
|
134
|
return \@row; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
#}}} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub mobile { |
173
|
2
|
|
|
2
|
1
|
6
|
my $self = shift; |
174
|
2
|
|
|
|
|
4
|
my $block = shift; |
175
|
2
|
|
|
|
|
4
|
my $inline = shift; |
176
|
2
|
|
|
|
|
4
|
my $items = shift; |
177
|
|
|
|
|
|
|
|
178
|
2
|
|
|
|
|
5
|
my $data = ''; |
179
|
|
|
|
|
|
|
|
180
|
2
|
|
|
|
|
5
|
for my $item ( @$items ) { |
181
|
4
|
|
|
|
|
7
|
my $rows = $item->{rows}; |
182
|
4
|
|
|
|
|
10
|
for my $cell ( @$rows ) { |
183
|
18
|
|
|
|
|
37
|
$cell =~ s/^\s+//; |
184
|
18
|
|
|
|
|
34
|
$cell =~ s/\s+$//; |
185
|
18
|
100
|
|
|
|
43
|
next if $cell =~ /^>$/ ; |
186
|
16
|
100
|
|
|
|
42
|
next if $cell =~ /^\^/; |
187
|
|
|
|
|
|
|
|
188
|
14
|
|
|
|
|
18
|
$cell =~ s/^\!//; |
189
|
14
|
|
|
|
|
18
|
$cell =~ s/^~//; |
190
|
14
|
|
|
|
|
15
|
while(1){ |
191
|
16
|
100
|
|
|
|
55
|
if ( my( $style , $value , $left ) = $cell =~ /^(BGCOLOR|COLOR|SIZE|LEFT|CENTER|RIGHT)\s*(?:\(([A-Za-z0-9\-\#]*)\))?\s*:\s*(.*)/i) { |
192
|
2
|
|
|
|
|
4
|
$cell = $left; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
else { |
195
|
14
|
|
|
|
|
18
|
last; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
14
|
|
|
|
|
44
|
$data .= $inline->parse($cell) . ' '; |
200
|
|
|
|
|
|
|
} |
201
|
4
|
|
|
|
|
13
|
$data .= " \n"; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
2
|
|
|
|
|
11
|
return $data; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 NAME |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Text::Livedoor::Wiki::Plugin::Block::Table - Table Block Plugin |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 DESCRIPTION |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
create table. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 SYNOPSIS |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|hoge|hoge| |
221
|
|
|
|
|
|
|
|!hoge|hoge| |
222
|
|
|
|
|
|
|
|~hoge|hoge| |
223
|
|
|
|
|
|
|
|>|hoge| |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
,hoge,hoge, |
226
|
|
|
|
|
|
|
,^,hoge, |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 FUNCTION |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 check |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 get |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 mobile |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 row |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 trs |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 AUTHOR |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
polocky |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=cut |