SearchHighlight
<< Reduce Band Width | Cookbook-V1 | Tell A Friend >>
Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.
Goal
Highlight keywords when coming from a search page, pmwiki,google,etc
Solution
Development/ResearchWordHighlighted depicts how to use a bit of javascript to highlight keywords. For some reason it gave an error on my pages. So I created a pmwiki module
Discussion
The basic principle is simple, find and replace. A catch is that we don't want to replace anything in html tags (< >).
For pmwiki with the template system (0.6.1+)
Download and save Attach:searchhighlight_1.13.txt as searchhighlight.php add to your local/config.php:
- include_once("local/searchhighlight.php");
Update your tmpl file (PmWiki.LayoutBasics):
- <!--function:highlight_capture_start-->
- <!--PageText-->
- <!--function:highlight_capture_stop-->
Add a style to your stylesheet:
- .highlight {background:yellow}
additional commentThis scripts only works unaltered on PHP4 >= 4.3.0 | |||
if (!function_exists("ob_get_clean")) {
} | |||
|
For pmwiki 0.5
Download and save Attach:searchhighlight_1.7.php
Add the code below to the very end of your local.php (just above the ?>)
- if ( ! $action || ($action=='browse' ) ) {
- include_once("local/searchhighlight.php");
- array_push ($PageHeaderFmt, "function:highlight_capture_start");
- array_unshift($PageFooterFmt, "function:highlight_capture_stop");
- }
Add a style to the used stylesheet:
- .highlight {background:yellow;}
Or edit the script and add some bgcolor to the font (near the end).
See Also
Development/ResearchWordHighlighted
History
16-01-2004 | 1.2 | Initial version |
16-01-2004 | 1.5 | case insensitve wasn't that easy;sorry. |
21-01-2004 | 1.6 | Corrected the highlight of partial matches |
Figured out how to use lookforward | ||
Script requires a style hightlight in a css. | ||
02-04-2004 | 1.11 | Pmwiki 0.6 rework |
02-26-2004 | Update for the templates (0.6.1+) |
Comments & Bugs
- Using a wrapper around PrintText would be nicer I think
- The highlight function should work for any chunk of text.
The highlight function should work for any chunk of text.
Since SearchWiki finds any chunk of text, they should be highlighted. To get that result, just change the function highlight(..) in the searchhighlight.php to be found above:
function highlight(&$text,$word) {
} | |
function highlight(&$text,$word) {
} |
Now everything gets highlighted. J.P.Jarolim
Contributors
- bram
- J.P.Jarolim (Minor additions)
pmwiki-2.3.38 -- Last modified by {{BrBrBr}}