Wiki source for AcronymFormatter

Show raw source

===== Acronym (or Abbreviation) Formatter =====

>>==See also:==
>>This is the development page for the Acronym (or Abbreviation) Formatter.::c::
This modification allows Wikka to automatically parse known acronyms and render them as ##<acronym>## elements with titles, for example:

~""<acronym style=" border-bottom: 1px dotted #333;cursor: help" title="Cascading Style Sheets">CSS</acronym> - <acronym style=" border-bottom: 1px dotted #333;cursor: help" title="Frequently Asked Questions">FAQ</acronym> - <acronym style=" border-bottom: 1px dotted #333;cursor: help" title="HyperText Markup Language">HTML</acronym>""

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.

Current version: **0.3** ''(improved regex pattern)''

~-customizable acronym definition file;
~-formatter can be disabled from config file;
~-configurable ""<acronym style=" border-bottom: 1px dotted #333;cursor: help" title="Regular Expressions">REGEX</acronym>"" pattern;
~-configurable output format (##abbrv## or ##acronym##);

==== To do ====

~- **important** fix conflicts with links, [[Docs:WikiName | WikiNames]] and other elements containing sequences of uppercase letters that should not be rendered as acronyms;
~- improve ""<acronym style=" border-bottom: 1px dotted #333;cursor: help" title="Regular Expressions">REGEX</acronym>"" pattern;
~- support ""<acronym style=" border-bottom: 1px dotted #333;cursor: help" title="Cascading Style Sheets">CSS</acronym>"" classes for different kinds of acronyms;

==== 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##==

// we're cutting the last <br />
$text = preg_replace("/<br \/>$/","", $text);

echo ($text);

// we're cutting the last <br />
$text = preg_replace("/<br \/>$/","", $text);

//render acronyms
$text = $this->RenderAcronyms($text);

echo ($text);

== 2. Modify ##wikka.php##==

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


* Look up and return acronym definition from a configuration file.
* @author {@link DarioTaraborelli}
* @version 0.3
* @access public
* @uses GetConfigValue()
* @param string $text source sent from the formatter
* @return string $text source with known acronyms formatted as HTML elements

function RenderAcronyms($text){
if (($this->GetConfigValue('enable_acronyms') == 1) && file_exists($this->GetConfigValue('acronym_table'))) {
// define constants
define('ACRONYM_PATTERN', '/\b([A-Z]{2,})\b/'); #matches sequences of 2 or more capital letters within word boundaries
define('FORMATTED_ACRONYM','<acronym title="%s">%s</acronym>'); # acronym can be replaced by abbrv
// get acronym definitions
global $wikka_acronyms;
// replace known acronyms with HTML elements
$text = preg_replace_callback(
'global $wikka_acronyms; return (is_array($wikka_acronyms) && array_key_exists($matches[0], $wikka_acronyms))? sprintf(FORMATTED_ACRONYM, $wikka_acronyms[$matches[0]], $matches[0]) : $matches[0];'
return $text;


== 3. Modify ##wikka.config.php##==

Add the following values to the [[Docs:ConfigurationOptions | configuration file]]:

"enable_acronyms" => "1",
"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:


$wikka_acronyms = array(
"ACL" => "Access Control List",
"API" => "Application Program(ming) Interface",
"CSS" => "Cascading Style Sheets",
"CVS" => "Concurrent Version System",
"DHTML" => "Dynamic HyperText Markup Language",
"DOM" => "Document Object Model",
"DTD" => "Document Type Definition",
"FAQ" => "Frequently Asked Questions",
"FF" => "Firefox",
"GIF" => "Graphics Interchange Format",
"GPL" => "GNU General Public License",
"GUI" => "Graphical User Interface",
"HTML" => "HyperText Markup Language",
"HTTP" => "HyperText Transfer Protocol",
"IE" => "Internet Explorer",
"PHP" => "PHP hypertext processor",
"RSS" => "Rich Site Summary", # or Really Simple Syndication or RDF Site Summary...
"SQL" => "Structured Query Language",
"TOC" => "Table of Contents",


== 5. Add some style ==

Some browsers (Mozilla/""<acronym style=" border-bottom: 1px dotted #333;cursor: help" title="Firefox">FF</acronym>"") 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*/

CategoryDevelopmentFormatters, CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki