Зміст

divalign Plugin

Compatible with DokuWiki

No compatibility info given!

plugin Align content left, right, center, or justify

Last updated on
2008-03-29
Provides
Syntax
Conflicts with
divalign2

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to alignment, divalign2, wrap

Tagged with style, typography

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, unobtrusive, 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.

Updated

A new plugin based off this one has been added to the Plugins list. divalign2 implements some of the requests and corrections features under Discussion.

Luis Machuca B. 2009/02/14 05:32

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

Syntax

Align Left:

#;;
This would be aligned left.
#;;

Align Right:

;;#This is aligned right.;;#

Align Center:

;#;
This is aligned center.
;#;

Align Justify:

###Justify me baby!###

Notes

The Code

syntax.php
<?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 :
?>

Discussion

Hi, and welcome to the DokuWiki community :-)

Some notes on your plugin:

Christopher Smith 2005-09-24 02:20

Christian Marg 2008-07-17 00:04

An XHTML validation 'fix':

I agree about the XHTML compliant 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 compliant!

Walter Torres 2008-08-24 23:52

Is the author still working on this plugin? If not, I would like to incorporate the suggestions to the existing code and release a new version, or a fork, if applicable, as well as package for the Plugin Manager. — Luis Machuca B. 2009/01/22 21:13

Feel free to fork and release as you like, but always acknowledge the contribution of the previous authors. To take over the plugin, send an email to the current author/maintainer offering to take it over. If you get no reply, go with your fork. You are free to edit this page to point people at your fork. On the page you create for your fork include a link back to this page. — Christopher Smith 2009/01/25 02:59
OK, so I did wrote the OA (Jason) and never got an answer, so I took the code base, the corrections that made the last update, and some of the suggestions, and cooked up some code. I've forked this plugin into divalign2 which features Plugin Manager option and code separation. I've followed your advice on links back and forth, Chris. So I hope those among you who were waiting for the improvements can check it and comment. I'll see to provide later a complete list of fixes, featurettes and missing corrections. – — Luis Machuca B. 2009/02/14 05:32