-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsyntax.php
More file actions
executable file
·145 lines (127 loc) · 3.49 KB
/
Copy pathsyntax.php
File metadata and controls
executable file
·145 lines (127 loc) · 3.49 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
if(!defined('DOKU_REL')) define('DOKU_REL', '/dokuwiki/');
/**
* Auto-Tooltip DokuWiki plugin
*
* @license MIT
* @author Eli Fenton
*/
class syntax_plugin_autotooltip extends DokuWiki_Syntax_Plugin {
/** @type helper_plugin_autotooltip m_helper */
private $m_helper;
public function __construct() {
$this->m_helper = plugin_load('helper', 'autotooltip');
}
/**
* @return string
*/
function getType() {
return 'substition';
}
/**
* @return string
*/
function getPType() {
return 'normal';
}
/**
* @return int
*/
function getSort() {
return 165;
}
/**
* @param $mode
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('<autott[^>]*>(?:[\s\S]*?</autott>)', $mode, 'plugin_autotooltip');
}
/**
* @param string $match - The match from addEntryPattern.
* @param int $state - The DokuWiki event state.
* @param int $pos - The position in the full text.
* @param Doku_Handler $handler
* @return array|string
*/
function handle($match, $state, $pos, Doku_Handler $handler) {
$inner = [];
$classes = [];
$pageid = [];
preg_match('/<autott\s*([^>]+?)\s*>/', $match, $classes);
preg_match('/<autott[^>]*>\s*([\s\S]+)\s*<\/autott>/', $match, $inner);
if (count($inner) < 1) {
return 'ERROR';
}
$inner = $inner[1];
$data = [];
$data['classes'] = count($classes) >= 1 ? $classes[1] : '';
if (strchr($inner, '<') === FALSE) {
$parts = array_map(function($s) {return trim($s);}, explode('|', $inner));
// <autott class1 class2>wikilink|desc</autott>
if (cleanID($parts[0]) == $parts[0]) {
$data['pageid'] = $parts[0];
if (count($parts) > 1) {
$data['content'] = $parts[1];
}
return $data;
}
}
// <autott class1 class2><content></content><tip></tip><title></title><pageid></pageid></autott>
else {
$content = [];
$tip = [];
$title = [];
$link = [];
preg_match('/<content>([\s\S]+)<\/content>/', $inner, $content);
preg_match('/<tip>([\s\S]+)<\/tip>/', $inner, $tip);
preg_match('/<title>([\s\S]+)<\/title>/', $inner, $title);
preg_match('/<link>([\s\S]+)<\/link>/', $inner, $link);
if (count($content) >= 1 || count($pageid) >= 1) {
$data['content'] = $content[1] ?? '';
$data['pageid'] = $pageid[1] ?? null;
$data['tip'] = $tip[1] ?? null;
$data['title'] = $title[1] ?? null;
$data['link'] = $link[1] ?? null;
return $data;
}
}
return 'ERROR';
}
/**
* @param string $mode
* @param Doku_Renderer $renderer
* @param array|string $data - Data from handle()
* @return bool|void
*/
function render($mode, Doku_Renderer $renderer, $data) {
if ($mode == 'xhtml' && !is_a($renderer, 'renderer_plugin_dw2pdf')) {
if ($data == 'ERROR') {
msg('Error: Invalid instantiation of autotooltip plugin');
}
else if (isset($data['pageid'])) {
$renderer->doc .= $this->m_helper->forWikilink($data['pageid'], $data['content']??'', '', $data['classes']??'');
}
else {
$renderer->doc .= $this->m_helper->forText(
$data['content']??'',
$data['tip']??'',
$data['title']??'',
'', // preTitle
$data['classes']??'',
'', // textClasses
$data['link']??''
);
}
}
else {
if ($data == 'ERROR') {
$renderer->doc .= 'Error: Invalid instantiation of autotooltip plugin';
}
else {
$renderer->doc .= $data['content'] ?? '';
}
}
}
}