1<?php
2/**
3 * Plugin bookmark: Creates a bookmark to your document.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Otto Vainio <bookmark.plugin@valjakko.net>
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_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_bookmark extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * return some info
21     */
22    function getInfo(){
23        return array(
24            'author' => 'Otto Vainio',
25            'email'  => 'plugins@valjakko.net',
26            'date'   => '2020-07-14',
27            'name'   => 'Bookmark plugin',
28            'desc'   => 'a bookmark <a name=\'name\'></a>',
29            'url'    => 'http://www.dokuwiki.org/plugin:bookmark',
30        );
31    }
32
33    /**
34     * What kind of syntax are we?
35     */
36    function getType(){
37        return 'substition';
38    }
39
40    function getSort(){ return 357; }
41
42    function connectTo($mode) {
43        $this->Lexer->addSpecialPattern('<BOOKMARK:\w+>',$mode,'plugin_bookmark');
44    }
45
46
47    /**
48     * Handle the match
49     */
50    function handle($match, $state, $pos, Doku_Handler $handler){
51        $match = substr($match,10,-1); //strip <BOOKMARK: from start and > from end
52        return array(strtolower($match));
53    }
54
55    /**
56     * Create output
57     */
58    function render($mode, Doku_Renderer $renderer, $data) {
59        if($mode == 'xhtml'){
60            $renderer->doc .= '<a name="' . $data[0] . '" id="' . $data[0]. '"></a>';
61            return true;
62        }
63        return false;
64    }
65}
66?>
67