1 # Copyright (C) 2016 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');
18 my $l = PublicInbox::Linkify->new;
19 my $u = 'http://example.com/url-with-trailing-semicolon';
21 $s = $l->linkify_1($s);
22 $s = $l->linkify_2($s);
23 is($s, qq(<a\nhref="$u">$u</a>;), 'trailing semicolon not in URL');
27 my $l = PublicInbox::Linkify->new;
28 my $u = 'http://example.com/url-with-(parens)';
29 my $s = "hello $u world";
30 $s = $l->linkify_1($s);
31 $s = $l->linkify_2($s);
32 is($s, qq(hello <a\nhref="$u">$u</a> world), 'URL preserved');
35 $s = "hello $u world";
36 $s = $l->linkify_1($s);
37 $s = $l->linkify_2($s);
38 is($s, qq(hello <a\nhref="$u">$u</a> world), 'query preserved');
41 $s = "hello $u world";
42 $s = $l->linkify_1($s);
43 $s = $l->linkify_2($s);
44 is($s, qq(hello <a\nhref="$u">$u</a> world),
45 'query + fragment preserved');
47 $u = "http://example.com/";
48 $s = "hello $u world";
49 $s = $l->linkify_1($s);
50 $s = $l->linkify_2($s);
51 is($s, qq(hello <a\nhref="$u">$u</a> world), "root URL preserved");
53 $u = "http://example.com/#fragment";
54 $s = "hello $u world";
55 $s = $l->linkify_1($s);
56 $s = $l->linkify_2($s);
57 is($s, qq(hello <a\nhref="$u">$u</a> world), "root + fragment");
60 # Markdown compatibility
62 my $l = PublicInbox::Linkify->new;
63 my $u = 'http://example.com/';
64 my $s = "[markdown]($u)";
65 $s = $l->linkify_1($s);
66 $s = $l->linkify_2($s);
67 is($s, qq![markdown](<a\nhref="$u">$u</a>)!, 'Markdown-compatible');
69 $s = qq![markdown]($u "title")!;
70 $s = $l->linkify_1($s);
71 $s = $l->linkify_2($s);
72 is($s, qq![markdown](<a\nhref="$u">$u</a> "title")!,
73 'Markdown title compatible');
75 $s = qq![markdown]($u).!;
76 $s = $l->linkify_1($s);
77 $s = $l->linkify_2($s);
78 is($s, qq![markdown](<a\nhref="$u">$u</a>).!,
79 'Markdown-compatible end of sentence');