Sample Renderer Plugin to replace standard xhtml renderer

Note:

  • the canRender() method. This tells DW configuration manager that this plugin is capable of replacing a DokuWiki core renderer and the format of the renderer it can replace. At present only one format is supported, xhtml.
  • plugins are only instantiated once. DW core renderers are instantiated every time they are used. Its necessary to implement the reset() function to properly reset the renderer for reuse.

./dokuwiki/lib/plugins/xbr.php

<?php
/**
 * Render Plugin for XHTML output with preserved linebreaks
 *
 * @author Chris Smith <chris@jalakai.co.uk>
 */
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
require_once DOKU_INC . 'inc/parser/xhtml.php';
 
/**
 * The Renderer
 */
class renderer_plugin_xbr extends Doku_Renderer_xhtml {
 
    /**
     * return some info
     */
    function getInfo(){
      return array(
        'author' => 'Christopher Smith',
        'email'  => 'chris@jalakai.co.uk',
        'date'   => '2008-03-09',
        'name'   => 'XBR',
        'desc'   => 'XHTML renderer with line break preservation.',
        'url'    => 'http://wiki.splitbrain.org/plugin:xbr',
      );
    }
 
    function canRender($format) {
      return ($format=='xhtml');
    }
 
    function reset() {
       $this->doc = '';
       $this->footnotes = array();
       $this->lastsec = 0;
       $this->store = '';
       $this->_counter = array();
    }
 
    function cdata($text) {
        $this->doc .= str_replace("\n",'<br />',$this->_xmlEntities($text));
    }
 
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :

 
tutorials/renderer.txt · Last modified: 2008/05/08 00:42 by chris
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki