Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-05-22 05:51:15

Etz Haim
Archived Plugin Author
From: Karlstad, Sweden
Registered: 2005-01-24
Posts: 262
Website

[plugin] [ORPHAN] etz_hilite

Highlights search terms inside your pages.

Usage:

  1. Wrap the part of the page you want to highlight between <txp:etz_hilite> and </txp:etz_hilite>.
  2. Put span.etz_hilite {color: yellow;} or whatever in your CSS.

Additional options:

  • class defaults to “etz_hilite”

Known bugs/limitations:

  • Does not support multibyte encodings (including Unicode) yet.
  • Ignores quotes in search terms.
  • Only supports Google and Textpattern’s own search for the moment.

Notes:

Currently it’s of little use to me because it doesn’t support UTF-8, but it should be usefult to you that use 100% Latin scripts. I plan to extend its functionality in the future. Feedback is most appreciated.

Download version 0.1a now!

Last edited by Etz Haim (2005-07-30 18:00:47)

Offline

#2 2005-05-22 11:28:52

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: [plugin] [ORPHAN] etz_hilite

This sounds really cool. Will this work in an artilce form?

Offline

#3 2005-05-22 12:01:54

Etz Haim
Archived Plugin Author
From: Karlstad, Sweden
Registered: 2005-01-24
Posts: 262
Website

Re: [plugin] [ORPHAN] etz_hilite

> soulship wrote:

> This sounds really cool. Will this work in an artilce form?

Sure, it will work anywhere you put it. I actually use mine inside an article form.

Offline

#4 2005-07-10 09:25:30

ubernostrum
Member
From: Lawrence, KS
Registered: 2004-05-05
Posts: 238
Website

Re: [plugin] [ORPHAN] etz_hilite

Etz,

A while back I wrote an extensible search-highlighting script (had it supporting twenty or so different search engines last I checked) that I’ve been meaning to turn into a TXP plugin; would you have any objection to my using your plugin as a basis for that? You would, of course, be credited.


You cooin’ with my bird?

Offline

#5 2005-07-10 10:00:49

Etz Haim
Archived Plugin Author
From: Karlstad, Sweden
Registered: 2005-01-24
Posts: 262
Website

Re: [plugin] [ORPHAN] etz_hilite

Sure you can, I’d love that.

Offline

#6 2005-07-10 14:26:27

paularms
Member
From: University of Minnesota
Registered: 2004-10-21
Posts: 155
Website

Re: [plugin] [ORPHAN] etz_hilite

Currently it’s of little use to me because it doesn’t support UTF-8

That makes me sad. I wish UTF-8 were supported.

Offline

#7 2005-07-10 21:04:24

ubernostrum
Member
From: Lawrence, KS
Registered: 2004-05-05
Posts: 238
Website

Re: [plugin] [ORPHAN] etz_hilite

Etz: cool. I’ll try to have a first draft in about a week.


You cooin’ with my bird?

Offline

#8 2010-12-08 16:27:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,729
Website

Re: [plugin] [ORPHAN] etz_hilite

With the following changes to the final function in the code, etz_hilite will use the new HTML5 mark tag as standard, e.g. to have your search term highlighted as <mark>term</mark>, use:

<txp:etz_hilite><txp:body /></txp:etz_hilite>

If you still want your terms wrapped in <span class="hilite">term</span>, then use:

<txp:etz_hilite wraptag="span" class="hilite"><txp:body /></txp:etz_hilite>

This is the changed final function of the plugin:

function etz_hilite ($atts, $thing) {
	if (is_array($atts)) extract($atts);
	if (!(isset($wraptag))) $wraptag = "mark";
	if (!(isset($class))) {$class = "";} else {$class=' class="'.$class.'"'; }
	if (!(isset($keywords))) $keywords = etz_getkeywords();
	$output = parse($thing);

	if ($keywords != NULL) {
		$keywords_split = explode(' ', $keywords);
		foreach ($keywords_split as $etz_keyword) {
			$h = new Highlight ($etz_keyword,'<'.$wraptag.$class.'>{keyword}</'.$wraptag.'>');
			$output = $h->process($output);
		}
	}
	return $output;
}

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB