xref: /dokuwiki/lib/plugins/syntax.php (revision 896a5c22ad2bfe6b07b70324ed639fbaf9a20869)
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     * General Info
21     *
22     * Needs to return a associative array with the following values:
23     *
24     * author - Author of the plugin
25     * email  - Email address to contact the author
26     * date   - Last modified date of the plugin in YYYY-MM-DD format
27     * name   - Name of the plugin
28     * desc   - Short description of the plugin (Text only)
29     * url    - Website with more information on the plugin (eg. syntax description)
30     */
31    function getInfo(){
32        trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING);
33    }
34
35    /**
36     * Syntax Type
37     *
38     * Needs to return one of the mode types defined in $PARSER_MODES in parser.php
39     */
40    function getType(){
41        trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING);
42    }
43
44    /**
45     * Paragraph Type
46     *
47     * Defines how this syntax is handled regarding paragraphs. This is important
48     * for correct XHTML nesting. Should return one of the following:
49     *
50     * 'normal' - The plugin can be used inside paragraphs
51     * 'block'  - Open paragraphs need to be closed before plugin output
52     * 'stack'  - Special case. Plugin wraps other paragraphs.
53     *
54     * @see Doku_Handler_Block
55     */
56    function getPType(){
57        return 'normal';
58    }
59
60    /**
61     * Handler to prepare matched data for the rendering process
62     *
63     * Usually you should only need the $match param.
64     *
65     * @param   $match   string    The text matched by the patterns
66     * @param   $state   int       The lexer state for the match
67     * @param   $pos     int       The character position of the matched text
68     * @param   $handler ref       Reference to the Doku_Handler object
69     * @return  array              Return an array with all data you want to use in render
70     */
71    function handle($match, $state, $pos, &$handler){
72        trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING);
73    }
74
75    /**
76     * Handles the actual output creation.
77     *
78     * The function should always check for the given mode and return false
79     * when a mode isn't supported.
80     *
81     * $renderer contains a reference to the renderer object which is
82     * currently handling the rendering. You need to use it for writing
83     * the output. How this is done depends on the renderer used (specified
84     * by $mode
85     *
86     * The contents of the $data array depends on what the handler() function above
87     * created
88     *
89     * @param   $mode     string   current Rendermode
90     * @param   $renderer ref      reference to the current renderer object
91     * @param   $data     array    data created by handler()
92     * @return  boolean            rendered correctly?
93     */
94    function render($mode, &$renderer, $data) {
95        trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING);
96    }
97
98}
99
100//Setup VIM: ex: et ts=4 enc=utf-8 :
101