Badger
view release on metacpan or search on metacpan
lib/Badger/Codec/HTML.pm view on Meta::CPAN
use Badger::Class
version => 0.01,
base => 'Badger::Codec';
our $CHARSET = {
'ISO-8859-1' => \&fix_windows,
'WINDOWS-1252' => \&fix_windows,
};
sub encode {
my ($class, $html, $charset) = @_;
my $filter;
return undef unless defined($html);
for ($html) {
s/&/&/g;
s/\"/"/g;
s/>/>/g;
s/</</g;
}
# pass resulting HTML through any corresponding filter for the
# character set (if specified)
if ($charset && ($filter = $CHARSET->{ $charset })) {
$html = &$filter($html);
}
return $html;
}
sub decode {
my ($class, $html) = @_;
return undef unless defined($html);
lib/Badger/Codec/HTML.pm view on Meta::CPAN
decoding HTML. It is based on code extracted from Lincoln Stein's
CGI.pm module.
The L<encode()> method encodes HTML by converting any reserved characters
to the correct HTML entities.
The L<decode()> method reverses this process.
=head1 METHODS
=head2 encode($html, $charset)
Encodes the HTML text passed as the first argument.
$encoded = Badger::Codec::HTML->encode($html);
The optional second argument can be used to indicate the character set
in use. If this is set to C<ISO-8859-1> C<WINDOWS-1252> then the
encoded data will undergo some additional processing in order to work
around some known bugs in Microsoft's web browsers. See L<fix_windows()>.
t/filesystem/testfiles/visitor/tmp/goodbye.html.old view on Meta::CPAN
<html>
<head>
<title>Just Listen to the Sustain</title>
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="/css/swear_loudly_for_the_next_three_hours.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/css/bang_your_head_against_brick_wall.css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/css/print.css" media="print">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="author" content="Andy Wardley">
</head>
<body>
<pre>
Nigel: Just listen for a minute...
Marty: I'm not...
Nigel: The sustain... listen to it...
Marty: I'm not hearing anything.
Nigel: You would, though, if it were playing, because it really... it's
famous for its sustain... I mean, you could, just hold it...
t/filesystem/testfiles/visitor/two/goodbye.html view on Meta::CPAN
<html>
<head>
<title>Just Listen to the Sustain</title>
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="/css/swear_loudly_for_the_next_three_hours.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/css/bang_your_head_against_brick_wall.css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/css/print.css" media="print">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="author" content="Andy Wardley">
</head>
<body>
<pre>
Nigel: Just listen for a minute...
Marty: I'm not...
Nigel: The sustain... listen to it...
Marty: I'm not hearing anything.
Nigel: You would, though, if it were playing, because it really... it's
famous for its sustain... I mean, you could, just hold it...
t/filesystem/testfiles/visitor/two/hello.html view on Meta::CPAN
<html>
<head>
<title>A Random HTML Page</title>
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="/css/swear_loudly_for_the_next_three_hours.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/css/bang_your_head_against_brick_wall.css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/css/print.css" media="print">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="author" content="Andy Wardley">
</head>
<body>
<h1>The Badger Says...</h1>
<blockquote>
Hello World!
</blockquote>
</body>
</html>
( run in 0.378 second using v1.01-cache-2.11-cpan-4d50c553e7e )