|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace S1SYPHOS\HIGHLIGHT; |
| 3 | +namespace Kirby\Plugins\Highlight; |
4 | 4 |
|
5 | 5 | use kirbytext; |
6 | 6 | use Highlight\Highlighter; |
7 | 7 | use c; |
8 | 8 |
|
9 | | -class Settings { |
10 | | - |
11 | | - /** |
12 | | - * Returns the default options for `kirby-highlight` |
13 | | - * |
14 | | - * @return array |
15 | | - */ |
16 | | - |
17 | | - public static function __callStatic($name, $args) { |
18 | | - |
19 | | - // Set prefix |
20 | | - $prefix = 'plugin.kirby-highlight.'; |
21 | | - |
22 | | - // Set config names and fallbacks as settings |
23 | | - $settings = [ |
24 | | - 'languages' => ['html', 'php'], // Languages to be auto-detected |
25 | | - 'escaping' => false, // Enables / disables character escaping |
26 | | - ]; |
27 | | - |
28 | | - // If config settings exist, return the config with fallback |
29 | | - if(isset($settings) && array_key_exists($name, $settings)) { |
30 | | - return c::get($prefix . $name, $settings[$name]); |
31 | | - } |
32 | | - } |
33 | | -} |
34 | | - |
35 | 9 | kirbytext::$post[] = function($kirbytext, $value) { |
36 | 10 |
|
37 | 11 | // Pattern to be matched when parsing kirbytext() (everything between <code> and </code>) |
38 | 12 | $pattern = '~<code[^>]*>\K.*(?=</code>)~Uis'; |
39 | 13 |
|
40 | 14 | return preg_replace_callback($pattern, function($match) { |
41 | 15 |
|
42 | | - // Instantiating highlighter & passing array of languages |
| 16 | + // Instantiating Highlighter & passing array of languages to be auto-detected |
43 | 17 | $highlighter = new Highlighter(); |
44 | | - $highlighter->setAutodetectLanguages(settings::languages()); |
| 18 | + $highlighter->setAutodetectLanguages(c::get('plugin.kirby-highlight.languages', ['html', 'php'])); |
45 | 19 |
|
46 | 20 | // Optionally escaping each match .. |
47 | | - $input = settings::escaping() ? $match[0] : htmlspecialchars_decode($match[0]); |
| 21 | + $input = c::get('plugin.kirby-highlight.escaping', false) ? $match[0] : htmlspecialchars_decode($match[0]); |
48 | 22 |
|
49 | 23 | // .. but always highlighting & outputting it |
50 | 24 | $highlightedMatch = $highlighter->highlightAuto($input); |
|
0 commit comments