xref: /plugin/mermaid/action.php (revision 46a60b4f15d119956be60b60dc3d5545f8ec859f)
1<?php
2/**
3 * DokuWiki Plugin mermaid (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Robert Weinmeister <develop@weinmeister.org>
7 */
8
9class action_plugin_mermaid extends \dokuwiki\Extension\ActionPlugin
10{
11    /** @inheritDoc */
12    public function register(Doku_Event_Handler $controller)
13    {
14        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'load');
15    }
16
17    public function load(Doku_Event $event, $param)
18    {
19        $event->data['script'][] = array
20        (
21            'type'    => 'text/javascript',
22            'charset' => 'utf-8',
23            'src' => DOKU_BASE."lib/plugins/mermaid/mermaid.min.js"
24		);
25
26        $event->data['link'][] = array
27        (
28            'rel'     => 'stylesheet',
29            'type'    => 'text/css',
30            'href'    => DOKU_BASE."lib/plugins/mermaid/mermaid.css",
31        );
32
33        // Can be changed for debugging
34        // https://mermaid.js.org/config/directives.html#changing-loglevel-via-directive
35        $event->data['script'][] = array
36        (
37            'type'    => 'text/javascript',
38            'charset' => 'utf-8',
39            '_data'   => 'mermaid.initialize({logLevel: "error"});'
40        );
41    }
42}