Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 18d6041

Browse files
committed
Applying PSR2 coding style
1 parent a89d7b7 commit 18d6041

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

core/syntax_highlight.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@
66
use Highlight\Highlighter;
77
use c;
88

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';
1012

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) {
1314

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']));
1518

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]);
1921

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;
3025

26+
return $highlightedMatch;
27+
}, $value);
3128
};

kirby-highlight.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
<?php
2-
3-
/**
4-
* Kirby Highlight - Themeable server-side syntax highlighting for Kirby
5-
*
6-
* @package Kirby CMS
7-
* @author S1SYPHOS <hello@twobrain.io>
8-
* @link http://twobrain.io
9-
* @version 0.5.0
10-
* @license MIT
11-
*/
12-
13-
if(!c::get('plugin.kirby-highlight')) return;
14-
15-
// Initialising composer's autoloader
16-
require_once __DIR__ . DS . 'vendor' . DS . 'autoload.php';
17-
18-
// Loading settings & core
19-
require_once __DIR__ . DS . 'core' . DS . 'syntax_highlight.php';
1+
<?php
2+
3+
/**
4+
* Kirby Highlight - Themeable server-side syntax highlighting for Kirby
5+
*
6+
* @package Kirby CMS
7+
* @author S1SYPHOS <hello@twobrain.io>
8+
* @link http://twobrain.io
9+
* @version 0.5.0
10+
* @license MIT
11+
*/
12+
13+
if (c::get('plugin.kirby-highlight', true)) {
14+
// Initialising composer's autoloader
15+
require_once __DIR__ . DS . 'vendor' . DS . 'autoload.php';
16+
17+
// Loading settings & core
18+
require_once __DIR__ . DS . 'core' . DS . 'syntax_highlight.php';
19+
}

0 commit comments

Comments
 (0)