skx has asked for the wisdom of the Perl Monks concerning the following question:
I'm having a problem using the URI::Find module to process a mixture of plain text and HTML code.
The perldoc suggests using the following code:
use CGI qw(escapeHTML); $text = "<pre>\n" . escapeHTML($text) . "</pre>\n"; my $finder = URI::Find->new( sub { my($uri, $orig_uri) = @_; return qq|<a href="$uri">$orig_uri</ +a>|; }); $finder->find(\$text);
This works beautifully when I'm processing plain text input, however the callback doesn't have any context so it cannot avoid modifying the following badly:
<a href="http://foo.com/">foo</a>
This is transformed even though I don't need it to be.
Short of trying to heuristically detect whether I'm processing HTML or plain text is there another module I could use to insert hyperlinks around URIs which are not already linked ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using URI::Find with HTML
by merlyn (Sage) on Dec 06, 2005 at 15:12 UTC | |
by skx (Parson) on Dec 06, 2005 at 15:59 UTC |