Created
September 9, 2010 10:27
-
-
Save gfx/571696 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!perl -w | |
| use strict; | |
| use Text::Xslate qw(html_builder html_escape); | |
| use URI::Find; | |
| my $text = <<'EOT'; | |
| <http://example.com/?a=10&b=20> | |
| EOT | |
| my $finder = URI::Find->new(sub { | |
| my($obj_uri, $orig_uri) = @_; | |
| my $safe_uri = html_escape($orig_uri); | |
| return qq|<a href="$safe_uri">$safe_uri</a>|; | |
| }); | |
| my $tx = Text::Xslate->new( | |
| function => { | |
| autolink => html_builder { | |
| my($text) = @_; | |
| $finder->find(\$text, \&html_escape); | |
| return $text; | |
| }, | |
| }, | |
| ); | |
| print $tx->render_string(<<'T', { text => $text }); | |
| : $text | autolink | |
| T | |
| __END__ | |
| result: | |
| <<a href="http://example.com/?a=10&b=20">http://example.com/?a=10&b=20</a>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment