| 1 |
#!perl |
| 2 |
|
| 3 |
BEGIN { chdir 't' if -d 't' } |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
use Test::More tests => 8; |
| 9 |
use Test::NoWarnings; |
| 10 |
use Text::MediawikiFormat |
| 11 |
as => 'wf', |
| 12 |
implicit_links => 0, |
| 13 |
absolute_links => 0, |
| 14 |
process_html => 0; |
| 15 |
|
| 16 |
my $wikitext = <<'WIKI'; |
| 17 |
|
| 18 |
I download code from http://www.cpan.org/ or ftp://ftp.cpan.org/ and |
| 19 |
email mailto:[email protected] |
| 20 |
|
| 21 |
WIKI |
| 22 |
|
| 23 |
my $htmltext = wf( $wikitext, {}, { absolute_links => 1 } ); |
| 24 |
|
| 25 |
is $htmltext, |
| 26 |
qq{<p>I download code from <a href='http://www.cpan.org/'>} |
| 27 |
. qq{http://www.cpan.org/</a> } |
| 28 |
. qq{or <a href='ftp://ftp.cpan.org/'>ftp://ftp.cpan.org/</a> and\n} |
| 29 |
. q{email <a href='mailto:[email protected]'>} |
| 30 |
. q{mailto:[email protected]</a>} |
| 31 |
. qq{</p>\n}, |
| 32 |
'Picking up absolute links'; |
| 33 |
|
| 34 |
$htmltext = wf( $wikitext, {}, { absolute_links => 0 } ); |
| 35 |
is $htmltext, |
| 36 |
qq{<p>I download code from http://www.cpan.org/ or ftp://ftp.cpan.org/ } |
| 37 |
. qq{and\n} |
| 38 |
. q{email mailto:[email protected]} |
| 39 |
. qq{</p>\n}, |
| 40 |
q{Doesn't pick up links when absolute_links is off}; |
| 41 |
|
| 42 |
$wikitext = "this is a moose:notalink"; |
| 43 |
|
| 44 |
$htmltext = wf( $wikitext, {}, { absolute_links => 1 } ); |
| 45 |
is $htmltext, qq{<p>this is a moose:notalink</p>\n}, q{Doesn't pick up things that might look like links}; |
| 46 |
|
| 47 |
$htmltext = wf( $wikitext, { schemas => ['moose'] }, { absolute_links => 1 } ); |
| 48 |
is $htmltext, |
| 49 |
qq{<p>this is a <a href='moose:notalink'>moose:notalink</a></p>\n}, |
| 50 |
q{Schema tag allows specifying what is a link}; |
| 51 |
|
| 52 |
$wikitext = <<'WIKI'; |
| 53 |
|
| 54 |
http://www.cpan.org/. |
| 55 |
|
| 56 |
A link in angle brackets: <http://link.org>. |
| 57 |
WIKI |
| 58 |
|
| 59 |
$htmltext = wf( $wikitext, {}, { absolute_links => 1 } ); |
| 60 |
like $htmltext, qr{href='http://www.cpan.org/'>}, 'Links work at beginning of line and lose cruft'; |
| 61 |
like $htmltext, qr{org/</a>\.}, 'Cruft restored after link'; |
| 62 |
like $htmltext, qr{>http://link\.org</a>>\.}, 'Angle brackets around links are left alone'; |