-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight.php
52 lines (44 loc) · 1.52 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
<?php
use Herbie\DI;
use Herbie\Hook;
class HighlightPlugin
{
/**
* @return array
*/
public static function install()
{
$config = DI::get('Config');
if ((bool)$config->get('plugins.config.highlight.twig', false)) {
Hook::attach('twigInitialized', ['HighlightPlugin', 'addTwigExtension']);
}
if ((bool)$config->get('plugins.config.highlight.shortcode', true)) {
Hook::attach('shortcodeInitialized', ['HighlightPlugin', 'addShortcode']);
}
}
public static function addTwigExtension($twig)
{
include_once (__DIR__ . '/classes/HighlightExtension.php');
include_once (__DIR__ . '/classes/HighlightNode.php');
include_once (__DIR__ . '/classes/HighlightTokenParser.php');
include_once (__DIR__ . '/vendor/geshi-1.0.8.15/geshi.php');
$twig->addExtension(new HighlightExtension());
}
public static function addShortcode($shortcode)
{
$shortcode->add('code', ['HighlightPlugin', 'codeShortcode']);
}
public static function codeShortcode($options, $content)
{
include_once (__DIR__ . '/vendor/geshi-1.0.8.15/geshi.php');
$name = empty($options[0]) ? 'text' : $options[0];
$geshi = new GeSHi(trim($content), $name);
#$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
return sprintf(
'<div class="highlight highlight-%s">%s</div>',
$name,
$geshi->parse_code()
);
}
}
HighlightPlugin::install();