line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xatena::Node::Section; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
93
|
use strict; |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
605
|
|
4
|
17
|
|
|
17
|
|
92
|
use warnings; |
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
446
|
|
5
|
17
|
|
|
17
|
|
86
|
use base qw(Text::Xatena::Node); |
|
17
|
|
|
|
|
31
|
|
|
17
|
|
|
|
|
240
|
|
6
|
|
|
|
|
|
|
|
7
|
17
|
|
|
17
|
|
102
|
use Text::Xatena::Util; |
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
238
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use constant { |
10
|
17
|
|
|
|
|
7151
|
SECTION => qr/^(?: |
11
|
|
|
|
|
|
|
(\*\*\*?)([^\*].*) | # *** or ** |
12
|
|
|
|
|
|
|
(\*)((?!\*\*?[^\*]).*) # * |
13
|
|
|
|
|
|
|
)$/x, |
14
|
17
|
|
|
17
|
|
2096
|
}; |
|
17
|
|
|
|
|
38
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub parse { |
17
|
295
|
|
|
295
|
0
|
474
|
my ($class, $s, $parent, $stack) = @_; |
18
|
295
|
100
|
|
|
|
707
|
if ($s->scan(SECTION)) { |
19
|
43
|
|
66
|
|
|
132
|
my $level = length($s->matched->[1] || $s->matched->[3]); |
20
|
43
|
|
100
|
|
|
126
|
my $title = $s->matched->[2] || $s->matched->[4]; |
21
|
43
|
|
|
|
|
279
|
$title =~ s/^\s+|\s+$//g; |
22
|
|
|
|
|
|
|
|
23
|
43
|
|
|
|
|
200
|
my $node = $class->new; |
24
|
43
|
|
|
|
|
1359
|
$node->{level} = $level; |
25
|
43
|
|
|
|
|
107
|
$node->{title} = $title; |
26
|
|
|
|
|
|
|
|
27
|
43
|
|
100
|
|
|
391
|
pop @$stack while |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
28
|
|
|
|
|
|
|
((ref($stack->[-1]) eq $class) && ($stack->[-1]->level >= $level)) || |
29
|
|
|
|
|
|
|
($level == 1 && ref($stack->[-1]) eq 'Text::Xatena::Node::SeeMore' && !$stack->[-1]->{is_super}); |
30
|
|
|
|
|
|
|
|
31
|
43
|
|
|
|
|
75
|
$parent = $stack->[-1]; |
32
|
|
|
|
|
|
|
|
33
|
43
|
|
|
|
|
1046
|
push @$parent, $node; |
34
|
43
|
|
|
|
|
76
|
push @$stack, $node; |
35
|
43
|
|
|
|
|
311
|
return 1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
73
|
|
|
73
|
0
|
418
|
sub level { $_[0]->{level} } |
40
|
38
|
|
|
38
|
0
|
226
|
sub title { $_[0]->{title} } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
## NOT COMPATIBLE WITH Hatena Syntax |
43
|
|
|
|
|
|
|
sub as_html { |
44
|
38
|
|
|
38
|
0
|
77
|
my ($self, $context, %opts) = @_; |
45
|
38
|
|
|
|
|
100
|
my $level = $self->level; |
46
|
|
|
|
|
|
|
|
47
|
38
|
|
|
|
|
133
|
$context->_tmpl(__PACKAGE__, q[ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{{= $title }} |
50
|
|
|
|
|
|
|
{{= $content }} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
], { |
53
|
|
|
|
|
|
|
title => $context->inline->format($self->title), |
54
|
|
|
|
|
|
|
level => $level, |
55
|
|
|
|
|
|
|
content => $self->SUPER::as_html($context, %opts), |
56
|
|
|
|
|
|
|
}); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |