/[drupal]/contributions/modules/textile/textile.module
ViewVC logotype

Contents of /contributions/modules/textile/textile.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.22 - (show annotations) (download) (as text)
Mon Oct 13 21:16:34 2008 UTC (13 months, 2 weeks ago) by joshk
Branch: MAIN
CVS Tags: DRUPAL-6--2-0, HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2
Changes since 1.21: +8 -8 lines
File MIME type: text/x-php
update for 6.0 release
1 <?php
2 // $Id: textile.module,v 1.21 2007/06/28 00:26:09 joshk Exp $
3
4 /**
5 * The textile module allows input of Textile shorthand.
6 *
7 * @version $Id: textile.module,v 1.21 2007/06/28 00:26:09 joshk Exp $
8 * @copyright Copyright (c) 2003-2007 Jim Riggs. All rights reserved.
9 * @author Jim Riggs <drupal at jim and lissa dot com>
10 */
11
12 /********************************************************************
13 * Drupal Hooks
14 ********************************************************************/
15
16 /**
17 * Implementation of hook_filter().
18 */
19 function textile_filter($op, $delta = 0, $format = -1, $text = '') {
20 switch ($op) {
21 case 'list':
22 return array(t("Textile"));
23
24 case 'description':
25 return t('Allows content to be submitted using Textile, a simple, plain text syntax that is filtered into valid XHTML.');
26
27 case 'process':
28 if (variable_get("textile_tags_$format", 0)) {
29 return preg_replace_callback('{\[textile\](.*?)(\[/textile\]|$)}is', '_textile_process', $text);
30 }
31 else {
32 return _textile_process(array(NULL, $text));
33 }
34
35 case 'settings':
36 $form = array();
37 $form['textile_settings'] = array(
38 '#type' => 'fieldset',
39 '#title' => t('Textile filter'),
40 '#collapsible' => TRUE
41 );
42 $form['textile_settings']["textile_tags_$format"] = array(
43 '#type' => 'checkbox',
44 '#title' => t('Use tags'),
45 '#default_value' => variable_get("textile_tags_$format", 0),
46 '#description' => t('If enabled, only text between [textile] and optional [/textile] tags will be processed. Otherwise, all text will be processed as Textile markup.')
47 );
48
49 return $form;
50
51 default:
52 return $text;
53 }
54 }
55
56 /**
57 * Implementation of hook_filter_tips().
58 */
59 function textile_filter_tips($delta, $format, $long = FALSE) {
60 if ($long) {
61 return t('
62 <h1>Textile Help</h1>
63
64 <h2>Block modifier syntax:</h2>
65
66 <p>
67 CSS attributes can be applied to blocks (paragraphs, headers,
68 etc.). CSS classes are specifed with "<code>(<i>class</i>)</code>";
69 CSS IDs are specified with "<code>(#<i>id</i>)</code>"; both can be
70 specified with "<code>(<i>class</i>#<i>id</i>)</code>". An arbtirary
71 CSS style can be applied by using
72 "<code>{<i>style</i>}</code>". Finally, language attributes are
73 applied using "<code>[<i>language</i>]</code>".
74 </p>
75 <p>
76 Additionally, alignment and indentation shorthands are provided. To
77 left-align, right-align, center, and justify text, use
78 "<code>&lt;</code>", "<code>&gt;</code>", "<code>=</code>", and
79 "<code>&lt;&gt;</code>", respectively. "<code>(</code>" left-indents
80 a block 1em for each occurrence, and "<code>)</code>" right-indents
81 similarly.
82 </p>
83 <p>
84 Tables have additional options. "<code>^</code>", "<code>-</code>",
85 and "<code>~</code>" specify top, middle, and bottom vertical
86 alignment. The "<code>_</code>" attribute on a cell indicates that
87 it is a table header.
88 </p>
89 <p>
90 The examples below illustrate these attributes.
91 </p>
92
93 <table>
94 <tr>
95 <th>textile input</th>
96 <th>output</th>
97 </tr>
98
99 <tr class="dark">
100 <td colspan="2">
101 <h3>Headings</h3>
102 <code>h<i>x</i>.</code> (where <i>x</i> is 1 - 6)
103 </td>
104 </tr>
105 <tr class="light">
106 <td>h1. Heading</td>
107 <td><h1>Heading</h1></td>
108 </tr>
109 <tr class="light">
110 <td>h2(class). Heading with class</td>
111 <td><h2 class="class">Heading with class</h2></td>
112 </tr>
113
114 <tr class="dark">
115 <td colspan="2"><h3>Paragraphs</h3></td>
116 </tr>
117 <tr class="light">
118 <td>p=. Centered text</td>
119 <td><p style="text-align:center;">Centered text</p></td>
120 </tr>
121 <tr class="light">
122 <td>p())(#id). Indented text with ID</td>
123 <td>
124 <p style="padding-left:1em;padding-right:2em;" id="id">Indented
125 text with ID</p>
126 </td>
127 </tr>
128
129 <tr class="dark">
130 <td colspan="2"><h3>Block quotes</h3></td>
131 </tr>
132 <tr class="light">
133 <td>bq(class#id). Quote with class and ID</td>
134 <td>
135 <blockquote class="class" id="id">Quote with class and
136 ID</blockquote>
137 </td>
138 </tr>
139 <tr class="light">
140 <td>bq[en]. English quote</td>
141 <td>
142 <blockquote lang="en">English quote</blockquote>
143 </td>
144 </tr>
145
146 <tr class="dark">
147 <td colspan="2"><h3>Ordered lists</h3></td>
148 </tr>
149 <tr class="light">
150 <td>
151 {color: blue}# Attributes specified<br />
152 # before the first item<br />
153 # affect the whole list
154 </td>
155 <td>
156 <ol style="color:blue;">
157 <li>Attributes specified</li>
158 <li>before the first item</li>
159 <li>affect the whole list</li>
160 </ol>
161 </td>
162 </tr>
163
164 <tr class="dark">
165 <td colspan="2"><h3>Unordered lists</h3></td>
166 </tr>
167 <tr class="light">
168 <td>
169 * Lists can have<br />
170 ## subitems or<br />
171 ## sublists<br />
172 * too
173 </td>
174 <td>
175 <ul>
176 <li>Lists can have
177 <ol>
178 <li>subitems or</li>
179 <li>sublists</li>
180 </ol>
181 </li>
182 <li>too</li>
183 </ul>
184 </td>
185 </tr>
186
187 <tr class="dark">
188 <td colspan="2">
189 <h3>Footnotes</h3>
190 <code>fn<i>x</i>.</code> (where <i>x</i> is 1 - 100)
191 </td>
192 </tr>
193 <tr class="light">
194 <td>fn17. Footnote</td>
195 <td><p id="fn17"><sup>17</sup> Footnote</p></td>
196 </tr>
197
198 <tr class="dark">
199 <td colspan="2"><h3>Tables</h3></td>
200 </tr>
201 <tr class="light">
202 <td>
203 |_. A|_. B|_. C|<br />
204 (dark). |very|simple|table|<br />
205 |&lt;. left|=. center|&gt;. right|<br />
206 |^{height:3em}. top|-. middle|~. bottom|
207 </td>
208 <td>
209 <table>
210 <tr>
211 <th>A</th>
212 <th>B</th>
213 <th>C</th>
214 </tr>
215 <tr class="dark">
216 <td>very</td>
217 <td>simple</td>
218 <td>table</td>
219 </tr>
220 <tr>
221 <td style="text-align:left;">left</td>
222 <td style="text-align:center;">center</td>
223 <td style="text-align:right;">right</td>
224 </tr>
225 <tr>
226 <td style="vertical-align:top;height:3em;">top</td>
227 <td style="vertical-align:middle;">middle</td>
228 <td style="vertical-align:bottom;">bottom</td>
229 </tr>
230 </table>
231 </td>
232 </tr>
233 </table>
234
235 <h2>Phrase modifier syntax:</h2>
236 <p>
237 The class, ID, style, and language attributes described above also
238 apply to the span phrase modifier as shown below.
239 </p>
240
241 <table>
242 <tr>
243 <th>textile input</th>
244 <th>output</th>
245 </tr>
246 <tr class="dark">
247 <td>_emphasis_</td>
248 <td><em>emphasis</em></td>
249 </tr>
250 <tr class="light">
251 <td>__italic__</td>
252 <td><i>italic</i></td>
253 </tr>
254 <tr class="dark">
255 <td>*strong*</td>
256 <td><strong>strong</strong></td>
257 </tr>
258 <tr class="light">
259 <td>**bold**</td>
260 <td><b>bold</bold></td>
261 </tr>
262 <tr class="dark">
263 <td>??citation??</td>
264 <td><cite>citation</cite></td>
265 </tr>
266 <tr class="light">
267 <td>-delete text-</td>
268 <td><del>deleted text</del></td>
269 </tr>
270 <tr class="dark">
271 <td>+inserted text+</td>
272 <td><ins>inserted text</ins></td>
273 </tr>
274 <tr class="light">
275 <td>^superscript^</td>
276 <td><sup>superscript</sup></td>
277 </tr>
278 <tr class="dark">
279 <td>~subscript~</td>
280 <td><sub>subscript</sub></td>
281 </tr>
282 <tr class="light">
283 <td>@code@</td>
284 <td><code>code</code></td>
285 </tr>
286 <tr class="dark">
287 <td>%(class)span%</td>
288 <td><span class="class">span</span></td>
289 </tr>
290 <tr class="dark">
291 <td>%{color:red;}span%</td>
292 <td><span style="color:red;">span</span></td>
293 </tr>
294 <tr class="light">
295 <td>==no textile==</td>
296 <td>no textile</td>
297 </tr>
298 <tr class="dark">
299 <td>"link text":url</td>
300 <td><a href="url">link text</a></td>
301 </tr>
302 <tr class="light">
303 <td>"link text(title)":url</td>
304 <td><a href="url" title="title">link text</a></td>
305 </tr>
306 <tr class="dark">
307 <td>!imageurl!</td>
308 <td><img src="imageurl" /></td>
309 </tr>
310 <tr class="light">
311 <td>!imageurl(alt text)!</td>
312 <td><img src="imageurl" alt="alt text" /></td>
313 </tr>
314 <tr class="dark">
315 <td>!imageurl!:url</td>
316 <td><a href="imageurl"><img src="imageurl" /></a></td>
317 </tr>
318 <tr class="light">
319 <td>ABC(Always Be Closing)</td>
320 <td><acronym title="Always Be Closing">ABC</acronym></td>
321 </tr>
322 <tr class="dark">
323 <td>Footnote reference[17]</td>
324 <td>Footnote reference<sup><a href="#17">17</a></sup></td>
325 </tr>
326 </table>
327 ');
328 }
329 elseif (variable_get("textile_tags_$format", 0)) {
330 return t('You can use Textile markup to format text between the [textile] and (optional) [/textile] tags.');
331 }
332 else {
333 return t('You can use Textile markup to format text.');
334 }
335 }
336
337 /**
338 * Implementation of hook_help().
339 */
340 function textile_help($path = 'admin/help#textile', $arg) {
341 switch ($path) {
342 case 'admin/help#textile':
343 return t('
344 <p>
345 The Textile module allows users to enter content using Textile, a
346 simple, plain text syntax that is filtered into valid XHTML. The <a
347 href="filter/tips" title="Textile help">filter tips page</a>
348 provides syntax descriptions and examples.
349 </p>
350 ');
351 }
352 }
353
354 /**
355 * Implementation of hook_enable()
356 *
357 * Run a check for the library and set an error message if not present.
358 */
359 function textile_enable() {
360 if ($error = _textile_lib_check()) {
361 drupal_set_message($error, 'error');
362 }
363 }
364
365
366 /********************************************************************
367 * Module Functions
368 ********************************************************************/
369
370 /**
371 * Performs the appropriate Textile filtering on the provided text.
372 *
373 * @param $matches
374 * The <code>array</code> specifying the text to be filtered at
375 * index 1.
376 *
377 * @return
378 * A <code>string</code> containing the filtered text.
379 *
380 * @private
381 */
382 function _textile_process($matches) {
383 static $textile = NULL;
384
385 if ($textile === NULL) {
386 $path = drupal_get_path('module', 'textile');
387 include_once($path .'/classTextile.php');
388
389 $textile = new Textile();
390 //$textile->hu is the string that preceeds all relative URLs.
391 //So I copied the part of url() implementation in common.inc
392 //not tested in real non-Apache webserver yet
393 $textile->hu = base_path() . ((strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === FALSE) ? 'index.php' : '') . ((bool)variable_get('clean_url', '0') ? '' : '?q=');
394 }
395 //should there be any encoding declaration of some sort? Can't find how to do it though
396 return $textile->TextileThis($matches[1]);
397 }
398
399 /**
400 * Checking that the classTextile.php library is installed, and if not return an error string.
401 */
402
403 function _textile_lib_check() {
404 $path = drupal_get_path('module', 'textile');
405 if (!file_exists($path .'/classTextile.php')) {
406 return t('The classTextile.php library is missing. Drupal cannot use textile markup without this library. Please check the <a href="!url">textile module INSTALL documentation</a> for information on how to download this.', array('!url' => 'http://cvs.drupal.org/viewcvs/*checkout*/drupal/contributions/modules/textile/INSTALL.txt'));
407 }
408 }

  ViewVC Help
Powered by ViewVC 1.1.2