-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.php
57 lines (50 loc) · 1.39 KB
/
renderer.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
<?php
// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
/**
* DokuWiki Plugin dbquery (Renderer Component)
*
* Extracts code blocks from pages and returns them as JSON
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
class renderer_plugin_dbquery extends \Doku_Renderer
{
protected $codeBlocks = [];
protected $lastHeader = '';
/** @inheritDoc */
public function getFormat()
{
return 'dbquery';
}
/** @inheritDoc */
public function header($text, $level, $pos)
{
$this->lastHeader = $text;
}
/** @inheritDoc */
public function code($text, $lang = null, $file = null)
{
if (!isset($this->codeBlocks['_'])) {
// first code block is always the SQL query
$this->codeBlocks['_'] = trim($text);
} else {
// all other code blocks are treated as HTML named by their header
$this->codeBlocks[$this->lastHeader] = trim($text);
}
}
/** @inheritdoc */
public function document_start()
{
parent::document_start();
$this->info['dbquery']['transpose'] = false;
}
/** @inheritDoc */
public function document_end()
{
$this->doc = json_encode([
'codeblocks' => $this->codeBlocks,
'macros' => $this->info['dbquery'],
]);
}
}