1<?php
2/**
3 * DokuPrism Plugin - Code highlighter using [prismjs.com] library
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Adam Mnemnonic <adam85mn@gmail.com>
7 */
8if (!defined("DOKU_INC"))  die();
9
10class action_plugin_dokuprism extends DokuWiki_Action_Plugin {
11
12    function register(Doku_Event_Handler $controller) {
13        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'metaheaders'); // https://www.dokuwiki.org/devel:event:tpl_metaheader_output
14        $controller->register_hook('TOOLBAR_DEFINE'       , 'AFTER' , $this, 'codeLanguageToolbar', array());
15    }
16
17
18    function metaheaders(&$event, $param) {
19        // Adding a stylesheet
20        $event->data["link"][] = array (
21            "type" => "text/css",
22            "rel"  => "stylesheet",
23            "href" => DOKU_BASE."lib/plugins/dokuprism/prism/prism.css",
24        );
25        // Adding javascript
26        $event->data["script"][] = array (
27            "type"  => "text/javascript",
28            "src"   => DOKU_BASE."lib/plugins/dokuprism/prism/prism.js",
29            "_data" => "",
30        );
31        return true;
32    }
33
34    function codeLanguageToolbar(Doku_Event $event, $param) {
35        $languages  = explode('|',$this->getConf('lanuages_list'));
36        $sub_buttons = array();
37        foreach($languages as $lang) {
38            $sub_buttons[] = array(
39                            'type'   =>  'format',
40                            'title'  =>  $lang,
41                            'open'   =>  "<code $lang>\n",
42                            'icon'   =>  DOKU_BASE."lib/plugins/dokuprism/svg.php?label=$lang",
43                            'close'  =>  "\n</code>");
44        }
45
46        $button = array(
47                'type' => 'picker',
48                'title' => $this->getLang('button_title'),
49                'icon' => DOKU_REL.'lib/plugins/dokuprism/code.png',
50                'list' => $sub_buttons
51        );
52        $event->data[] = $button;
53    }
54}
55
56