forked from royallthefourth/CodeHighlightBolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtension.php
More file actions
52 lines (34 loc) · 1.1 KB
/
Extension.php
File metadata and controls
52 lines (34 loc) · 1.1 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
<?php
// Code Highlight Extension for Bolt, by Royall Spence (original version by Mespeche)
namespace Bolt\Extension\royallthefourth\CodeHighlightBolt;
class Extension extends \Bolt\BaseExtension
{
public function getName()
{
return "Code Highlight";
}
/**
* Initialize Code Highlight. Called during bootstrap phase.
*/
function initialize()
{
// Add javascript file
$this->addJavascript("assets/highlightjs/highlight.pack.min.js");
// Add CSS file
$theme = $this->config['theme'];
$this->addCSS("assets/highlightjs/styles/" . $theme . ".css");
$snippet = "<script>hljs.initHighlightingOnLoad();</script>";
// Add string snippet to endofbody
$this->addSnippet('endofbody', $snippet);
// Initialize the Twig function
$this->addTwigFunction('highlight', 'twigHighlight');
}
/**
* Twig function {{ highlight() }} in Code Highlight extension.
*/
function twigHighlight($name="")
{
$html = $name;
return new \Twig_Markup($html, 'UTF-8');
}
}