deflist plugin by Matthias Watermann
Full range (X)HTML style definition list
Last updated on 2007-08-15. Provides Syntax.
Compatible with DokuWiki 2005-07-13+.
Similar to definition, definitionlist, definitions, dl, yalist.
One of the most important HTML tags marks up a list of definitions1). In contrast to the more simpler (un)ordered lists which both consist solely of list item (”<li>”) elements, a definition list embeds two elements, a definition term (”<dt>” which is restricted to inline content) and its respective definition data (”<dd>” which contains block-level content)2). Such a list of terms/phrases and their definition/description can have – by ways of HTML – various slightly different forms:
<dl> <dt>Item 1</dt> <dd>First definition of item one.</dd> <dd>Second definition of item one.</dd> <dd>Third definition of item one.</dd> <dt>Item 2</dt> <dd>Definition of item two.</dd> <dt>Item 3</dt> <dt>Item 4</dt> <dd>Definition of items three and four.</dd> <dt>Item 5</dt> <dt>Item 6</dt> <dd>First definition of items five and six.</dd> <dd>Second definition of items five and six.</dd> </dl>
This plugin allows for using all four variants in your DokuWiki pages thus adding the full range of W3C definition lists to DokuWiki.
The markup syntax implemented by this plugin looks in its simplest form like
?? term/phrase :: definition of term !!
Everything between ?? and :: is marked up as the definition term (i.e. <dt>) and everything between :: and !! is taken for the term's definition data (i.e. <dd>)3) where there is additional markup allowed (see the examples below).
The most readable form for me seems to be:
?? the term :: the definition !!
But, of course, you're free to use whatever linebreaking style you like.
To allow for linking (either from the same document or an external document) to a certain definition all definition terms automatically get anchored, that is they are wrapped within a
<a id="the_term" name="the_term">the Term</a>
construct12).
The XHTML specs (section C.8) provide a RegEx for valid fragment identifiers which is reduced by this implementation to ”[a-z][a-z0-9_]*[a-z0-9]”13).
All non alphanumeric characters14) are replaced by underscores15).
So the wiki markup
?? Item 1(a) :: Definition of item one (a). !!
would be converted to the HTML markup
<dt><a id="item_1_a" name="item_1_a">Item 1(a)</a></dt> <dd><p>Definition of item one (a).</p></dd>
Please note that ”id” and ”name” attributes by definition share the same namespace16) and MUST be unique within a document17). As a consequence you have to make sure that no two identical fragment identifiers are used within one document. – You should be aware that DokuWiki automatically creates anchors18) for all headlines. Therefor you must avoid to use the same string for both a headline and a definition term. And, of course, there must not be the same definition term multiple times within the same document.
In contrast to older releases of this plugin19) the nesting of definition lists is now supported20). The syntax looks like:
?? Level 1 Term 1-1
:: definition __1-1__ !!
?? Level 1 Term 1-2
:: Prefix of //1-2//
?? Level 2 Term 2-2-1
:: definition of Term __2-2-1__ !!
?? Level 2 Term 2-2-2
:: Prefix of **2-2-2**
?? Level 3 Term 3-2-2-1
:: definition of Term __3-2-2-1__ !!
?? Level 3 Term 3-2-2-2
:: Prefix of __3-2-2-2__
?? Level 4 Term 4-2-2-2-1
:: definition of Term __4-2-2-2-1__ !!
?? Level 4 Term 4-2-2-2-2
:: definition of Term __4-2-2-2-2__ !!
Postfix of __3-2-2-2__ !!
Postfix of **2-2-2** !!
Postfix of //1-2// !!
?? Level 1 Term 1-3
:: definition __1-3__ !!
As one can see, the definition term ”?? ... ::” is indented variably for the different nesting levels:
Only the very last definition data is terminated by two linefeeds while the nested lists are handled solely by the indention level of its definition term21). See Lorem ipsum below for a working example.
The ”Prefix of …” and ”Postfix of …” texts are (apart from the ”::” and ”!!” delimiters) completely optional. In other words the nested list could be started without any preceding text and ended without any subsequent text. I've used the texts here for demonstration purposes only to make the nestings more obvious.
The generated HTML rendering looks as follows:
<dl> <dt><a id="level_1_term_1_1" name="level_1_term_1_1">Level 1 Term 1-1</a></dt> <dd><p>definition <u>1-1</u></p></dd> <dt><a id="level_1_term_1_2" name="level_1_term_1_2">Level 1 Term 1-2</a></dt> <dd><p>Prefix of <em>1-2</em></dd> <dd><dl> <dt><a id="level_2_term_2_2_1" name="level_2_term_2_2_1">Level 2 Term 2-2-1</a></dt> <dd><p>definition of Term <u>2-2-1</u></p></dd> <dt><a id="level_2_term_2_2_2" name="level_2_term_2_2_2">Level 2 Term 2-2-2</a></dt> <dd><p>Prefix of <strong>2-2-2</strong></dd> <dd><dl> <dt><a id="level_3_term_3_2_2_1" name="level_3_term_3_2_2_1">Level 3 Term 3-2-2-1</a></dt> <dd><p>definition of Term <u>3-2-2-1</u></p></dd> <dt><a id="level_3_term_3_2_2_2" name="level_3_term_3_2_2_2">Level 3 Term 3-2-2-2</a></dt> <dd><p>Prefix of <u>3-2-2-2</u></dd> <dd><dl> <dt><a id="level_4_term_4_2_2_2_1" name="level_4_term_4_2_2_2_1">Level 4 Term 4-2-2-2-1</a></dt> <dd><p>definition of Term <u>4-2-2-2-1</u></p></dd> <dt><a id="level_4_term_4_2_2_2_2" name="level_4_term_4_2_2_2_2">Level 4 Term 4-2-2-2-2</a></dt> <dd><p>definition of Term <u>4-2-2-2-2</u></p></dd> </dl> <p>Postfix of <u>3-2-2-2</u></p></dd> </dl> <p>Postfix of <strong>2-2-2</strong></p></dd> </dl> <p>Postfix of <em>1-2</em></p></dd> <dt><a id="level_1_term_1_3" name="level_1_term_1_3">Level 1 Term 1-3</a></dt> <dd><p>definition <u>1-3</u></p></dd> </dl><p>
(X)HTML style Markup (i.e. ”<sometag>” like markup) should generally not be used in wiki pages.
In case it's inserted nevertheless in a definition list the HTML special characters ”&”, ”<” and ”>” are converted to HTML entities thus rendering the tag(s) as normal text.
This should make it impossible to compromise the wiki by inserting e.g. malicious JavaScript code – it would show up in plain source code instead of beeing executed.22)
Following the overview above let's see how to write the wiki text accordingly.
?? Item One :: Definition of item one. !!
?? Item Two ?? Item Three :: Definition of items two and three. !!
?? Item Four :: First definition of item four. !! :: Second definition of item four. !! :: Third definition of item four. !!
?? Item Five ?? Item Six :: First definition of items five and six. !! :: Second definition of items five and six. !! :: Third definition of items five and six. !!
?? Item 1 :: First definition of item one. !! :: Second definition of item one. !! :: Third definition of item one. !! ?? Item 2 :: Definition of item two. !! ?? Item 3 ?? Item 4 :: Definition of items three and four. !! ?? Item 5 ?? Item 6 ::First definition of items five and six. !! ::Second definition of items five and six. !!
Note the additional linefeed at the end of each list marking, er, the end of list.
Inside the definition data other DokuWiki markup may be used e.g. strong, emphasized or underlined text.23) – The following example shows how some other block-level elements are incorporated within a definition list. Besides the aforesaid font manipulations there are table, un/ordered list24), footnote and all possible combinations of definition term/data groups. — When using such nested block elements you are, of course, bound by the respective element's syntax constraints25).
Suppose kind of glossary providing information about Terms, phrases or abbreviations26).
Once the maintainer of the Wiki decides to install this plugin, this note and the ”code” tags around the following block could be removed to make its effects actually visible.
?? AAA
::* //__A__nton's __A__ccelerated __A__bominations//: Morbi sed dui ac arcu nonummy vestibulum.
Class aptent taciti sociosqu ad litora torquent per conubia nostra,
per inceptos hymenaeos.
Vivamus blandit eros mollis tellus. Maecenas egestas posuere wisi. !!
::* //__A__nother __a__bandoned __a__ccessory//: Pellentesque vel odio.
Praesent laoreet nulla nec quam.
Curabitur pede pede, ultrices ornare, accumsan eget, suscipit sed, metus.
Sed volutpat justo sit amet libero. !!
?? APC
:: This abbreviation stands for various different things, amongst them:
?? Devices
::
?? American Power Conversion Corporation
:: A provider of [[#UPS]] (see [[http://www.apc.com/]]).
Quisque non orci ut sapien tincidunt tristique. Duis mollis feugiat dolor.
Etiam elit. Pellentesque et lacus. Duis ut turpis. In nonummy. Donec
consectetuer pharetra mi. Quisque vestibulum neque non erat.
The following models are quite popular:
?? model a
:: Maecenas in purus. Aenean in erat. Morbi ac felis ut lorem dapibus tempus.
^ semper malesuada ^ Donec ut nulla ^ Praesent at mauris ^
| odio |Duis sed dolor | Donec tempor |
| erat eu |Maecenas auctor neque sit amet lacus ||
| metus |Aenean | id tortor |
<sup>Sed in dui quis nisl adipiscing semper.</sup> !!
?? model b
:: Suspendisse dignissim.
Suspendisse fermentum luctus nulla. Integer ut ipsum sit
amet felis fermentum consequat. Morbi eget augue vel metus pellentesque
eleifend. !!
?? model c
::
^ semper malesuada ^ Donec ut nulla ^ Praesent at mauris ^
|In auctor |ipsum urna |cursus felis |
|erat eu pretium |vitae varius |elit risus |
|Aenean rhoncus iaculis ipsum ||interdum |
//Sed ornare eget augue. dolor et nisl. Morbi rutrum dui ut mauris. Proin
non felis sit amet odio eleifend iaculis.// !!
GNU/Linux support: Quisque faucibus nonummy nulla. Nam a nulla sed nibh
condimentum euismod. Integer ac sem eu quam adipiscing rutrum.
//Vestibulum// accumsan. Cras quam. Fusce nibh ante, convallis quis,
sollicitudin a, rutrum a, sem.
!!
?? Abra Padrapa Cumulii
:: A private corporation. Vivamus tristique, pede eu vulputate pharetra,
nulla purus volutpat ligula, nec condimentum velit mauris at lorem. Donec
sit amet lacus. !!
?? Organizations
::
?? Association for Progressive Communications
:: An organization founded ... (see [[http://www.apc.org/]])
The activities of this worldwide acting [[#NGO]] include
- Aenean ligula mi, feugiat nec, eleifend ac, ullamcorper id, velit. Donec at orci in leo nonummy fermentum. Vestibulum pellentesque wisi sed magna elementum mattis.
- Donec vel ante quis ipsum vulputate dapibus. Cras ultrices. Sed egestas neque nec augue congue ornare. Sed sit amet lectus ac nibh porta mollis. Aenean justo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
- Pellentesque nonummy nunc eu lacus. Praesent tincidunt mollis wisi. Donec id est. Proin odio wisi, ornare vitae, scelerisque non, ultrices vel, dolor. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla nec risus.
- Aliquam erat volutpat. Integer non dui id justo sodales dignissim. In molestie suscipit ipsum. Donec nonummy mauris id justo. Nullam vehicula gravida tortor.
!!
?? Another Public Community
:: A publically available service. Vivamus tortor erat, dictum ut, ultrices
eget, gravida non, ligula. Vestibulum malesuada, risus nec tempor vulputate,
est velit placerat orci, viverra tincidunt mi sapien eu augue. !!
?? Aphasellus polumassa corleo
:: Nullam tempor adipiscing quam, eleifend eu,
dignissim ac, venenatis a, lorem. Vestibulum sed ipsum quis neque tincidunt
luctus. Curabitur eu nisl. Pellentesque non metus id purus rhoncus rutrum. !!
?? other ::
* Morbi nonummy sodales metus. Praesent semper. Nullam at leo. Cras turpis.
* Quisque nibh ipsum, malesuada vel, feugiat id, fringilla sit amet, mauris.
* Morbi imperdiet volutpat tellus. Donec enim libero, auctor at, hendrerit ac, eleifend vitae, arcu.
* Praesent quis libero ac sapien vestibulum mollis. Quisque eget ante eget velit egestas sagittis.
* Proin porta pede non quam. Quisque congue nibh id wisi. Curabitur malesuada adipiscing est. Donec eleifend.
* Morbi tristique congue velit. Etiam placerat aliquet orci. In tincidunt venenatis enim.
//Maecenas id metus non quam feugiat pretium.// !!
!!
?? NGO
:: __N__on-__G__overnmental __O__rganization. Aliquam mollis libero vel elit.
Sed tempus ante et ante. Phasellus sed mauris nec diam ultrices consequat.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames
ac turpis egestas. Phasellus malesuada. !!
?? UPS
::
?? Uninterruptible Power Supply.
:: Mauris quis justo nec nibh ultrices molestie. Integer
imperdiet feugiat sapien. Nunc ante justo, dapibus nec, interdum quis,
tempus ut, ligula. !!
?? Ut Provo Corpora
:: Laoreet tellus placerat libero hendrerit posuere. Sed
eleifend sollicitudin felis. Etiam lacinia malesuada augue. Cras eu odio.
Pellentesque id sem. Mauris erat sapien, ullamcorper id, facilisis a, congue
in, lectus. Donec risus nisl, rutrum ornare, imperdiet ut, ultricies eu, neque. !!
This will be converted to HTML as follows:
<dl> <dt><a id="aaa" name="aaa">AAA</a></dt> <dd><p>* <em><u>A</u>nton's <u>A</u>ccelerated <u>A</u>bominations</em>: Morbi sed dui ac arcu nonummy vestibulum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Vivamus blandit eros mollis tellus. Maecenas egestas posuere wisi.</p></dd> <dd><p>* <em><u>A</u>nother <u>a</u>bandoned <u>a</u>ccessory</em>: Pellentesque vel odio. Praesent laoreet nulla nec quam. Curabitur pede pede, ultrices ornare, accumsan eget, suscipit sed, metus. Sed volutpat justo sit amet libero.</p></dd> <dt><a id="apc" name="apc">APC</a></dt> <dd><p>This abbreviation stands for various different things, amongst them:</dd> <dd><dl> <dt><a id="devices" name="devices">Devices</a></dt> <dd><dl> <dt><a id="american_power_conversion_corporation" name="american_power_conversion_corporation">American Power Conversion Corporation</a></dt> <dd><p>A provider of →<a href="#ups" title="plugins:deflist_test ↵" class="wikilink1">UPS</a> (see <a href="http://www.apc.com/" class="urlextern" target="_blank" title="http://www.apc.com/" onclick="return svchk()" onkeypress="return svchk()" rel="nofollow">http://www.apc.com/</a>). Quisque non orci ut sapien tincidunt tristique. Duis mollis feugiat dolor. Etiam elit. Pellentesque et lacus. Duis ut turpis. In nonummy. Donec consectetuer pharetra mi. Quisque vestibulum neque non erat. The following models are quite popular:</dd> <dd><dl> <dt><a id="model_a" name="model_a">model a</a></dt> <dd><p>Maecenas in purus. Aenean in erat. Morbi ac felis ut lorem dapibus tempus. </p> <table class="inline"> <tr> <th class="leftalign"> semper malesuada </th><th class="leftalign"> Donec ut nulla </th><th class="leftalign"> Praesent at mauris </th> </tr> <tr> <td class="leftalign"> odio </td><td class="leftalign">Duis sed dolor </td><td class="leftalign"> Donec tempor </td> </tr> <tr> <td class="leftalign"> erat eu </td><td colspan="2">Maecenas auctor neque sit amet lacus </td> </tr> <tr> <td class="leftalign"> metus </td><td class="leftalign">Aenean </td><td class="leftalign"> id tortor </td> </tr> </table> <p><sup>Sed in dui quis nisl adipiscing semper.</sup></p></dd> <dt><a id="model_b" name="model_b">model b</a></dt> <dd><p>Suspendisse dignissim. Suspendisse fermentum luctus nulla. Integer ut ipsum sit amet felis fermentum consequat. Morbi eget augue vel metus pellentesque eleifend.</p></dd> <dt><a id="model_c" name="model_c">model c</a></dt> <dd><p></p> <table class="inline"> <tr> <th class="leftalign"> semper malesuada </th><th class="leftalign"> Donec ut nulla </th><th class="leftalign"> Praesent at mauris </th> </tr> <tr> <td class="leftalign">In auctor </td><td class="leftalign">ipsum urna </td><td class="leftalign">cursus felis </td> </tr> <tr> <td class="leftalign">erat eu pretium </td><td class="leftalign">vitae varius </td><td class="leftalign">elit risus </td> </tr> <tr> <td class="leftalign" colspan="2">Aenean rhoncus iaculis ipsum </td><td class="leftalign">interdum </td> </tr> </table> <p> <em>Sed ornare eget augue. dolor et nisl. Morbi rutrum dui ut mauris. Proin non felis sit amet odio eleifend iaculis.</em></p></dd> </dl> <p> <acronym title="GNU's Not Unix">GNU</acronym>/Linux support: Quisque faucibus nonummy nulla. Nam a nulla sed nibh condimentum euismod. Integer ac sem eu quam adipiscing rutrum.</p> <p><em>Vestibulum</em> accumsan. Cras quam. Fusce nibh ante, convallis quis, sollicitudin a, rutrum a, sem. </p></dd> <dt><a id="abra_padrapa_cumulii" name="abra_padrapa_cumulii">Abra Padrapa Cumulii</a></dt> <dd><p>A private corporation. Vivamus tristique, pede eu vulputate pharetra, nulla purus volutpat ligula, nec condimentum velit mauris at lorem. Donec sit amet lacus.</p></dd> </dl> <dt><a id="organizations" name="organizations">Organizations</a></dt> <dd><dl> <dt><a id="association_for_progressive_communications" name="association_for_progressive_communications">Association for Progressive Communications</a></dt> <dd><p>An organization founded ... (see <a href="http://www.apc.org/" class="urlextern" target="_blank" title="http://www.apc.org/" onclick="return svchk()" onkeypress="return svchk()" rel="nofollow">http://www.apc.org/</a>) The activities of this worldwide acting →<a href="#ngo" title="plugins:deflist_test ↵" class="wikilink1">NGO</a> include</p> <ol> <li class="level1"><div class="li"> Aenean ligula mi, feugiat nec, eleifend ac, ullamcorper id, velit. Donec at orci in leo nonummy fermentum. Vestibulum pellentesque wisi sed magna elementum mattis.</div> </li> <li class="level1"><div class="li"> Donec vel ante quis ipsum vulputate dapibus. Cras ultrices. Sed egestas neque nec augue congue ornare. Sed sit amet lectus ac nibh porta mollis. Aenean justo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</div> </li> <li class="level1"><div class="li"> Pellentesque nonummy nunc eu lacus. Praesent tincidunt mollis wisi. Donec id est. Proin odio wisi, ornare vitae, scelerisque non, ultrices vel, dolor. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla nec risus.</div> </li> <li class="level1"><div class="li"> Aliquam erat volutpat. Integer non dui id justo sodales dignissim. In molestie suscipit ipsum. Donec nonummy mauris id justo. Nullam vehicula gravida tortor.</div> </li> </ol></dd> <dt><a id="another_public_community" name="another_public_community">Another Public Community</a></dt> <dd><p>A publically available service. Vivamus tortor erat, dictum ut, ultrices eget, gravida non, ligula. Vestibulum malesuada, risus nec tempor vulputate, est velit placerat orci, viverra tincidunt mi sapien eu augue.</p></dd> <dt><a id="aphasellus_polumassa_corleo" name="aphasellus_polumassa_corleo">Aphasellus polumassa corleo</a></dt> <dd><p>Nullam tempor adipiscing quam, eleifend eu, dignissim ac, venenatis a, lorem. Vestibulum sed ipsum quis neque tincidunt luctus. Curabitur eu nisl. Pellentesque non metus id purus rhoncus rutrum.</p></dd> </dl> <dt><a id="other" name="other">other</a></dt> <dd><p></p> <ul> <li class="level1"><div class="li"> Morbi nonummy sodales metus. Praesent semper. Nullam at leo. Cras turpis. </div> </li> <li class="level1"><div class="li"> Quisque nibh ipsum, malesuada vel, feugiat id, fringilla sit amet, mauris. </div> <;/li> <li class="level1"><div class="li"> Morbi imperdiet volutpat tellus. Donec enim libero, auctor at, hendrerit ac, eleifend vitae, arcu.</div> </li> <li class="level1"><div class="li"> Praesent quis libero ac sapien vestibulum mollis. Quisque eget ante eget velit egestas sagittis.</div> </li> <li class="level1"><div class="li"> Proin porta pede non quam. Quisque congue nibh id wisi. Curabitur malesuada adipiscing est. Donec eleifend.</div> </li> <li class="level1"><div class="li"> Morbi tristique congue velit. Etiam placerat aliquet orci. In tincidunt venenatis enim.</div> </li> </ul> <p> <em>Maecenas id metus non quam feugiat pretium.</em></p></dd> </dl> <dt><a id="ngo" name="ngo">NGO</a></dt> <dd><p><u>N</u>on-<u>G</u>overnmental <u>O</u>rganization. Aliquam mollis libero vel elit. Sed tempus ante et ante. Phasellus sed mauris nec diam ultrices consequat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus malesuada.</p></dd> <dt><a id="ups" name="ups">UPS</a></dt> <dd><dl> <dt><a id="uninterruptible_power_supply" name="uninterruptible_power_supply">Uninterruptible Power Supply.</a></dt> <dd><p>Mauris quis justo nec nibh ultrices molestie. Integer imperdiet feugiat sapien. Nunc ante justo, dapibus nec, interdum quis, tempus ut, ligula.</p></dd> <dt><a id="ut_provo_corpora" name="ut_provo_corpora">Ut Provo Corpora</a></dt> <dd><p>Laoreet tellus placerat libero hendrerit posuere. Sed eleifend sollicitudin felis. Etiam lacinia malesuada augue. Cras eu odio.</p> <p>Pellentesque id sem. Mauris erat sapien, ullamcorper id, facilisis a, congue in, lectus. Donec risus nisl, rutrum ornare, imperdiet ut, ultricies eu, neque.</p></dd> </dl></dd> </dl><p>
Please note that the plugin tries hard to minimize the effects of DokuWiki's current handling27) of the respective renderers for the nested elements. This plugin attempts to make the best of the given situation by inserting/removing opening/closing paragraph tags as appropriate28).
It's quite easy to integrate this plugin with your DokuWiki:
{dokuwiki}/lib/plugins (make sure, included subdirectories are unpacked correctly); this will create the directory {dokuwiki}/lib/plugins/deflist.chown apache:apache dokuwiki/lib/plugins/* -Rc
You might as well use the plugin manager for installing or updating this plugin.
Here comes the GPLed PHP source29) for those who'd like to scan it before actually installing it:
<?php if (! class_exists('syntax_plugin_deflist')) { if (! defined('DOKU_PLUGIN')) { if (! defined('DOKU_INC')) { define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/'); } // if define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); } // if // include parent class require_once(DOKU_PLUGIN . 'syntax.php'); define('PLUGIN_DEFLIST', 'plugin_deflist'); /** * <tt>syntax_plugin_deflist.php </tt>- A PHP4 class that implements * a <tt>DokuWiki</tt> plugin for <tt>definition list</tt> elements. * * <p> * Definition list pattern:<br> * <tt>?? Term :: Term definition !!</tt> * </p> * <pre> * Copyright (C) 2005, 2007 DFG/M.Watermann, D-10247 Berlin, FRG * All rights reserved * EMail : <support@mwat.de> * </pre> * <p> * <em>Credits:</em> This plugin was inspired by ideas of * <a href="http://www.dokuwiki.org/plugin:definition_list" * target="_blank">Stephane Chamberland</a> and <a target="_blank" * href="http://www.dokuwiki.org/plugin:definitions">Pavel * Vitis</a> both of whom wrote a similar plugin that <em>almost</em> * worked. * </p> * <div class="disclaimer"> * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either * <a href="http://www.gnu.org/licenses/gpl.html">version 3</a> of the * License, or (at your option) any later version.<br> * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * </div> * @author <a href="mailto:support@mwat.de">Matthias Watermann</a> * @version <tt>$Id: syntax_plugin_deflist.php,v 1.14 2007/08/15 12:36:20 matthias Exp $</tt> * @since created 05-Aug-2005 */ class syntax_plugin_deflist extends DokuWiki_Syntax_Plugin { /** * @privatesection */ //@{ /** * Convert the specified <tt>$aID</tt> to a valid XHTML * fragment identifier. * * <p> * <a href="http://www.w3.org/TR/xhtml1/#guidelines" target="_blank"> * XHTML 1</a> (section C.8, Fragment Identifiers) gives the regex * <tt>[A-Za-z][A-Za-z0-9:_.-]*</tt> for valid identifiers. Here * it's slightly reduced to <tt>[A-Za-z][A-Za-z0-9_]+</tt> i.e. * all non alphanumeric characters are replaced by underscores. * </p> * @param $aID String The raw ID string. * @return String * @private * @since created 24-Aug-2005 * @see render() */ function _makeID(&$aID) { static $CHARS; if (! is_array($CHARS)) { $CHARS = array('|[^A-Za-z0-9_]|', // replace invalid characters '|_{2,}|', // reduce multiple underscores '|^[^A-Za-z]+|', // remove invalid leading chars '|_+$|'); // remove trailing underscores } // if // As long as DokuWiki (in contrast to W3C) doesn't allow uppercase // letters in internal anchor names we've to use 'strtolower()' // here as well to make the anchors work within DokuWiki. return strtolower(preg_replace($CHARS, array('_', '_'), utf8_deaccent($aID, 0))); } // _makeID() //@} /** * @publicsection */ //@{ /** * Tell the parser whether the plugin accepts syntax mode * <tt>$aMode</tt> within its own markup. * * <p> * This method mostly returns <tt>TRUE</tt> since all other types * are allowed within a definition list's <tt>DD</tt> sections. * Only another definition list is denied since <em>nested DLs are * currently not supported</em>. * </p> * @param $aMode String The requested syntaxmode. * @return Boolean <tt>TRUE</tt> unless <tt>$aMode</tt> * is <tt>plugin_deflist</tt> (which would result in a * <tt>FALSE</tt> method result). * @public * @see getAllowedTypes() */ function accepts($aMode) { return (PLUGIN_DEFLIST != $aMode); } // accepts() /** * Connect lookup pattern to lexer. * * @param $aMode String The desired rendermode. * @public * @see render() */ function connectTo($aMode) { if (PLUGIN_DEFLIST == $aMode) { return; } // if // We have to use assertion patterns here to make sure the DD sections // are UNMATCHED since only those are subject to further substitution. $this->Lexer->addEntryPattern( '\n\x20{2,}\s*\x3F\x3F(?s).+?(?=::(?s).*!!\n\n)', $aMode, PLUGIN_DEFLIST); $this->Lexer->addEntryPattern( '\n\t+\s*\x3F\x3F(?s).+?(?=::(?s).*!!\n\n)', $aMode, PLUGIN_DEFLIST); $this->Lexer->addPattern( '\n\x20{2,}\s*\x3F\x3F(?s).+?\s*(?=::(?s).*?!!)', PLUGIN_DEFLIST); $this->Lexer->addPattern( '\n\t+\s*\x3F\x3F(?s).+?\s*(?=::(?s).*?!!)', PLUGIN_DEFLIST); } // connectTo() /** * Get an associative array with plugin info. * * <p> * The returned array holds the following fields: * <dl> * <dt>author</dt><dd>Author of the plugin</dd> * <dt>email</dt><dd>Email address to contact the author</dd> * <dt>date</dt><dd>Last modified date of the plugin in * <tt>YYYY-MM-DD</tt> format</dd> * <dt>name</dt><dd>Name of the plugin</dd> * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd> * <dt>url</dt><dd>Website with more information on the plugin * (eg. syntax description)</dd> * </dl> * @return Array Information about this plugin class. * @public * @static */ function getInfo() { return array( 'author' => 'Matthias Watermann', 'email' => 'support@mwat.de', 'date' => '2007-08-15', 'name' => 'Definition List Syntax Plugin', 'desc' => '(X)HTML style Definition Lists [ ?? Term :: Definition !! ]', 'url' => 'http://www.dokuwiki.org/plugin:deflist'); } // getInfo() /** * Define how this plugin is handled regarding paragraphs. * * <p> * This method is important for correct XHTML nesting. It returns * one of the following values: * </p> * <dl> * <dt>normal</dt><dd>The plugin can be used inside paragraphs.</dd> * <dt>block</dt><dd>Open paragraphs need to be closed before * plugin output.</dd> * <dt>stack</dt><dd>Special case: Plugin wraps other paragraphs.</dd> * </dl> * @return String <tt>'normal'</tt> instead of the (correct) 'block' * since otherwise the current DokuWiki parser would put all * substitutions within a DD section in separate paragraphs. * @public * @static */ function getPType() { return 'normal'; } // getPType() /** * Where to sort in? * * @return Integer <tt>18</tt>, an arbitrary value smaller * <tt>Doku_Parser_Mode_preformated</tt> (20). * @public * @static */ function getSort() { return 18; } // getSort() /** * Get the type of syntax this plugin defines. * * @return String <tt>'container'</tt>. * @public * @static */ function getType() { return 'container'; } // getType() /** * Handler to prepare matched data for the rendering process. * * <p> * The <tt>$aState</tt> parameter gives the type of pattern * which triggered the call to this method: * </p> * <dl> * <dt>DOKU_LEXER_ENTER</dt> * <dd>a pattern set by <tt>addEntryPattern()</tt>.</dd> * <dt>DOKU_LEXER_MATCHED</dt> * <dd>a pattern set by <tt>addPattern()</tt> (here: DT data).</dd> * <dt>DOKU_LEXER_EXIT</dt> * <dd> a pattern set by <tt>addExitPattern()</tt>.</dd> * <dt>DOKU_LEXER_UNMATCHED</dt> * <dd>ordinary text encountered within the plugin's syntax mode * which doesn't match any pattern (here: DD data).</dd> * </dl> * @param $aMatch String The text matched by the patterns. * @param $aState Integer The lexer state for the match. * @param $aPos Integer The character position of the matched text. * @param $aHandler Object Reference to the Doku_Handler object. * @return Array Index <tt>[0]</tt> holds the current * <tt>$aState</tt>, index <tt>[1]</tt> the match (as a list of * entries) prepared for the <tt>render()</tt> method. * @public * @see render() * @static */ function handle($aMatch, $aState, $aPos, &$aHandler) { static $ESCDELIMS; // static constants to avoid the runtime overhead static $UNDELIMS; // of re-creating the arrays on each method call if (! is_array($ESCDELIMS)) { $ESCDELIMS = array('\?', '\!', '\:'); } // if if (! is_array($UNDELIMS)) { $UNDELIMS = array('?', '!', ':'); } // if switch ($aState) { case DOKU_LEXER_ENTER: // fall through to extract initial DTs case DOKU_LEXER_MATCHED: // DTs $aMatch = preg_split('|\n+(\s*\?\?)\s*|', $aMatch, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $dts = array(); $c = count($aMatch); for ($i = 0; $c > $i; ++$i) { if ($i & 1) { $dts[] = array($aMatch[$i - 1], str_replace($ESCDELIMS, $UNDELIMS, trim($aMatch[$i]))); $aMatch[$i - 1] = $aMatch[$i] = NULL; } else { $aMatch[$i