1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::Linkify;
9 my $l = PublicInbox::Linkify->new;
10 my $u = 'http://example.com/url-with-trailing-period';
12 $s = $l->linkify_1($s);
13 $s = $l->linkify_2($s);
14 is($s, qq(<a\nhref="$u">$u</a>.), 'trailing period not in URL');
17 # handle URLs in parenthesized statements
19 my $l = PublicInbox::Linkify->new;
20 my $u = 'http://example.com/';
22 $s = $l->linkify_1($s);
23 $s = $l->linkify_2($s);
24 is($s, qq{(see: <a\nhref="$u">$u</a>)}, 'trailing ) not in URL');
28 my $l = PublicInbox::Linkify->new;
29 my $u = 'http://example.com/url-with-trailing-semicolon';
31 $s = $l->linkify_1($s);
32 $s = $l->linkify_2($s);
33 is($s, qq(<a\nhref="$u">$u</a>;), 'trailing semicolon not in URL');
37 my $l = PublicInbox::Linkify->new;
38 my $u = 'http://example.com/url-with-(parens)';
39 my $s = "hello $u world";
40 $s = $l->linkify_1($s);
41 $s = $l->linkify_2($s);
42 is($s, qq(hello <a\nhref="$u">$u</a> world), 'URL preserved');
45 $s = "hello $u world";
46 $s = $l->linkify_1($s);
47 $s = $l->linkify_2($s);
48 is($s, qq(hello <a\nhref="$u">$u</a> world), 'query preserved');
51 $s = "hello $u world";
52 $s = $l->linkify_1($s);
53 $s = $l->linkify_2($s);
54 is($s, qq(hello <a\nhref="$u">$u</a> world),
55 'query + fragment preserved');
57 $u = "http://example.com/";
58 $s = "hello $u world";
59 $s = $l->linkify_1($s);
60 $s = $l->linkify_2($s);
61 is($s, qq(hello <a\nhref="$u">$u</a> world), "root URL preserved");
63 $u = "http://example.com/#fragment";
64 $s = "hello $u world";
65 $s = $l->linkify_1($s);
66 $s = $l->linkify_2($s);
67 is($s, qq(hello <a\nhref="$u">$u</a> world), "root + fragment");
70 # Markdown compatibility
72 my $l = PublicInbox::Linkify->new;
73 my $u = 'http://example.com/';
74 my $s = "[markdown]($u)";
75 $s = $l->linkify_1($s);
76 $s = $l->linkify_2($s);
77 is($s, qq![markdown](<a\nhref="$u">$u</a>)!, 'Markdown-compatible');
79 $s = qq![markdown]($u "title")!;
80 $s = $l->linkify_1($s);
81 $s = $l->linkify_2($s);
82 is($s, qq![markdown](<a\nhref="$u">$u</a> "title")!,
83 'Markdown title compatible');
85 $s = qq![markdown]($u).!;
86 $s = $l->linkify_1($s);
87 $s = $l->linkify_2($s);
88 is($s, qq![markdown](<a\nhref="$u">$u</a>).!,
89 'Markdown-compatible end of sentence');