line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Xatena::Inline; |
2
|
|
|
|
|
|
|
|
3
|
20
|
|
|
20
|
|
103
|
use strict; |
|
20
|
|
|
|
|
41
|
|
|
20
|
|
|
|
|
566
|
|
4
|
20
|
|
|
20
|
|
98
|
use warnings; |
|
20
|
|
|
|
|
43
|
|
|
20
|
|
|
|
|
579
|
|
5
|
20
|
|
|
20
|
|
8430
|
use Text::Xatena::Inline::Base -Base; |
|
20
|
|
|
|
|
50
|
|
|
20
|
|
|
|
|
171
|
|
6
|
20
|
|
|
20
|
|
16745
|
use URI::Escape; |
|
20
|
|
|
|
|
30468
|
|
|
20
|
|
|
|
|
1403
|
|
7
|
20
|
|
|
20
|
|
2811
|
use HTML::Entities; |
|
20
|
|
|
|
|
18243
|
|
|
20
|
|
|
|
|
23794
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub footnotes { |
10
|
1
|
|
|
1
|
0
|
3
|
my ($self) = @_; |
11
|
1
|
50
|
|
|
|
15
|
$self->{footnotes} || []; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
match qr{\[\]([\s\S]*?)\[\]}i => sub { |
15
|
|
|
|
|
|
|
my ($self, $unlink) = @_; |
16
|
|
|
|
|
|
|
$unlink; |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
match qr{(\(\(\(.*?\)\)\))}i => sub { |
20
|
|
|
|
|
|
|
my ($self, $unlink) = @_; |
21
|
|
|
|
|
|
|
$unlink; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
match qr{\)(\(\(.*?\)\))\(}i => sub { |
25
|
|
|
|
|
|
|
my ($self, $unlink) = @_; |
26
|
|
|
|
|
|
|
$unlink; |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
match qr{\(\((.+?)\)\)}i => sub { |
30
|
|
|
|
|
|
|
my ($self, $note) = @_; |
31
|
|
|
|
|
|
|
push @{ $self->{footnotes} ||= [] }, {}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $number = @{ $self->{footnotes} }; |
34
|
|
|
|
|
|
|
my $title = $note; |
35
|
|
|
|
|
|
|
$title =~ s/<[^>]+>//g; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $footnote = $self->{footnotes}->[-1]; |
38
|
|
|
|
|
|
|
$footnote->{number} = $number; |
39
|
|
|
|
|
|
|
$footnote->{note} = $note; |
40
|
|
|
|
|
|
|
$footnote->{title} = $title; |
41
|
|
|
|
|
|
|
return sprintf('*%d', |
42
|
|
|
|
|
|
|
$number, |
43
|
|
|
|
|
|
|
$title, |
44
|
|
|
|
|
|
|
$number |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
match qr{(]+>[\s\S]*?)}i => sub { |
49
|
|
|
|
|
|
|
my ($self, $anchor) = @_; |
50
|
|
|
|
|
|
|
$anchor; |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
match qr{} => sub { |
54
|
|
|
|
|
|
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
''; |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
match qr{(<[^>]+>)}i => sub { |
59
|
|
|
|
|
|
|
my ($self, $tag) = @_; |
60
|
|
|
|
|
|
|
$tag; |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
match qr<\[((?:https?|ftp)://[^\s:]+(?::\d+)?[^\s:]+)(:(?:title(?:=([^[]+))?|barcode))?\]>i => sub { |
64
|
|
|
|
|
|
|
my ($self, $uri, $opt, $title) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
if ($opt) { |
67
|
|
|
|
|
|
|
if ($opt =~ /^:barcode$/) { |
68
|
|
|
|
|
|
|
return sprintf('', |
69
|
|
|
|
|
|
|
uri_escape($uri), |
70
|
|
|
|
|
|
|
$uri, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
if ($opt =~ /^:title/) { |
74
|
|
|
|
|
|
|
if (!$title && $self->{aggressive}) { |
75
|
|
|
|
|
|
|
$title = $self->cache->get($uri); |
76
|
|
|
|
|
|
|
if (not defined $title) { |
77
|
|
|
|
|
|
|
eval { |
78
|
|
|
|
|
|
|
$title = $self->title_of($uri); |
79
|
|
|
|
|
|
|
$self->cache->set($uri, $title, "30 days"); |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
if ($@) { |
82
|
|
|
|
|
|
|
warn $@; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
return sprintf('%s', |
87
|
|
|
|
|
|
|
$uri, |
88
|
|
|
|
|
|
|
encode_entities(decode_entities($title || '')) |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
return sprintf('%s', |
93
|
|
|
|
|
|
|
$uri, |
94
|
|
|
|
|
|
|
$uri |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
match qr<\[?((?:https?|ftp):(?!([^\s<>\]]+?):(?:barcode|title))([^\s<>\]]+))\]?>i => sub { |
101
|
|
|
|
|
|
|
my ($self, $uri) = @_; |
102
|
|
|
|
|
|
|
sprintf('%s', |
103
|
|
|
|
|
|
|
$uri, |
104
|
|
|
|
|
|
|
$uri |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
match qr<\[?mailto:([^\s\@:?]+\@[^\s\@:?]+(\?[^\s]+)?)\]?>i => sub { |
109
|
|
|
|
|
|
|
my ($self, $uri) = @_; |
110
|
|
|
|
|
|
|
sprintf('%s', |
111
|
|
|
|
|
|
|
$uri, |
112
|
|
|
|
|
|
|
$uri |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
match qr<\[tex:([^\]]+)\]>i => sub { |
117
|
|
|
|
|
|
|
my ($self, $tex) = @_; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return sprintf('', |
120
|
|
|
|
|
|
|
uri_escape($tex), |
121
|
|
|
|
|
|
|
encode_entities($tex) |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
__END__ |