just recently I hacked together a plugin that highlights code snippets server-side.
But … why?
Why not? When I found out about Geert Bergman’s
highlight.php library (a PHP port of highlight.js), I decided to go for it:
- Extensive: currently 141 supported languages
- Customisable: 65 different styles included (more coming soon)
Use one of the following methods to install & use
If you know your way around Git, you can download this plugin as a submodule:
git submodule add https://github.com/S1SYPHOS/kirby-highlight.git site/plugins/kirby-highlight
Clone or download
Activate the plugin
Activate the plugin with the following line in your
Now proper classes are added to your code snippets, making them ‘themeable’. If you want to activate
kirby-highlight only on specific domains, read about multi-environment setups.
kirby-highlight options to suit your needs:
||Defines languages to be auto-detected (currently 141 languages are supported).|
To apply one of the many available stylesheets, just include it in your
<head> element using the
<?php echo css('assets/plugins/kirby-highlight/css/zenburn.css') ?>
Note: Most of the included themes depend some way or another on the class
.hljs to be added to the code’s container!
In order to make sure the theme gets applied as planned, any of these methods will work:
- Simply use
kirby-pepto put it there:
c::set('plugin.kirby-pep.code_class', 'language-%s hljs');
[class^="language-"]in the included stylesheet
- Copy it to your
assets/cssdirectory and modify it
- Include the styles in your own workflow
Adding an unsupported language breaks
kirbytext() parsing of the code snippet in question. Always be sure to only include valid languages.
You can find the plugin on Github. It’s not much, but it’s something. I’d love to get some feedback on this, and since this is my second (public) plugin, try to be nice