Peter's Blog

Redefining the Impossible

Gregarius Highlighter


I couldn't resist, here is an incredibly complex Gregarius plugin to highlight certain keywords in an rss article. There's no user interface to specify keywords, you have to edit this file. Store this in your Gregarius plugins folder and enable it in the admin.

   1  
   2  <?php
   3  
   4  /// Name: Keyword Highlighter
   5  /// Author: Peter Wilkinson
   6  /// Description: Highlight certain words in feeds
   7  /// Version: 0.0
   8  function __HighlightStuff( $in)
   9  {
  10      $output = preg_replace('/\b(python|django)\b/i', '<span style="color:red;font-size: larger">\\1</span>', $in);
  11  
  12      return $output;
  13  }
  14  
  15  rss_set_hook('rss.plugins.import.description','__HighlightStuff');
  16  ?>

This will highlight the words 'python' and 'django'. More words can be added between the brackets, separated by | characters.


Filed under: gregarius

Peter Says:

over 3 years ago

This does break if the keywords are found in urls in anchor tags... needs some more regular expression study.

Peter

Marco Says:

over 3 years ago

Good work! Feel free to submit your plugin to the repository (plugins.gregarius.net) when you think the world is ready for it! :)

Peter Says:

over 3 years ago

Here is mk 2. It uses a lookbehind assertion in an attempt to see if the keyword is within an url, in which case it should not get tampered with.

   1  /// Name: Keyword Highlighter
   2  /// Author: Peter Wilkinson
   3  /// Description: Highlight certain words in feeds
   4  /// Version: 0.0
   5  function __HighlightStuff( $in)
   6  {
   7      $output = preg_replace('/(?<![/"\'?.-])\b(python|django)\b/i', '<span style="color:red;font-size: larger">\\1</span>', $in);
   8  
   9      return $output;
  10  }
  11  
  12  rss_set_hook('rss.plugins.import.description','__HighlightStuff');
  13  
  14  ?>

Peter

Peter Says:

over 3 years ago

I'll test it some more but I'm not sure whether the world would prefer it to have a user interface for defining the keywords.

Peter

Have Your Say

I welcome constructive comments or questions but I reserve the right to delete any comments that displease me.

Who are you?

(Optional) If you enter an email address here I might email you back. Your email address will not be sold to spammers or shown anywhere

What do you have to say?