Text::Context(3pm)

๐Ÿ“ฆ
version 3.7 ยท 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

โœจ Text::Context โœจ

okay bestie, so this is a page from the User Contributed Perl Documentation section โ€” yes it's a 3pm manual, we're in module territory ๐Ÿ’… โ€” and it's literally all about highlighting search result context snippets. Let's get into it ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

Text::Context โ€” handle highlighting search result context snippets ๐Ÿ’–

Like, you give it a big ol' blob of text and some search terms, and it goes "say less" and pulls out the good part.


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

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;

not the # In case you change your mind comment ๐Ÿ˜ญ she's so real for that.


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So here's the vibe: given a piece of text and some search terms, this produces an object. That object:

  • 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 ๐Ÿ‘‘

periodt.

๐Ÿ’œ new

Creates a new snippet object for holding and formatting context for search terms. main character energy fr fr.

๐Ÿ’œ keywords

Accessor method to get/set keywords. And listen โ€” because the context search is done case-insensitively, the keywords will be lower-cased. no cap. that's just what happens.

๐Ÿ’œ paras

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

Return shortened paragraphs to fit together into a snippet of at most $maxlen characters. math is mathing, bestie ๐Ÿงฎโœจ

๐Ÿ’œ as_text

Calculates a "representative" string which contains the given search terms. And if there's lots and lots of context between the terms? it's replaced with an ellipsis. ... we love a dramatic pause ๐Ÿซถ

๐Ÿ’œ 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, which is "<span class="quoted">". cute! ๐ŸŽ€


๐ŸŒˆ AUTHOR ๐ŸŒˆ

  • Original author: Simon Cozens
  • Current maintainer: Tony Bowden

slay to both of them honestly ๐Ÿ‘‘


๐Ÿ’€ BUGS and QUERIES ๐Ÿ’€

Please direct all correspondence regarding this module to:

bug-Text-Context@rt.cpan.org
bestie if something's broken, email that address. don't just suffer in silence ๐Ÿ˜ญ

Copyright (C) 2002-2005 Kasei

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License; either version
2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

so basically: GPL, version 2 or later, redistribute and/or modify as you please ๐Ÿ’– โ€” but it comes with NO WARRANTY, like, none at all, not even the implied ones for merchantability or fitness for a particular purpose. it's giving "use at your own risk" and honestly? iconic.


and that's the whole page, bestie!! this one's a perl v5.36.0 situation, dated 2022-12-13 โ€” so when you cite it in your group chat, you know exactly what you're working with ๐Ÿ’…โœจ bye ily ๐Ÿซถ