NAME

Text::Context - Handle highlighting search result context snippets

SYNOPSIS

use Text::Context;

my $snippet = Text::Context->new($text, @keywords);

$snippet->keywords("foo", "bar"); # In case you change your mind

$snippet->offsets() # Array containing context string and offsets of terms

print $snippet->as_html;

DESCRIPTION

Given a piece of text and some search terms, produces an object which locates the search terms in the message, extracts a reasonable-length string containing all the search terms, and optionally dumps the string out as HTML text with the search terms highlighted in bold.

new

Creates a new snippet object for holding and formatting context for search terms.

keywords

Accessor method to get/set keywords. As the context search is done case-insensitively, the keywords will be lower-cased.

as_text

Calculates a "representative" string which contains the given search terms. If there's lots and lots of context between the terms, it's replaced with an ellipsis.

offsets

Calculate and return an array of the offsets to start and end highlighting of the string returned by as_text; the return value will be of the form:

[
    [ "foo", $foo_start, $foo_end ]
    [ "bar", $bar_start, $bar_end ]
] 

Note: Previous versions of Text::Context lumped as_text and offsets into one data structure. Hence, code which uses old versions will need to be updated.

as_html([ start => "<some tag>", end => "<some end tag>" ])

Markup the snippet as a HTML string using the specified delimiters or with a default set of delimiters (<span class="quoted">).

COPYRIGHT

Copyright (C) 2002 Kasei Limited

You may use and redistribute this module under the terms of the Artistic License.