xref: /dokuwiki/lib/plugins/syntax.php (revision af146da051337e3c5821b6e482d5121816294c67)
1<?php
2/**
3 * Syntax Plugin Prototype
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_INC.'inc/parser/parser.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode {
18
19    /**
20     * Syntax Type
21     *
22     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
23     */
24    function getType(){
25        trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING);
26    }
27
28    /**
29     * Paragraph Type
30     *
31     * Defines how this syntax is handled regarding paragraphs. This is important
32     * for correct XHTML nesting. Should return one of the following:
33     *
34     * 'normal' - The plugin can be used inside paragraphs
35     * 'block'  - Open paragraphs need to be closed before plugin output
36     * 'stack'  - Special case. Plugin wraps other paragraphs.
37     *
38     * @see Doku_Handler_Block
39     */
40    function getPType(){
41        return 'normal';
42    }
43
44    /**
45     * Handler to prepare matched data for the rendering process
46     *
47     * Usually you should only need the $match param.
48     *
49     * @param   $match   string    The text matched by the patterns
50     * @param   $state   int       The lexer state for the match
51     * @param   $pos     int       The character position of the matched text
52     * @param   $handler ref       Reference to the Doku_Handler object
53     * @return  array              Return an array with all data you want to use in render
54     */
55    function handle($match, $state, $pos, &$handler){
56        trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING);
57    }
58
59    /**
60     * Handles the actual output creation.
61     *
62     * The function should always check for the given mode and return false
63     * when a mode isn't supported.
64     *
65     * $renderer contains a reference to the renderer object which is
66     * currently handling the rendering. You need to use it for writing
67     * the output. How this is done depends on the renderer used (specified
68     * by $mode
69     *
70     * The contents of the $data array depends on what the handler() function above
71     * created
72     *
73     * @param   $mode     string   current Rendermode
74     * @param   $renderer ref      reference to the current renderer object
75     * @param   $data     array    data created by handler()
76     * @return  boolean            rendered correctly?
77     */
78    function render($mode, &$renderer, $data) {
79        trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING);
80    }
81
82}
83
84//Setup VIM: ex: et ts=4 enc=utf-8 :
85