divalign plugin by Jason Byrne
Align content left, right, center, or justify
Last updated on 2008-03-29. Provides Syntax.
No compatibility info given!
As a DokuWiki newbie, I'm pretty proud to be contributing with my first plugin (I only started using DokuWiki two days ago!). I think this makes a pretty nice, unintrusive, and intuitive way to align things without going against what I think is a core principle of not adding in html or html-like code to the native wiki format.
I've updated the source listing below to remove the security issue. Any user of this plugin should upgrade to the new version. To upgrade simply replace the contents of your lib/plugins/divalign/syntax.php file with the code shown below.
The update also includes other changes and improvements:
— Christopher Smith 2008/03/30 01:25
Align Left:
#;; This would be aligned left. #;;
Align Right:
;;#This is aligned right.;;#
Align Center:
;#; This is aligned center. ;#;
Align Justify:
###Justify me baby!###
<?php /** * divalign: allows you to align right, left, center, or justify * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Jason Byrne <jbyrne@floridascale.com> */ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); 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_divalign extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'Jason Byrne', 'email' => 'jbyrne@floridascale.com', 'date' => '2008-03-29', 'name' => 'divalign', 'desc' => 'Add alignment', 'url' => 'http://www.dokuwiki.org/plugin:divalign', ); } function getSort() { return 157; } function getType() { return 'container'; } function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); } function getPType(){ return 'block';} function connectTo($mode) { $this->Lexer->addEntryPattern(';;#(?=.*;;#)',$mode,'plugin_divalign'); $this->Lexer->addEntryPattern('#;;(?=.*#;;)',$mode,'plugin_divalign'); $this->Lexer->addEntryPattern(';#;(?=.*;#;)',$mode,'plugin_divalign'); $this->Lexer->addEntryPattern('###(?=.*###)',$mode,'plugin_divalign'); } function postConnect() { $this->Lexer->addExitPattern(';;#','plugin_divalign'); $this->Lexer->addExitPattern('#;;','plugin_divalign'); $this->Lexer->addExitPattern(';#;','plugin_divalign'); $this->Lexer->addExitPattern('###','plugin_divalign'); } function handle($match, $state, $pos, &$handler){ switch ( $state ) { case DOKU_LEXER_ENTER: switch ( $match ) { case '#;;' : $align = 'left'; break; case ';;#' : $align = 'right'; break; case ';#;' : $align = 'center'; break; case '###' : $align = 'justify'; break; default : $align = ''; } return array($align,$state,$pos); case DOKU_LEXER_UNMATCHED: $handler->_addCall('cdata', array($match), $pos); break; } return array('',$state,''); } function render($mode, &$renderer, $data) { if ($mode == 'xhtml'){ list($align,$state,$pos) = $data; switch ($state) { case DOKU_LEXER_ENTER: if ($align) { $renderer->doc .= '<div style="text-align: '.$align.';">'; } break; case DOKU_LEXER_EXIT : $renderer->doc .= '</div>'; break; } return true; } // end if ($mode == 'xhtml') return false; } } //Setup VIM: ex: et ts=4 enc=utf-8 : ?>
Hi, and welcome to the Dokuwiki community
Some notes on your plugin:
divalign/syntax/left.php, divalign/syntax/right.php, divalign/syntax/center.php, divalign/syntax/justify.php<div> a class name and using a style.css file rather than inline styles.$this->allowedModes values in the constructor. Not all plugins are loaded at that time so you may miss including the syntax modes of other plugins. The ideal method is via the getAllowedTypes() method.— Christopher Smith 2005-09-24 02:20
?> tag in syntax.php. Should work with any hand-coded plugin. Please let me know if this helps. — this comment from Luis Machuca B., a happy DW user (2007-09-29).— Christian Marg 2008-07-17 00:04
An xHTML validation 'fix':
I agree about the xHTML complicate coding. So I 'fixed' it.
In the “render” method, look for this line…
if ($align) { $renderer->doc .= '<div style="text-align: '.$align.';">'; }
Change it to…
if ($align) { $renderer->doc .= '<div class="divalign-' . $align . '">'; }
Also, remove the ?> at the end of the file, it causes trouble down stream.
Then create a style.css file in your divalign plugin folder and drop this code in there:
/* plugin:divalign */
div.divalign-left {
text-align: left;
}
div.divalign-right {
text-align: right;
}
div.divalign-center {
text-align: center;
}
div.divalign-justify {
text-align: justify;
}
/* end plugin:divalign */
The plugin is now xHTML complicate!
— Walter Torres 2008-08-24 23:52