Text::Context(3pm)

Text::Context3pm

Handle highlighting search result context snippets

Usage

  use Text::Context;
  my $snippet = Text::Context->new($text, @keywords);
  $snippet->keywords("foo", "bar"); # In case you change your mind
  print $snippet->as_html;
  print $snippet->as_text;

Overview

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.

paras

    @paras = $self->paras($maxlen)

Return shortened paragraphs to fit together into a snippet of at most $maxlen characters.

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.

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">").

BUGS and QUERIES

Please direct all correspondence regarding this module to:
[email protected]

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 3 times.

  1. 6.0–9
  2. 10
  3. 11
  4. 12–13

Author

Original author: Simon Cozens

Current maintainer: Tony Bowden

From libtext-context-perl 3.7-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.