NAME
Search::Tools::HiLiter - extract and highlight search results in original text
SYNOPSIS
use Search::Tools::HiLiter;
my $re = Search::Tools::RegExp->new;
my $kw = $re->build('the quick brown fox');
my $hiliter = Search::Tools::HiLiter->new( kw => $kw );
for my $text (@texts)
{
print $hiliter->light( $text );
}
DESCRIPTION
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.
METHODS
new( query => query )
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:
- class
- tag
- colors
- tty
- ttycolors
- no_html
open_tag( keyword )
close_tag( keyword )
light( text )
plain( text )
html( text )
class
The name of the class attribute to be used on the tag().
tag
The name of the highlighting tag. Default is span
.
tty
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.
ttycolors
Set the colors used if tty() is true. See the Term::ANSIColor documentation for options.
debug
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.
no_html
Set to a true value (1) to avoid HTML highlighting tags regardless of test for whether text is HTML.
keywords
Returns the keywords derived from query.
AUTHOR
Peter Karman 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.
COPYRIGHT
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.
SEE ALSO
HTML::HiLiter, Search::Tools::RegExp::Keywords