forked from condero/dokuwiki-toggle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.php
More file actions
98 lines (89 loc) · 2.22 KB
/
syntax.php
File metadata and controls
98 lines (89 loc) · 2.22 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Toggle Plugin: toggles visibility of texts with syntax <TOGGLE></TOGGLE>
*
* @license GPL3 (http://www.gnu.org/licenses/gpl.html)
* @author condero Aktiengesellschaft <info@condero.com>
*/
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_toggle extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'condero Aktiengesellschaft',
'email' => 'info@condero.com',
'date' => '2017-04-07',
'name' => 'Toggle Plugin',
'desc' => 'This plugin toggles visibility of text.',
'url' => 'http://www.dokuwiki.org/plugin:toggle',
);
}
/**
* What kind of syntax are we?
*/
function getType(){
return 'protected';
}
/**
* Where to sort in?
*/
function getSort(){
return 202;
}
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addEntryPattern('<TOGGLE>(?=.*?</TOGGLE>)',$mode,'plugin_toggle');
}
function postConnect() {
$this->Lexer->addExitPattern('</TOGGLE>','plugin_toggle');
}
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
switch ($state) {
case DOKU_LEXER_ENTER :
return array($state, '');
break;
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
break;
case DOKU_LEXER_EXIT :
return array($state, '');
break;
}
return array();
}
/**
* Create output
*/
function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
list($state, $match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER :
$renderer->doc.= '';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc.= '<span class="plugin_toggle" style="padding:2px; border:1px solid; cursor:pointer;" onclick="javascript:this.innerHTML=this.innerHTML==\'********\'?this.dataset.text:\'********\';" data-text="'.$match.'">********</span>';
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= "";
break;
}
return true;
}
return false;
}
}
?>