This is an old revision of the document!
Table of Contents
In and Out Plugin
Background
<del> ... </del>
is part of standard DokuWiki syntax. There is also a plugin which provides <ins> insert syntax. For me, I wanted something better for two reasons:
- Because of the frequency which I use these features
- Standard HTML tags severely limit the readability of the page when editing,
Feel free to play with it on my playground if you'd like..
Installation
You can use the plugin-manager to install this plugin. The URL is http://design1st.org/files/dokuwiki-plugin_inandout.tgz.
Syntax
You simply put a “-” on both sides of the text you want to appear deleted or a “+” for it to appear inserted. The trick is that there can never be a space between the +/- and the text you are inserting/deleting. Despite this it deals with text that includes spaces and is smart enough to not be fooled by hyphenated words or phone numbers etc.
Example
Input (Plain Text):
Text that you wish to be deleted should be -indicated like this- where as text that is inserted is +indicated like this+.
Output (HTML):
Text that you wish to be deleted should be <del>indicated like this</del> where as text that is inserted is <ins>indicated like this</ins>.
Plugin
Put this code into <your plugin-dir>/inandout/syntax.php
<?php /** * In and Out Plugin: Enables a custom mark-up for inserted and deleted text * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Timothy Martin */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_inandout extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Timothy Martin', 'email' => 'instanttim@mac.com', 'date' => '2006-01-09', 'name' => 'In and Out Plugin', 'desc' => 'Enables a custom mark-up for inserted and deleted text.', 'url' => 'http://www.dokuwiki.org/plugin:inandout', ); } /** * What kind of syntax are we? */ function getType(){ return 'formatting'; } /** * What kind of syntax do we allow (optional) */ function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } /** * Where to sort in? */ function getSort(){ return 137; } /** * Connect pattern to lexer */ function connectTo($mode) { // This is the regex i used to use... // // /\B(-)(?!\s)(.*)(?<!\s)(-)\B/ // $this->Lexer->addEntryPattern('(?<=\B)-(?!\s)(?=.*\w-\B)',$mode,'plugin_inandout'); $this->Lexer->addEntryPattern('(?<=\B)\+(?!\s)(?=.*\w\+\B)',$mode,'plugin_inandout'); } function postConnect() { $this->Lexer->addExitPattern('(?<!\s)-(?=\B)','plugin_inandout'); $this->Lexer->addExitPattern('(?<!\s)\+(?=\B)','plugin_inandout'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler) { switch ($state) { case DOKU_LEXER_ENTER : if ($match == "-") { return array($state, 'del'); } else if ($match == "+") { return array($state, 'ins'); } case DOKU_LEXER_UNMATCHED : return array($state, $match); case DOKU_LEXER_EXIT : if ($match == "-") { return array($state, 'del'); } else if ($match == "+") { return array($state, 'ins'); } } return array(); } /** * Create output */ function render($mode, &$renderer, $data) { if($mode == 'xhtml') { list($state, $match) = $data; switch ($state) { case DOKU_LEXER_ENTER : $renderer->doc .= "<".$match.">"; break; case DOKU_LEXER_UNMATCHED : $renderer->doc .= $renderer->_xmlEntities($match); break; case DOKU_LEXER_EXIT : $renderer->doc .= "</".$match.">"; break; } return true; } return false; } } ?>
Bugs
- I have found a bug where the minus sign in quotes will screw it up.
Discussion
Some notes:
Done!<del> ... </del>
is part of standard DokuWiki syntax. There is also a plugin which provides<ins>
insert syntax. It would be handy to indicate that your syntax is an alternative to these other forms.- This really should be done as two plugin components, one for insert and another for delete. Take a look at either the bbcode or code plugins for an example of a single plugin with multiple components. Why do you need that? Because each of your entry patterns has a different exit pattern. If you don't have multiple plugin/components a '- ' can cause an exit from insert syntax and a '+ ' from delete.
You should add a look ahead to ensure there is a matching exit pattern for the entry pattern.Done!
e.g.(?<=\B)-(?>=[^ \r\n].+?[^ \r\n]-[ \r\n])
.If you don't want to allow line breaks within your plugin useI changed my mind about this… since default DokuWiki ignores linebreaks, I figure I should too.[^\n\r]
instead of '.' in your look ahead for an ending pattern.
I hope this help some. — Christopher Smith 2005-11-30 20:52
If you install this plugin, you're going to want to fix your “wiki:syntax” page as a sizable portion of the bottom of this page is striked out. — GaryV 2006-06-30 08:30
This plugin seems to break my wiki:syntax page completely. All that displays is the “You are here” box at the top of the page. I like this plugin, but I can't use it. — lenehey 2007-12-21 9:48