-
Notifications
You must be signed in to change notification settings - Fork 2
/
highlight.php
56 lines (44 loc) · 1.58 KB
/
highlight.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
<?php
namespace Plugins\Highlight;
use \Typemill\Plugin;
class Highlight extends Plugin
{
protected $settings;
public static function getSubscribedEvents()
{
return array(
'onSettingsLoaded' => 'onSettingsLoaded',
'onTwigLoaded' => 'onTwigLoaded'
);
}
public function onSettingsLoaded($settings)
{
$this->settings = $settings->getData();
}
public function onTwigLoaded()
{
$highlightSettings = $this->settings['settings']['plugins']['highlight'];
/* add external CSS and JavaScript */
$this->addCSS('/highlight/public/reset.css'); // For theme code css reset
if (isset($highlightSettings['theme'])) {
$this->addCSS('/highlight/public/'.$highlightSettings['theme'].'.css');
} else {
$this->addCSS('/highlight/public/default.css');
}
$this->addJS('/highlight/public/highlight.pack.js');
$this->addJS('/highlight/public/highlightjs-line-numbers.min.js');
if (isset($highlightSettings['copyButton']) && $highlightSettings['copyButton'] == 'true') {
/* initialize copy badge
https://github.com/arronhunt/highlightjs-copy
*/
$this->addCss('/highlight/public/highlightjs-copy.min.css');
$this->addJS('/highlight/public/highlightjs-copy.min.js');
$this->addInlineJs('hljs.addPlugin(new CopyButtonPlugin());');
}
/* initialize the script */
$this->addInlineJS('hljs.highlightAll();');
if (isset($highlightSettings['lineNumber']) && $highlightSettings['lineNumber'] == 'true') {
$this->addInlineJS('hljs.initLineNumbersOnLoad({ singleLine: true });');
}
}
}