-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.php
More file actions
60 lines (50 loc) · 1.61 KB
/
syntax.php
File metadata and controls
60 lines (50 loc) · 1.61 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
<?php
if(!defined('DOKU_INC')) die();
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_marginnotes extends DokuWiki_Syntax_Plugin {
public function getPluginName() {
return $this->getInfo()['base'];
}
public function connectTo($mode) {
$this->Lexer->addEntryPattern('<mnote>(?=.*</mnote>)', $mode, 'plugin_' . $this->getPluginName());
}
public function postConnect() {
$this->Lexer->addExitPattern('</mnote>', 'plugin_' . $this->getPluginName());
}
function getSort() {
return 69;
}
function getType() {
return 'protected';
}
function getPType(){
return 'block';
}
function handle($match, $state, $pos, Doku_Handler $handler) {
switch ($state) {
case DOKU_LEXER_UNMATCHED:
return [
'state' => $state,
'match' => $match,
'pos' => $pos - strlen('<mnote>'),
];
}
return [
'state' => $state
];
}
function render($mode, Doku_Renderer $renderer, $data) {
switch ($data['state']) {
case DOKU_LEXER_ENTER:
$renderer->doc .= '<div class="marginnote">';
break;
case DOKU_LEXER_UNMATCHED:
$renderer->doc .= '<span>' . $data['match'] . '</span>';
break;
case DOKU_LEXER_EXIT:
$renderer->doc .= '</div>';
break;
}
return true;
}
}