xref: /plugin/nodetailsxhtml/syntax/acronym.php (revision b07cf47aad5ddb93ae029a56d6bc78fa317e8817)
1<?php
2/**
3 * iReflect Plugin
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     i-net software <tools@inetsoftware.de>
7 * @author     Gerry Weissbach <gweissbach@inetsoftware.de>
8 */
9
10if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14/**
15 * All DokuWiki plugins to extend the parser/rendering mechanism
16 * need to inherit from this class
17 */
18class syntax_plugin_nodetailsxhtml_acronym extends DokuWiki_Syntax_Plugin {
19
20	var $acronyms = array();
21	var $pattern = '';
22
23	function getInfo() {
24        if ( method_exists(parent, 'getInfo')) {
25            $info = parent::getInfo();
26        }
27	    return array_merge(is_array($info) ? $info : confToHash(dirname(__FILE__).'/../plugin.info.txt'), array(
28				'desc' => 'Acronym Extension to enable acronyms with whitespaces (represented as "_")',
29		));
30	}
31
32    function getType(){ return 'substition';}
33
34    function getSort(){ return 230; }
35
36    function syntax_plugin_nodetailsxhtml_acronym() {
37    	global $conf;
38
39    	if ( $conf['renderer_xhtml'] != 'nodetailsxhtml' ) { return; }
40    	$this->acronyms = getAcronyms();
41    }
42
43    function preConnect() {
44
45        $acronyms = array();
46        foreach( $this->acronyms as $key => $value ) {
47        		if ( !strstr($key, '_') ) { unset($this->acronyms[$key]); continue; }
48				$acronyms[] = str_replace('_', ' ', $key);
49        }
50
51        if(!count($acronyms)) return;
52
53        $bound = '[\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]';
54        $acronyms = array_map('Doku_Lexer_Escape',$acronyms);
55        $this->pattern = '(?<=^|'.$bound.')(?:'.join('|',$acronyms).')(?='.$bound.')';
56    }
57
58
59	function connectTo($mode){
60        if(!count($this->acronyms)) return;
61
62        if ( strlen($this->pattern) > 0 ) {
63			$this->Lexer->addSpecialPattern($this->pattern,$mode,'acronym');
64        }
65	}
66}
67
68//Setup VIM: ex: et ts=4 enc=utf-8 :