line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: LIST.pm 284 2006-12-01 07:51:49Z chronos $ |
2
|
|
|
|
|
|
|
package BBCode::Tag::LIST; |
3
|
3
|
|
|
3
|
|
18
|
use base qw(BBCode::Tag::Block); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
291
|
|
4
|
3
|
|
|
3
|
|
18
|
use BBCode::Util qw(:parse encodeHTML multilineText createListSequence); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
802
|
|
5
|
3
|
|
|
3
|
|
599
|
use BBCode::Tag::TEXT (); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
63
|
|
6
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
186
|
|
7
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
4690
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub Class($):method { |
11
|
19
|
|
|
19
|
1
|
62
|
return qw(LIST BLOCK); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub BodyPermitted($):method { |
15
|
68
|
|
|
68
|
1
|
309
|
return 1; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub BodyTags($):method { |
19
|
20
|
|
|
20
|
1
|
71
|
return qw(LI TEXT); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub NamedParams($):method { |
23
|
18
|
|
|
18
|
1
|
81
|
return qw(TYPE START BULLET OUTSIDE); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub RequiredParams($):method { |
27
|
0
|
|
|
0
|
1
|
0
|
return (); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub DefaultParam($):method { |
31
|
1
|
|
|
1
|
1
|
23
|
return 'TYPE'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub validateParam($$$):method { |
35
|
2
|
|
|
2
|
1
|
4
|
my($this,$param,$val) = @_; |
36
|
2
|
100
|
|
|
|
10
|
if($param eq 'TYPE') { |
37
|
1
|
50
|
|
|
|
6
|
return $val if parseListType($val) > 0; |
38
|
0
|
|
|
|
|
0
|
return '*'; |
39
|
|
|
|
|
|
|
} |
40
|
1
|
50
|
|
|
|
4
|
if($param eq 'START') { |
41
|
0
|
|
|
|
|
0
|
return parseInt $val; |
42
|
|
|
|
|
|
|
} |
43
|
1
|
50
|
|
|
|
5
|
if($param eq 'BULLET') { |
44
|
1
|
|
|
|
|
5
|
my $url = parseURL($val); |
45
|
1
|
50
|
|
|
|
10
|
if(defined $url) { |
46
|
0
|
|
|
|
|
0
|
return $url->as_string; |
47
|
|
|
|
|
|
|
} else { |
48
|
1
|
|
|
|
|
39
|
die qq(Invalid value "$val" for [LIST BULLET]); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
0
|
0
|
|
|
|
0
|
if($param eq 'OUTSIDE') { |
52
|
0
|
|
|
|
|
0
|
return parseBool $val; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
0
|
return $this->SUPER::validateParam($param,$val); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _text($$):method { |
58
|
0
|
|
|
0
|
|
0
|
my $this = shift; |
59
|
0
|
|
|
|
|
0
|
my $text = shift; |
60
|
0
|
|
|
|
|
0
|
my $tag = BBCode::Tag->new($this->parser, 'TEXT', [ undef, $text ]); |
61
|
0
|
|
|
|
|
0
|
return $tag; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _li($$):method { |
65
|
0
|
|
|
0
|
|
0
|
my $this = shift; |
66
|
0
|
|
|
|
|
0
|
my $text = shift; |
67
|
0
|
|
|
|
|
0
|
my $tag = BBCode::Tag->new($this->parser, 'LI'); |
68
|
0
|
|
|
|
|
0
|
$tag->pushBody($this->_text($text)); |
69
|
0
|
|
|
|
|
0
|
return $tag; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub pushBody($@):method { |
73
|
41
|
|
|
41
|
1
|
63
|
my $this = shift; |
74
|
41
|
|
|
|
|
55
|
my @tags; |
75
|
|
|
|
|
|
|
|
76
|
41
|
|
|
|
|
150
|
while(@_) { |
77
|
41
|
|
|
|
|
58
|
my $tag = shift; |
78
|
|
|
|
|
|
|
|
79
|
41
|
50
|
|
|
|
129
|
next if not defined $tag; |
80
|
|
|
|
|
|
|
|
81
|
41
|
50
|
|
|
|
99
|
if(not ref $tag) { |
82
|
0
|
|
|
|
|
0
|
unshift @_, $this->_text($tag); |
83
|
0
|
|
|
|
|
0
|
next; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
41
|
100
|
|
|
|
255
|
if(UNIVERSAL::isa($tag,'BBCode::Tag::TEXT')) { |
87
|
22
|
|
|
|
|
60
|
my $str = $tag->param(undef); |
88
|
22
|
50
|
|
|
|
104
|
unless($str =~ /^\s*$/) { |
89
|
0
|
0
|
|
|
|
0
|
push @tags, $this->_text("$1") if $str =~ s/^(\s+)//; |
90
|
0
|
0
|
|
|
|
0
|
unshift @_, $this->_text("$1") if $str =~ s/(\s+)$//; |
91
|
0
|
|
|
|
|
0
|
while($str =~ s/^(.*\S)(\s*\n\s*)//) { |
92
|
0
|
|
|
|
|
0
|
my($item,$sep) = ($1,$2); |
93
|
0
|
|
|
|
|
0
|
push @tags, $this->_li($item); |
94
|
0
|
|
|
|
|
0
|
push @tags, $this->_text($sep); |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
0
|
push @tags, $this->_li($str); |
97
|
0
|
|
|
|
|
0
|
next; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
41
|
|
|
|
|
119
|
push @tags, $tag; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
41
|
|
|
|
|
165
|
return $this->SUPER::pushBody(@tags); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub bodyHTML($):method { |
108
|
8
|
|
|
8
|
1
|
15
|
my $this = shift; |
109
|
8
|
|
|
|
|
15
|
my $html = ''; |
110
|
8
|
|
|
|
|
24
|
foreach($this->body) { |
111
|
34
|
100
|
|
|
|
175
|
next unless UNIVERSAL::isa($_,'BBCode::Tag::LI'); |
112
|
16
|
|
|
|
|
51
|
$html .= $_->toHTML; |
113
|
|
|
|
|
|
|
# die qq(\n> $html[$#html]\nOMGWTFBBQ?) if $html[$#html] =~ m# #i; |
114
|
|
|
|
|
|
|
} |
115
|
8
|
|
|
|
|
29
|
return multilineText $html; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub ListDefault($):method { |
119
|
7
|
|
|
7
|
0
|
20
|
return qw(ul); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub toHTML($):method { |
123
|
8
|
|
|
8
|
1
|
20
|
my $this = shift; |
124
|
8
|
|
|
|
|
123
|
my @list = parseListType($this->param('TYPE')); |
125
|
8
|
50
|
|
|
|
47
|
@list = $this->ListDefault unless @list; |
126
|
|
|
|
|
|
|
|
127
|
8
|
|
|
|
|
13
|
my @css; |
128
|
8
|
50
|
|
|
|
22
|
if(@list > 1) { |
129
|
0
|
|
|
|
|
0
|
push @css, qq(list-style-type: $list[1]); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
8
|
|
|
|
|
27
|
my $start = $this->param('START'); |
133
|
8
|
50
|
66
|
|
|
37
|
if($list[0] eq 'ol' and defined $start) { |
134
|
0
|
|
|
|
|
0
|
$start = qq( start="$start"); |
135
|
|
|
|
|
|
|
} else { |
136
|
8
|
|
|
|
|
17
|
$start = ''; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
8
|
100
|
66
|
|
|
85
|
if($list[0] eq 'ul' and $this->parser->allow_image_bullets) { |
140
|
7
|
|
|
|
|
26
|
my $url = $this->param('BULLET'); |
141
|
7
|
50
|
|
|
|
26
|
if(defined $url) { |
142
|
0
|
|
|
|
|
0
|
push @css, sprintf "list-style-image: url('%s')", encodeHTML($url->as_string); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
8
|
|
|
|
|
27
|
my $outside = $this->param('OUTSIDE'); |
147
|
8
|
50
|
|
|
|
23
|
if(defined $outside) { |
148
|
0
|
0
|
|
|
|
0
|
push @css, "list-style-position: ".($outside ? "outside" : "inside"); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
8
|
50
|
|
|
|
26
|
my $css = @css ? qq( style=").join("; ", @css).qq(") : ""; |
152
|
8
|
|
|
|
|
33
|
my $body = $this->bodyHTML; |
153
|
8
|
|
|
|
|
32
|
$body =~ s#()(<[uo]l>)#$1\n$2#g; |
154
|
8
|
|
|
|
|
56
|
$body =~ s/^/\t/mg; |
155
|
8
|
|
|
|
|
53
|
$body =~ s#^\t(?!?li>)#\t\t#mg; |
156
|
8
|
|
|
|
|
43
|
return multilineText "<$list[0]$start$css>\n$body$list[0]>\n"; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub toText($):method { |
160
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
161
|
0
|
|
|
|
|
|
my @body = grep { $_->isa('BBCode::Tag::LI') } $this->body; |
|
0
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
my $seq = createListSequence($this->param('TYPE'), $this->param('START'), scalar(@body)); |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $text = ""; |
165
|
0
|
|
|
|
|
|
foreach(@body) { |
166
|
0
|
|
|
|
|
|
$text .= $seq->()." ".$_->toText."\n"; |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
|
return multilineText $text; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |