Server-side code highlighting for KirbyText.
Built upon highlight.php which itself is a port of highlight.js. Features include:
- π³οΈβπ Supports 189 languages
- π« 94 styles available
- β³οΈ Automatic language detection
- Kirby 3
- PHP 7.4+
Download and copy this repository to /site/plugins/kirby-highlight
.
git submodule add https://github.com/johannschopplich/kirby-highlight.git site/plugins/kirby-highlight
composer require johannschopplich/kirby-highlight
Create a code block in your KirbyText field and optionally set the code language:
```css
.currentColor {
color: currentColor;
}
```
Which outputs:
<pre class="hljs"><code><span class="hljs-selector-class">.currentColor</span> {
<span class="hljs-attribute">color</span>: currentColor;
}</code></pre>
The syntax highlighting functionality can be changed. You can choose between two highlighting modes:
- Explicit mode (default)
- Automatic language detection mode (opt-in)
In explicit mode, you have to define which language the code block is. Otherwise highlighting will be skipped.
Alternatively you can use the automatic detection mode, which highlights your code with the language the library thinks is best. It is highly recommended you explicitly choose the language or limit the number of languages to automatically detect from. This reduces the number of inaccuracies and skips this extremely inefficient selection process.
To enable automatic language detection, set:
kirby-extended.highlight.autodetect
totrue
kirby-extended.highlight.languages
to an array of names from which languages should be chosen
Option | Default | Description |
---|---|---|
kirby-extended.highlight.class |
hljs |
Style class for Highlight to be added to the pre element. |
kirby-extended.highlight.autodetect |
false |
Indicates if the library should define which language thinks is best. Only applies when no language was set on the KirbyText code block. |
kirby-extended.highlight.languages |
[] |
Array of language names to be auto detected. If empty, every language will be |
- Geert Bergman and contributors for the awesome highlight.php port
- Martin Folkers for his Kirby Highlight plugin which built the base of this package