1<?php
2/**
3 * Prevent dokuwiki from escaping HTML entities (e.g., '&gt;') so you can use them
4 * inline.  Doesn't work with non-HTML renderers!
5 *
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     Tyler Bletsch (tkbletsc@ncsu.edu)
9 */
10
11if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(DOKU_PLUGIN.'syntax.php');
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class syntax_plugin_literal_entities extends DokuWiki_Syntax_Plugin {
20
21   /**
22    * Get an associative array with plugin info.
23    *
24    * <p>
25    * The returned array holds the following fields:
26    * <dl>
27    * <dt>author</dt><dd>Author of the plugin</dd>
28    * <dt>email</dt><dd>Email address to contact the author</dd>
29    * <dt>date</dt><dd>Last modified date of the plugin in
30    * <tt>YYYY-MM-DD</tt> format</dd>
31    * <dt>name</dt><dd>Name of the plugin</dd>
32    * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd>
33    * <dt>url</dt><dd>Website with more information on the plugin
34    * (eg. syntax description)</dd>
35    * </dl>
36    * @param none
37    * @return Array Information about this plugin class.
38    * @public
39    * @static
40    */
41    function getInfo(){
42        return array(
43            'author' => 'Tyler Bletsch',
44            'email'  => 'tkbletsc@ncsu.edu',
45            'date'   => '2010-12-02',
46            'name'   => 'Literal Entities',
47            'desc'   => "Prevent dokuwiki from escaping HTML entities (e.g., '&gt;') so you can use them inline. Doesn't work with non-HTML renderers!",
48            'url'    => 'http://www.dokuwiki.org/plugin:literal_entities',
49        );
50    }
51
52   /**
53    * Get the type of syntax this plugin defines.
54    *
55    * @param none
56    * @return String <tt>'substition'</tt> (i.e. 'substitution').
57    * @public
58    * @static
59    */
60    function getType(){
61        return 'substition';
62    }
63
64   /**
65    * Where to sort in?
66    *
67    * @param none
68    * @return Integer <tt>6</tt>.
69    * @public
70    * @static
71    */
72    function getSort(){
73        return 999;
74    }
75
76
77   /**
78    * Connect lookup pattern to lexer.
79    *
80    * @param $aMode String The desired rendermode.
81    * @return none
82    * @public
83    * @see render()
84    */
85    function connectTo($mode) {
86      $this->Lexer->addSpecialPattern('&[#\w]\w*;',$mode,'plugin_literal_entities');
87    }
88
89   /**
90    * Handler to prepare matched data for the rendering process.
91    *
92    * <p>
93    * The <tt>$aState</tt> parameter gives the type of pattern
94    * which triggered the call to this method:
95    * </p>
96    * <dl>
97    * <dt>DOKU_LEXER_ENTER</dt>
98    * <dd>a pattern set by <tt>addEntryPattern()</tt></dd>
99    * <dt>DOKU_LEXER_MATCHED</dt>
100    * <dd>a pattern set by <tt>addPattern()</tt></dd>
101    * <dt>DOKU_LEXER_EXIT</dt>
102    * <dd> a pattern set by <tt>addExitPattern()</tt></dd>
103    * <dt>DOKU_LEXER_SPECIAL</dt>
104    * <dd>a pattern set by <tt>addSpecialPattern()</tt></dd>
105    * <dt>DOKU_LEXER_UNMATCHED</dt>
106    * <dd>ordinary text encountered within the plugin's syntax mode
107    * which doesn't match any pattern.</dd>
108    * </dl>
109    * @param $aMatch String The text matched by the patterns.
110    * @param $aState Integer The lexer state for the match.
111    * @param $aPos Integer The character position of the matched text.
112    * @param $aHandler Object Reference to the Doku_Handler object.
113    * @return Integer The current lexer state for the match.
114    * @public
115    * @see render()
116    * @static
117    */
118    function handle($match, $state, $pos, &$handler){
119		return $match;
120    }
121
122   /**
123    * Handle the actual output creation.
124    *
125    * <p>
126    * The method checks for the given <tt>$aFormat</tt> and returns
127    * <tt>FALSE</tt> when a format isn't supported. <tt>$aRenderer</tt>
128    * contains a reference to the renderer object which is currently
129    * handling the rendering. The contents of <tt>$aData</tt> is the
130    * return value of the <tt>handle()</tt> method.
131    * </p>
132    * @param $aFormat String The output format to generate.
133    * @param $aRenderer Object A reference to the renderer object.
134    * @param $aData Array The data created by the <tt>handle()</tt>
135    * method.
136    * @return Boolean <tt>TRUE</tt> if rendered successfully, or
137    * <tt>FALSE</tt> otherwise.
138    * @public
139    * @see handle()
140    */
141    function render($mode, &$renderer, $data) {
142		$renderer->doc .= $data;
143        return true;
144    }
145}
146
147?>
148