-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsyntax.php
120 lines (96 loc) · 3.03 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* DataTables plugin: Add DataTables support to DokuWiki
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Giuseppe Di Terlizzi <[email protected]>
* @copyright (C) 2015-2016, Giuseppe Di Terlizzi
*/
class syntax_plugin_datatables extends DokuWiki_Syntax_Plugin
{
/** @inheritdoc */
public function getType()
{
return 'container';
}
/** @inheritdoc */
public function getAllowedTypes()
{
return ['container', 'substition'];
}
/** @inheritdoc */
public function getPType()
{
return 'block';
}
/** @inheritdoc */
public function getSort()
{
return 195;
}
/** @inheritdoc */
public function connectTo($mode)
{
$this->Lexer->addEntryPattern(
'<(?:DATATABLES?|datatables?)\b.*?>(?=.*?</(?:DATATABLES?|datatables?)>)',
$mode,
'plugin_datatables'
);
}
/** @inheritdoc */
public function postConnect()
{
$this->Lexer->addExitPattern('</(?:DATATABLES?|datatables?)>', 'plugin_datatables');
}
/** @inheritdoc */
public function handle($match, $state, $pos, Doku_Handler $handler)
{
switch ($state) {
case DOKU_LEXER_UNMATCHED:
case DOKU_LEXER_EXIT:
case DOKU_LEXER_ENTER:
return [$state, $match];
}
return [];
}
/** @inheritdoc */
public function render($mode, Doku_Renderer $renderer, $data)
{
if (empty($data)) return false;
if ($mode !== 'xhtml') return false;
/** @var Doku_Renderer_xhtml $renderer */
list($state, $match) = $data;
switch ($state) {
case DOKU_LEXER_ENTER:
$html5_data = array();
$xml = @simplexml_load_string(str_replace('>', '/>', $match));
if (!is_object($xml)) {
$xml = simplexml_load_string('<foo />');
global $ACT;
if ($ACT == 'preview') {
msg(
sprintf(
'<strong>DataTable Plugin</strong> - Malformed tag (<code>%s</code>).' .
' Please check your code!',
hsc($match)
),
-1
);
}
}
foreach ($xml->attributes() as $key => $value) {
$html5_data[] = sprintf("data-%s='%s'", $key, str_replace("'", "'", (string)$value));
}
$renderer->doc .= sprintf('<div class="dt-wrapper" %s>', implode(' ', $html5_data));
return true;
case DOKU_LEXER_EXIT:
$renderer->doc .= '</div>';
return true;
case DOKU_LEXER_UNMATCHED:
$renderer->doc .= $match;
return true;
}
// should never be reached
return false;
}
}