HTML::Highlighter - PSGI middleware to highlight text in an HTML response
use Plack::Builder; use HTML::Highlighter; # highlight the "search" query param builder { enable "+HTML::Highlighter", param => "search"; ... $app; }; # or highlight the user stored in session builder { enable "+HTML::Highlighter", callback => sub { my $env = shift; $env->{'psgix.highlight'} = $env->{'psgix.session'}{user}; }; ... $app; };
The HTML::Highlighter module is a piece of PSGI middleware that will inspect an HTML response and highlight parts of the page based on a query parameter or other request data. This is very much like what Google does when you load a page from their cache. Any text that matches your original query is highlighted.
HTML::Highlighter
<span class="highlight">[matching text]</span>
If no param or callback are provided to HTML::Highlighter, it will look for commonly used search parameters (e.g. q, query, search, and highlight.)
This module also includes a javascript file called highlighter.js which gives you a class with methods to jump (scroll) through the highlights.
This option allows you to specify a query parameter to be used for the highlighting. For example, if you specify "search" as the param, each response will look for a query parameter called "search" will highlight that value in the response.
This option lets you specify a function that will be called on each request to generate the text used for highlighting. The function will be passed the $env hashref, and should set 'psgix.highlight' on it. This value will be used for the highlighting. This could be useful if you want to highlight a username that is stored in a session, or something similar.
Plack::Builder
HTML::Parser
Copyright (C) 2010 Lee Aylward <leedo at cpan.org>, all rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Lee Aylward, <leedo@cpan.org>
To install HTML::Highlighter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Highlighter
CPAN shell
perl -MCPAN -e shell install HTML::Highlighter
For more information on module installation, please visit the detailed CPAN module installation guide.