line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::AutoLink; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25552
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION $TextRe $TagRe $TagRe_ $UrlRe); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
104
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1238
|
use Template::Plugin::Filter; |
|
1
|
|
|
|
|
14126
|
|
|
1
|
|
|
|
|
41
|
|
8
|
1
|
|
|
1
|
|
14
|
use base qw( Template::Plugin::Filter ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
875
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$TextRe = q{[^<]*}; |
11
|
|
|
|
|
|
|
$TagRe_ = q{[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$(?!\n))}; #'}}}}; |
12
|
|
|
|
|
|
|
my $comment_tag_re = '-]*(?:-[^>-]+)*?)??)*(?:>|$(?!\n)|--.*$)'; |
13
|
|
|
|
|
|
|
$TagRe = qq{$comment_tag_re|<$TagRe_}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $http_url_re = |
16
|
|
|
|
|
|
|
q{\b(?:https?|shttp)://(?:(?:[-_.!~*'()a-zA-Z0-9;:&=+$,]|%[0-9A-Fa-f} . |
17
|
|
|
|
|
|
|
q{][0-9A-Fa-f])*@)?(?:(?:[a-zA-Z0-9](?:[-a-zA-Z0-9]*[a-zA-Z0-9])?\.)} . |
18
|
|
|
|
|
|
|
q{*[a-zA-Z](?:[-a-zA-Z0-9]*[a-zA-Z0-9])?\.?|[0-9]+\.[0-9]+\.[0-9]+\.} . |
19
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?:/(?} . |
33
|
|
|
|
|
|
|
q{:[-_.!~*'()a-zA-Z0-9:@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*)*(?:;type=[} . |
34
|
|
|
|
|
|
|
q{AIDaid])?)?(?:\?(?:[-_.!~*'()a-zA-Z0-9;/?:@&=+$,]|%[0-9A-Fa-f][0-9} . |
35
|
|
|
|
|
|
|
q{A-Fa-f])*)?(?:#(?:[-_.!~*'()a-zA-Z0-9;/?:@&=+$,]|%[0-9A-Fa-f][0-9A} . |
36
|
|
|
|
|
|
|
q{-Fa-f])*)?}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $mail_re = |
39
|
|
|
|
|
|
|
q{(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\} . |
40
|
|
|
|
|
|
|
q{\[\]\000-\037\x80-\xff])|"[^\\\\\x80-\xff\n\015"]*(?:\\\\[^\x80-\xff][} . |
41
|
|
|
|
|
|
|
q{^\\\\\x80-\xff\n\015"]*)*")(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x} . |
42
|
|
|
|
|
|
|
q{80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff])|"[^\\\\\x80-} . |
43
|
|
|
|
|
|
|
q{\xff\n\015"]*(?:\\\\[^\x80-\xff][^\\\\\x80-\xff\n\015"]*)*"))*@(?:[^(} . |
44
|
|
|
|
|
|
|
q{\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\\\[\]\0} . |
45
|
|
|
|
|
|
|
q{00-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[^\x80-\xff])*} . |
46
|
|
|
|
|
|
|
q{\])(?:\.(?:[^(\040)<>@,;:".\\\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,} . |
47
|
|
|
|
|
|
|
q{;:".\\\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\\\x80-\xff\n\015\[\]]|\\\\[} . |
48
|
|
|
|
|
|
|
q{^\x80-\xff])*\]))*}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$UrlRe = "($http_url_re|$ftp_url_re|($mail_re))"; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub init { |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
0
|
|
|
|
|
|
$self->{_DYNAMIC} = 1; |
55
|
0
|
|
|
|
|
|
$self->install_filter('auto_link'); |
56
|
0
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub filter { |
60
|
0
|
|
|
0
|
0
|
|
my ($self, $str, $args, $config) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$config = $self->merge_config($config); |
63
|
0
|
|
|
|
|
|
my $anchor = sprintf '
64
|
0
|
|
|
|
|
|
join ' ', map {qq|$_="$config->{$_}"|} keys %{$config}; |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $result = ''; |
67
|
0
|
|
|
|
|
|
my $skip = 0; |
68
|
0
|
|
|
|
|
|
while ($str =~ /($TextRe)($TagRe)?/gso) { |
69
|
0
|
0
|
0
|
|
|
|
last if $1 eq '' and $2 eq ''; |
70
|
0
|
|
|
|
|
|
my $text_tmp = $1; |
71
|
0
|
|
|
|
|
|
my $tag_tmp = $2; |
72
|
0
|
0
|
|
|
|
|
if ($skip) { |
73
|
0
|
|
|
|
|
|
$result .= $text_tmp . $tag_tmp; |
74
|
0
|
0
|
|
|
|
|
$skip = 0 if $tag_tmp =~ /^<\/[aA](?![0-9A-Za-z])/; |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
|
$text_tmp =~ s{$UrlRe} |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
{my($org, $mail) = ($1, $2); |
78
|
0
|
|
|
|
|
|
(my $tmp = $org) =~ s/"/"/g; |
79
|
0
|
0
|
|
|
|
|
$anchor . ($mail ne '' ? 'mailto:' : '') . "$tmp\">$org"}ego; |
80
|
0
|
|
|
|
|
|
$result .= $text_tmp . $tag_tmp; |
81
|
0
|
0
|
|
|
|
|
$skip = 1 if $tag_tmp =~ /^<[aA](?![0-9A-Za-z])/; |
82
|
0
|
0
|
|
|
|
|
if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) { |
83
|
0
|
|
|
|
|
|
$str =~ /(.*?(?:<\/$1(?![0-9A-Za-z])$TagRe_|$))/gsi; |
84
|
0
|
|
|
|
|
|
$result .= $1; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
return $result; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |