Revision [8127]
This is an old revision of AcronymFormatter made by DarTar on 2005-05-14 10:28:05.
Acronym (or Abbreviation) Formatter
This is the development page for the Acronym (or Abbreviation) Formatter.
This modification allows Wikka to automatically parse known acronyms and render them as <acronym> elements with titles, for example:
CSS - FAQ - HTML
The list of acronyms can be set by the WikiAdmin in a configuration file: each time an acronym is found in the page source matching one of the entries of this file, it is automatically rendered with the appropriate markup and expanded description.
Features
- customizable acronym definitions file
- formatter can be disabled from config file
To do
- fix eventual conflicts with WikiName WikiNames containing sequences of uppercase letters;
- improve REGEX;
- use abbrv or acronym ?
- support CSS classes for different kinds of acronyms;
- (optionally) move the preg_replace_callback section from the formatter to the AcronymTableLookup() function.
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:
- // we're cutting the last <br />
- echo ($text);
- wakka2callback('closetags');
modified:
- // we're cutting the last <br />
- //render acronyms
- if ($this->GetConfigValue('enable_acronyms') == 1) {
- $text = preg_replace_callback('/([A-Z]{2,})/', array(&$this,'AcronymTableLookup'), $text); # REGEX pattern matching sequences of 2 or more capital letters
- }
- echo ($text);
2. Modify wikka.php
Add the following function in the code, for instance immediately before the VARIABLES section:
original:
- // VARIABLES
modified:
- /**
- * Look up and return acronym definition from a configuration file.
- *
- * @author {@link http://wikka.jsnx.com/DarTar DarioTaraborelli}
- * @version 0.1
- *
- * @access public
- * @uses GetConfigValue()
- *
- * @param array $matches array of matching strings sent from the formatter
- * @return string $acronym acronym formatted as HTML element
- */
- function AcronymTableLookup($matches){
- global $wikka_acronyms;
- include($this->GetConfigValue('acronym_table'));
- $acronym = (is_array($wikka_acronyms) && array_key_exists($matches[0], $wikka_acronyms))? "<acronym title=\"".$wikka_acronyms[$matches[0]]."\">".$matches[0]."</acronym>" : $matches[0];
- return $acronym;
- }
- // VARIABLES
3. Modify wikka.config.php
Add the following values to the ConfigurationOptions configuration file:
"enable_acronyms" => "1",
"acronym_table" => "acronyms.php",
"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
$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"
);
?>
$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"
);
?>
5. Add some style
Some browsers (Mozilla/FF) automatically highlight acronym elements in the page. To make acronyms visible also in other browsers, paste the following in your stylesheet (default: ./css/wikka.css):
acronym {
border-bottom: 1px dotted #333;
cursor: help /*modifies the mouse pointer as a question mark*/
}
border-bottom: 1px dotted #333;
cursor: help /*modifies the mouse pointer as a question mark*/
}
CategoryDevelopment