Created
July 16, 2009 16:32
-
-
Save gardejo/148523 to your computer and use it in GitHub Desktop.
HTML::Shakan::Renderer::HTML::SelectivelyEncodable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package HTML::Shakan::Renderer::HTML::SelectivelyEncodable; | |
use HTML::Shakan::Utils; | |
use Any::Moose '::Role'; | |
sub selectively_encode { | |
my ($self, $label) = @_; | |
my $label_for_render = $label; | |
my $prefix = q{}; | |
my $suffix = q{}; | |
if ( | |
$label_for_render =~ s{ | |
\A | |
( | |
< | |
[^>]+ | |
> | |
)? | |
( | |
.+? | |
) | |
( | |
< | |
[^>]+ | |
> | |
)? | |
\z | |
}{$2}xms | |
) { | |
$prefix = defined $1 ? $1 : q{}; | |
$suffix = defined $3 ? $3 : q{}; | |
} | |
return $prefix . encode_entities($label_for_render) . $suffix; | |
} | |
no Any::Moose '::Role'; | |
1; | |
__END__ | |
=head1 DESCRIPTION | |
labelに項目ガイドへのリンクを仕込んでも、しっかりエスケープされるので、 | |
<label for="foo"><a href="http://sample.example/help/foo/">foo</a></label> | |
エスケープされる範囲を限定してしまう。 | |
<label for="foo"><a href="http://sample.example/help/foo/">foo</a></label> | |
=head1 SEE ALSO | |
=over 4 | |
=item HTML::Shakan::Renderer::HTML::DefinitionList | |
http://gist.github.com/148522 | |
=item HTML::Shakan::Renderer::HTML::SelectivelyEncodable | |
http://gist.github.com/148523 | |
=item HTML::Shakan::Renderer::HTML::DateTimeSeparatable | |
http://gist.github.com/148524 | |
=back |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment