It's better when it's simple

User Tools

Site Tools


This is an old revision of the document!

class plugin

Compatible with DokuWiki

No compatibility info given!

plugin Simple plugin to add a class to a content

Last updated on

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

The following security issue was reported for this extension: XSS vulnerability allows arbitrary JavaScript insertion. Author informed on 2009-09-15.

It is not recommended to use this extension until this issue was fixed. Extension authors should read the plugin security guidelines

Similar to box

Tagged with boxes, class, css, notes, styles

By Janusz


This is a simply plugin to add a class to a content. It prevents to use

<html></p><div class="myStyleClass"><p></html>
This is my content.


Just use this syntax and change “myStyleClass” by your class.

<class myStyleClass>This is my content.</class>

Source code and installation

Put the following PHP file in /lib/plugins/class/syntax.php

 * Plugin class : add a class to a content
 * Syntax: <class myStyleClass>content</class>
 * @author     Janusz <>
 * @license    GPL 2 (
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
class syntax_plugin_class extends DokuWiki_Syntax_Plugin {
    * Get an associative array with plugin info.
    function getInfo(){
        return array(
            'author' => 'Janusz',
            'email'  => '',
            'date'   => '2008-12-15',
            'name'   => 'class Plugin',
            'desc'   => 'Simple plugin to add a class to a content',
            'url'    => '',
    function getType(){ return 'container'; }
    function getPType(){ return 'normal'; }
    function getAllowedTypes() { 
        return array('container','substition','protected','disabled','formatting','paragraphs');
    // must return a number lower than returned by native 'code' mode (200)
    function getSort(){ return 158; }
     * Connect pattern to lexer
    function connectTo($mode) {       
    function postConnect() {
     * Handle the match
    function handle($match, $state, $pos, &$handler){
        switch ($state) {
            case DOKU_LEXER_ENTER:
                $data = strtolower(trim(substr($match,6,-1)));
                return array($state, $data);
            case DOKU_LEXER_UNMATCHED : 
                return array($state, $match);
            case DOKU_LEXER_EXIT :
                return array($state, '');
        return false;
     * output
    function render($mode, &$renderer, $indata) {
        if($mode == 'xhtml'){
            list($state, $match) = $indata;
            switch ($state) {
            case DOKU_LEXER_ENTER :      
                $renderer->doc .= '</p><div class="'.$match.'"><p>';
              case DOKU_LEXER_UNMATCHED : 
                $renderer->doc .= $renderer->_xmlEntities($match);
              case DOKU_LEXER_EXIT :
                $renderer->doc .= "</p></div><p>";
            return true;
        return false;
//Setup VIM: ex: et ts=4 enc=utf-8 :


  • 2008-12-15 : Change the getType() to convert the inside text in HTML code.
  • 2008-12-08 : First version.


plugin/class.1253041528.txt.gz · Last modified: 2009-09-15 21:05 by HåkanS