Revision [8101]

This is an old revision of AcronymFormatter made by DarTar on 2005-05-14 00:20:47.

 

Acronym Formatter


This modification allows Wikka to parse known acronyms and render them as <acronym> elements with titles, for example:

CSS

The list of acronyms can be set by the WikiAdmin in a configuration file: each time the formatter finds in the page source an acronym listed in this file, it automatically renders it with the appropriate markup and expanded description.

To do



The code

Here's the list of files that you will have to create or modify (backup the original files before making any modification)

1. Modify ./formatters/wakka.php

original:
  1. // we're cutting the last <br />
  2. $text = preg_replace("/<br \/>$/","", $text);
  3.  
  4. echo ($text);
  5. wakka2callback('closetags');


modified:
  1. // we're cutting the last <br />
  2. $text = preg_replace("/<br \/>$/","", $text);
  3.  
  4. //render acronyms
  5. $text = preg_replace_callback('/([A-Z]{2,})/', array(&$this,'AcronymTableLookup'), $text); # REGEX pattern matching sequences of 2 or more capital letters
  6. echo ($text);
  7. wakka2callback('closetags');


2. Modify wikka.php

Add the following function in the code, for instance immediately before the VARIABLES section:

original:
  1.     // VARIABLES


modified:
  1.     function AcronymTableLookup($matches){
  2.         global $wikka_acronyms;
  3.         include($this->GetConfigValue('acronym_table'));
  4.         return (is_array($wikka_acronyms) && array_key_exists($matches[0], $wikka_acronyms))? "<acronym title=\"".$wikka_acronyms[$matches[0]]."\">".$matches[0]."</acronym>" : "";
  5.     }
  6.     // VARIABLES


3. Modify wikka.config.php

Add the following value to the ConfigurationOptions configuration file:

    "acronym_table" => "acronyms.php",


4. Create the acronym configuration file (acronyms.php)

Save the following code as acronyms.php in the root folder of your Wikka installation. You can obviously add as many acronym definitions as you like:

%%(php)
<?php

$wikka_acronyms = array(
"CSS" => "Cascade Style Sheet",
"GIF" => "Graphics Interchange Format",
"GPL" => "GNU General Public License",
"HTML" => "Hyper Text Markup Language",
"HTTP" => "Hyper Text Transfer Protocol"
);

?>





CategoryDevelopment
There are 9 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki