outdent plugin

experimental

This plugin extends Dokuwiki syntax to enable the removal of one level of section indenting.

In native DokuWiki, all the content between headings is included in a section. The indentation for a particular section corresponds to the heading it follows. Dokuwiki doesn't provide a way to finish a section and move back to the indentation level of the previous section - at least not without using another heading. This plugins makes that possible.

e.g.

HEADING 1
level 1 section content
  HEADING 2
  level 2 section content
    HEADING 3
    level 3 section content
  level 2 section content
    HEADING 3
level 1 section content

Syntax

==

The two equals signs must be on their own line.

See the page in action here

Installation

Plugin sources: zip format (2k), tar.gz format (1k), darcs repository

If your wiki uses either the plugin manager or the darcs plugin you can use them with the links above to install the plugin.

To install the plugin manually, download the source to your plugin folder, lib/plugins and extract its contents. That will create a new plugin folder, lib/plugins/outdent, and install the plugin.

The folder will contain:

syntax.php                            ; plugin script

The plugin is now installed.

Configuration

The plugin has no configuration settings.

Details

The plugin consists one file, the plugin script syntax.php.

syntax.php

<?php
/**
 * Plugin Outdent: Removes one level of indenting.
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Christopher Smith <chris@jalakai.co.uk>
 */
 
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_outdent extends DokuWiki_Syntax_Plugin {
 
    function getInfo(){
      return array(
        'author' => 'Christopher Smith',
        'email'  => 'chris@jalakai.co.uk',
        'date'   => '2005-09-30',
        'name'   => 'Outdent Plugin',
        'desc'   => 'Remove one level of indenting
                     Syntax: ==',
        'url'    => 'http://wiki.splitbrain.org/plugin:unindent',
      );
    }
 
    function getType() { return 'baseonly'; }
    function getSort() { return 50; }                       /* same as header */
 
    function connectTo($mode) { 
        $this->Lexer->addSpecialPattern('\n[ \t]*==[ \t]*(?=\n)',$mode,'plugin_outdent'); 
    }
 
    function handle($match, $state, $pos, &$handler){
      $level=0;
      if ($state == DOKU_LEXER_SPECIAL) {
        $level = $this->_getLevel($handler->calls);
        if ($level > 1) {
            $handler->_addCall('section_close', array(), $pos);
            $handler->_addCall('section_open', array($level-1), $pos);    
        }        
      }
 
      return NULL;
    }
 
    function render($mode, &$renderer, $data) {
 
      return false;
    }
 
    function _getLevel(&$calls) {
 
      for ($i=count($calls); $i >= 0; $i--) {
          if ($calls[$i][0] == 'header') return $calls[$i][1][1];
        if ($calls[$i][0] == 'section_open') return $calls[$i][1][0];
      }
 
      return 0;
    }
}

Revision History

2005-09-30
Released.

To Do

Bugs

Discussion

 
tutorials/outdent.txt · Last modified: 2010/05/31 16:21 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki