Table of Contents

Smaller Plugin

Note: This plugin will be discontinued. A BBCode plugin will be released soon making different text sizes possible.

Description

With this plugin the syntax of DokuWiki is extended to allow text with smaller font size. The syntax to use this plugin is…

#-Smaller text-#

You can see the plugin in action here.

Plugin

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

<?php
/**
 * Smaller Plugin: enables smaller text font size with syntax #-text-#
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Esther Brunner <esther [at] kaffeehaus [dot] ch>
 */
 
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_smaller extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Esther Brunner',
            'email'  => 'esther@kaffeehaus.ch',
            'date'   => '2005-06-27',
            'name'   => 'Smaller Plugin',
            'desc'   => 'Enables smaller text',
            'url'    => 'http://www.dokuwiki.org/plugin:smaller',
        );
    }
 
    /**
     * Constructor - adds allowed modes
     */
    function syntax_plugin_smaller(){
        global $PARSER_MODES;
        $this->allowedModes = array_merge(
            $PARSER_MODES['formatting'],
            $PARSER_MODES['substition'],
            $PARSER_MODES['disabled']
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'formatting';
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 104;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addEntryPattern('#\-(?=.*\-#)',$mode,'plugin_smaller');
    }
 
    function postConnect() {
      $this->Lexer->addExitPattern('\-#','plugin_smaller');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        return array($match, $state);
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
            if ($data[1] == DOKU_LEXER_ENTER){
                $renderer->doc .= '<span style="font-size:smaller">';
            } else if ($data[1] == DOKU_LEXER_UNMATCHED){
                $renderer->doc .= $renderer->_xmlEntities($data[0]);
            } else if ($data[1] == DOKU_LEXER_EXIT){
                $renderer->doc .= '</span>';
            }
            return true;
        }
        return false;
    }
 
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>
plugin/smaller.txt · Last modified: 2011/06/18 17:02 by ach
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate