|
6 | 6 | use Highlight\Highlighter; |
7 | 7 | use c; |
8 | 8 |
|
9 | | -kirbytext::$post[] = function($kirbytext, $value) { |
| 9 | +kirbytext::$post[] = function ($kirbytext, $value) { |
| 10 | + // Pattern to be matched when parsing kirbytext() (everything between <code> and </code>) |
| 11 | + $pattern = '~<code[^>]*>\K.*(?=</code>)~Uis'; |
10 | 12 |
|
11 | | - // Pattern to be matched when parsing kirbytext() (everything between <code> and </code>) |
12 | | - $pattern = '~<code[^>]*>\K.*(?=</code>)~Uis'; |
| 13 | + return preg_replace_callback($pattern, function ($match) { |
13 | 14 |
|
14 | | - return preg_replace_callback($pattern, function($match) { |
| 15 | + // Instantiating Highlighter & passing array of languages to be auto-detected |
| 16 | + $highlighter = new Highlighter(); |
| 17 | + $highlighter->setAutodetectLanguages(c::get('plugin.kirby-highlight.languages', ['html', 'php'])); |
15 | 18 |
|
16 | | - // Instantiating Highlighter & passing array of languages to be auto-detected |
17 | | - $highlighter = new Highlighter(); |
18 | | - $highlighter->setAutodetectLanguages(c::get('plugin.kirby-highlight.languages', ['html', 'php'])); |
| 19 | + // Optionally escaping each match .. |
| 20 | + $input = c::get('plugin.kirby-highlight.escaping', false) ? $match[0] : htmlspecialchars_decode($match[0]); |
19 | 21 |
|
20 | | - // Optionally escaping each match .. |
21 | | - $input = c::get('plugin.kirby-highlight.escaping', false) ? $match[0] : htmlspecialchars_decode($match[0]); |
22 | | - |
23 | | - // .. but always highlighting & outputting it |
24 | | - $highlightedMatch = $highlighter->highlightAuto($input); |
25 | | - $highlightedMatch = $highlightedMatch->value; |
26 | | - |
27 | | - return $highlightedMatch; |
28 | | - |
29 | | - }, $value); |
| 22 | + // .. but always highlighting & outputting it |
| 23 | + $highlightedMatch = $highlighter->highlightAuto($input); |
| 24 | + $highlightedMatch = $highlightedMatch->value; |
30 | 25 |
|
| 26 | + return $highlightedMatch; |
| 27 | + }, $value); |
31 | 28 | }; |
0 commit comments