-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsyntax.php
More file actions
77 lines (60 loc) · 1.86 KB
/
Copy pathsyntax.php
File metadata and controls
77 lines (60 loc) · 1.86 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
<?php
/**
* Plugin TableWidth
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Mykola Ostrovskyy <dwpforge@gmail.com>
*/
class syntax_plugin_tablewidth extends DokuWiki_Syntax_Plugin {
private $mode;
public function __construct() {
$this->mode = substr(get_class($this), 7);
}
public function getType() {
return 'container';
}
public function getPType() {
return 'block';
}
public function getSort() {
return 5;
}
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('[\t ]*\n\|<[^\n]+?>\|(?=\s*?\n[|^])', $mode, $this->mode);
}
public function handle($match, $state, $pos, Doku_Handler $handler) {
if ($state == DOKU_LEXER_SPECIAL) {
if (preg_match('/\|<(\s*)(.+?)(\s*)>\|/', $match, $match) != 1) {
return false;
}
// Sanitize the width spec to avoid injection of HTML tags and extra CSS declarations
$widthSpec = str_replace(array('<', '>', ';', '"'), '', $match[2]);
$tableAlign = $this->getTableAlign($match[1], $match[3]);
return array($tableAlign . $widthSpec);
}
return false;
}
public function render($mode, Doku_Renderer $renderer, $data) {
if ($mode == 'xhtml') {
$renderer->doc .= '<!-- table-width ' . $data[0] . ' -->' . DOKU_LF;
return true;
}
return false;
}
private function getTableAlign($paddingLeft, $paddingRight) {
if (strlen($paddingLeft) > 1) {
if (strlen($paddingRight) > 1) {
return '>< ';
}
else {
return '> ';
}
}
else {
if (strlen($paddingRight) > 1) {
return '< ';
}
}
return '';
}
}