Search::Tools::HiLiter - extract and highlight search results in original text
use Search::Tools::HiLiter; my $re = Search::Tools::RegExp->new; my $rekw = $re->build('the quick brown fox'); my $hiliter = Search::Tools::HiLiter->new( rekw => $rekw ); for my $text (@texts) { print $hiliter->light( $text ); }
Search::Tools::HiLiter uses HTML tags to highlight text just like a felt-tip HiLiter. S::T::H can handle both plain and marked up text (HTML and XML). Nested entities and tags within keywords are supported.
You create a HiLiter object with either a string, an array of strings, or a Search::Tools::RegExp::Keywords object, and then feed the HiLiter text to highlight. You can control the style and color of the highlight tags.
Some caveats if you are highlighting HTML or XML: Unlike its more powerful cousin HTML::HiLiter, S::T::H knows nothing about context. This can give unexpected results when your keywords appear in the HTML <head> or across block tag boundaries. Use HTML::HiLiter if you need a real HTML parser. It uses the same regular expressions as S::T::H but is designed for full HTML documents rather than smaller fragments.
<head
query must be either a scalar string, an array reference to a list of scalar strings, or a Search::Tools::RegExp::Keywords object. You might use the last if you are also using Search::Tools::Snipper, since you only need to compile your S::T::R::Keywords object once and then pass it to both new() instances.
The following params are also supported. Each is available as a method as well:
The name of the class attribute to be used on the tag().
The name of the highlighting tag. Default is span.
span
Pass a true value to use Term::ANSIColor highlighting. This is useful when using a terminal for debugging or for displaying results. Default is off.
Set the colors used if tty() is true. See the Term::ANSIColor documentation for options.
Set to a value >= 1 to get debugging output. If used in conjuction with tty(), both tty colors and HTML tags are used for highlighting.
Set to a true value (1) to avoid HTML highlighting tags regardless of test for whether text is HTML.
Returns the keywords derived from query.
Peter Karman perl@peknet.com
perl@peknet.com
Based on the HTML::HiLiter regular expression building code, originally by the same author, copyright 2004 by Cray Inc.
Thanks to Atomic Learning www.atomiclearning.com for sponsoring the development of this module.
www.atomiclearning.com
Copyright 2006 by Peter Karman. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HTML::HiLiter, Search::Tools::RegExp::Keywords
To install Search::Tools, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Search::Tools
CPAN shell
perl -MCPAN -e shell install Search::Tools
For more information on module installation, please visit the detailed CPAN module installation guide.