1<?php
2if (! class_exists('syntax_plugin_shy')) {
3	if (! defined('DOKU_PLUGIN')) {
4		if (! defined('DOKU_INC')) {
5			define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/');
6		} // if
7		define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
8	} // if
9	// Include parent class:
10	require_once(DOKU_PLUGIN . 'syntax.php');
11
12/**
13 * <tt>syntax_plugin_shy.php </tt>- A PHP4 class that implements
14 * a <tt>DokuWiki</tt> plugin for so-called 'soft hyphens'.
15 *
16 * <p>
17 * Usage:<br>
18 * <tt>\\-</tt><br>
19 * to insert a so-called "soft hyphen".
20 * </p><pre>
21 *	Copyright (C) 2007, 2010  M.Watermann, D-10247 Berlin, FRG
22 *			All rights reserved
23 *		EMail : &lt;support@mwat.de&gt;
24 * </pre>
25 * <div class="disclaimer">
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either
29 * <a href="http://www.gnu.org/licenses/gpl.html">version 3</a> of the
30 * License, or (at your option) any later version.<br>
31 * This software is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34 * See the GNU General Public License for more details.
35 * </div>
36 * @author <a href="mailto:support@mwat.de">Matthias Watermann</a>
37 * @version <tt>$Id: syntax_plugin_shy.php,v 1.4 2010/02/22 10:49:59 matthias Exp $</tt>
38 * @since created 05-Jan-2007
39 */
40class syntax_plugin_shy extends DokuWiki_Syntax_Plugin {
41
42	/**
43	 * @publicsection
44	 */
45	//@{
46
47	/**
48	 * Tell the parser whether the plugin accepts syntax mode
49	 * <tt>$aMode</tt> within its own markup.
50	 *
51	 * @param $aMode String The requested syntaxmode.
52	 * @return Boolean <tt>FALSE</tt> always.
53	 * @public
54	 * @see getAllowedTypes()
55	 */
56	function accepts($aMode) {
57		return FALSE;
58	} // accepts()
59
60	/**
61	 * Connect lookup pattern to lexer.
62	 *
63	 * @param $aMode String The desired rendermode.
64	 * @public
65	 * @see render()
66	 */
67	function connectTo($aMode) {
68		// Only match markup inside words:
69		$this->Lexer->addSpecialPattern('(?<![\x20-\x2F\x5C])\x5C\x2D',
70			$aMode, plugin_shy);
71	} // connectTo()
72
73	/**
74	 * Get an associative array with plugin info.
75	 *
76	 * <p>
77	 * The returned array holds the following fields:
78	 * <dl>
79	 * <dt>author</dt><dd>Author of the plugin</dd>
80	 * <dt>email</dt><dd>Email address to contact the author</dd>
81	 * <dt>date</dt><dd>Last modified date of the plugin in
82	 * <tt>YYYY-MM-DD</tt> format</dd>
83	 * <dt>name</dt><dd>Name of the plugin</dd>
84	 * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd>
85	 * <dt>url</dt><dd>Website with more information on the plugin
86	 * (eg. syntax description)</dd>
87	 * </dl>
88	 * @return Array Information about this plugin class.
89	 * @public
90	 * @static
91	 */
92	function getInfo() {
93		return array(
94			'author' =>	'Matthias Watermann',
95			'email' =>	'support@mwat.de',
96			'date' =>	'2010-02-22',
97			'name' =>	'Soft Hyphen Syntax Plugin',
98			'desc' =>	'Include soft hyphens in wiki pages.',
99			'url' =>	'http://www.dokuwiki.org/plugin:shy');
100	} // getInfo()
101
102	/**
103	 * Where to sort in?
104	 *
105	 * @return Integer <tt>176</tt>.
106	 * @public
107	 * @static
108	 */
109	function getSort() {
110		return 176;
111	} // getSort()
112
113	/**
114	 * Get the type of syntax this plugin defines.
115	 *
116	 * @return String <tt>'substition'</tt> (i.e. 'substitution').
117	 * @public
118	 * @static
119	 */
120	function getType() {
121		return 'substition';	// sic! should be __substitution__
122	} // getType()
123
124	/**
125	 * Handler to prepare matched data for the rendering process.
126	 *
127	 * <p>
128	 * The <tt>$aState</tt> parameter gives the type of pattern
129	 * which triggered the call to this method.
130	 * </p>
131	 * @param $aMatch String The text matched by the patterns.
132	 * @param $aState Integer The lexer state for the match.
133	 * @param $aPos Integer The character position of the matched text.
134	 * @param $aHandler Object Reference to the Doku_Handler object.
135	 * @return Integer The given <tt>$aState</tt> value.
136	 * @public
137	 * @see render()
138	 * @static
139	 */
140	function handle($aMatch, $aState, $aPos, &$aHandler) {
141		return $aState;	// nothing more to do here ...
142	} // handle()
143
144	/**
145	 * Handle the actual output creation.
146	 *
147	 * <p>
148	 * The method checks for the given <tt>$aFormat</tt> and returns
149	 * <tt>FALSE</tt> when a format isn't supported. <tt>$aRenderer</tt>
150	 * contains a reference to the renderer object which is currently
151	 * handling the rendering. The contents of <tt>$aData</tt> is the
152	 * return value of the <tt>handle()</tt> method.
153	 * </p>
154	 * @param $aFormat String The output format to generate.
155	 * @param $aRenderer Object A reference to the renderer object.
156	 * @param $aData Integer The state value returned by <tt>handle()</tt>.
157	 * @return Boolean <tt>TRUE</tt> always.
158	 * @public
159	 * @see handle()
160	 */
161	function render($aFormat, &$aRenderer, &$aData) {
162		if (DOKU_LEXER_SPECIAL == $aData) {
163			// No test of '$aFormat' needed here:
164			// The raw UTF-8 character sequence is the same anyway.
165			$aRenderer->doc .= chr(194) . chr(173);
166		} // if
167		return TRUE;
168	} // render()
169
170	//@}
171} // class syntax_plugin_shy
172} // if
173?>
174