-
Notifications
You must be signed in to change notification settings - Fork 1
/
syntax.php
114 lines (91 loc) · 3.29 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
<?php
/**
* Plugin vertical : Configure vertical-align in tables.
*
* Syntax: <vertical head=bottom body=center>table</vertical>
*
* @author Pavel Korotkiy (outdead)
* @license MIT (https://opensource.org/license/mit/)
*/
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_vertical extends DokuWiki_Syntax_Plugin {
function getInfo(){
return array(
'author' => 'outdead',
'email' => 'paul.korotkiy@gmail.com',
'date' => '2023-07-11',
'name' => 'Table Vertical Align',
'desc' => 'Simple plugin to configure vertical-align in tables',
'url' => 'https://github.com/outdead/dokuwiki-plugin-vertical',
);
}
function getType() {
return 'container';
}
function getPType() {
return 'normal';
}
function getAllowedTypes() {
return array('container', 'substition', 'protected', 'disabled', 'formatting', 'paragraphs');
}
function getSort() {
return 137;
}
function connectTo($mode) {
$this->Lexer->addEntryPattern('<vertical[^>]*>(?=.*?</vertical>)', $mode, 'plugin_vertical');
}
function postConnect() {
$this->Lexer->addExitPattern('</vertical>', 'plugin_vertical');
}
function handle($match, $state, $pos, $handler){
switch ($state) {
case DOKU_LEXER_ENTER:
$data = strtolower(trim(substr($match, 9, -1)));
$data = trim($data);
return array($state, $data);
case DOKU_LEXER_UNMATCHED :
return array($state, $match);
case DOKU_LEXER_EXIT :
return array($state, '');
}
return false;
}
function render($mode, $renderer, $indata) {
if ($mode == 'xhtml') {
list($state, $match) = $indata;
switch ($state) {
case DOKU_LEXER_ENTER:
$class = "";
$instructions = explode(" ", htmlspecialchars($match));
foreach ($instructions as $instruction) {
$parts = explode("=", $instruction);
if (count($parts) != 2) {
continue;
}
$position = $parts[0];
$align = $parts[1];
if ($position != "head" && $position != "body") {
continue;
}
if ($align != "top" && $align != "center" && $align != "bottom") {
continue;
}
$class .= " vertical_${align}_${position}";
}
$class = trim($class);
$renderer->doc .= '<div class="'.$class.'">';
break;
case DOKU_LEXER_UNMATCHED :
$renderer->doc .= $renderer->_xmlEntities($match);
break;
case DOKU_LEXER_EXIT :
$renderer->doc .= "</div>";
break;
}
return true;
}
return false;
}
}