-
Notifications
You must be signed in to change notification settings - Fork 4
/
syntax.php
62 lines (54 loc) · 1.94 KB
/
syntax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
*
* @author Szymon Olewniczak
*/
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_randompage2 extends DokuWiki_Syntax_Plugin {
public function getType(){ return 'formatting'; }
public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
public function getSort(){ return 158; }
public function connectTo($mode) { $this->Lexer->addEntryPattern('<randompage_link>(?=.*?</randompage_link>)',$mode,'plugin_randompage2'); }
public function postConnect() { $this->Lexer->addExitPattern('</randompage_link>','plugin_randompage2'); }
/**
* Handle the match
*/
public function handle($match, $state, $pos, Doku_Handler $handler){
switch ($state) {
case DOKU_LEXER_ENTER :
return array($state, '');
case DOKU_LEXER_UNMATCHED : return array($state, $match);
case DOKU_LEXER_EXIT : return array($state, '');
}
return array();
}
/**
* Create output
*/
public function render($mode, Doku_Renderer $renderer, $data) {
global $ID;
// $data is what the function handle() return'ed.
if($mode == 'xhtml'){
/** @var Doku_Renderer_xhtml $renderer */
list($state, $match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER :
$renderer->doc .= '<a href="'.wl($ID, array('do' => 'randompage'), true).'">';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc .= $renderer->_xmlEntities($match);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= '</a>';
break;
}
return true;
}
return false;
}
}