I don’t think it works like this. I copied this example bit from the GeShi documentation
<?php
//
// Include the GeSHi library
//
include_once 'geshi.php';
//
// Define some source to highlight, a language to use
// and the path to the language files
//
$source = '$foo = 45;
for ( $i = 1; $i < $foo; $i++ )
{
echo "$foo\n";
--$foo;
}';
$language = 'php';
//
// Create a GeSHi object
//
$geshi = new GeSHi($source, $language);
//
// And echo the result!
//
echo $geshi->parse_code();
?>
into a template and added the geshi.php file and the geshi folder into /site/plugins and it works perfectly.
Since this is a php class, you need to call it somewhere.
BTW. I use prism.js and so does the Kirby website. You may want to check that out instead? http://prismjs.com
Keep in mind that you probably have to update the knowledge base template, it was made for Kirby 1 and has never been updated to work with Kirby 2, so you might run into errors.
OK, that is clear.
I would prefer GeSHI because it has a language that prismjs does not.
I understand the use in a template. But what do I need to change to have code replaced (´´´php… ´´´) with syntax highlight ? I kind of need to call $geshi->parse_code(); for the text in “fenced code”. Not assuming that is automatic ?
And is there a way to change the string for code, it’s difficult for me to type the back ticks
Extract the text items and the language between the backticks using regex and parse them with geshi.
Another option: A custom Kirbytext tag, have a look at the columns plugin as a basis for ideas: http://getkirby-plugins.com/columns. The you would not need to enter backticks either.
@lukasbestle thanks, that got me a long way.
I found, maybe helpful to others, that to actually color highlight the syntax, I needed to load the CSS in the template. This CSS can be generated from the GeSHi package by calling a PHP script. Needed to comment out a .text class.
I am 99% there. But what I do not understand is the difference between this:
**This works **
Source text: /spaces are here for the forum only../
` ` `php
<? print("this is nice!"); ?>
` ` `
And highlighter:
return preg_replace_callback('!```(.*?)```!is', function($code){
This is not interpreted and outputs as normal text
¤¤¤php
<? print("this is nice!"); ?>
¤¤¤
And highlighter:
return preg_replace_callback('!¤¤¤(.*?)¤¤¤!is', function($code){
As if the kirbytext is only interpreted if I use back ticks.
I can’t really find the place that can tell the difference. This is my last step
Generally this should work just as well. But is that the currency sign found on scandinavian keyboards? Maybe that could be an encoding issue. Have you tried using a different character?
MAAAN do I feel stupid! I work with these things every day. And I am trapped by a dumb encoding issue. One of the files (highlight.php) was ANSI, the source UTF-8. Once that was fixed, it worked.
So, I now have something that works. GREAT.
For the people that read this, you may want to have a look at GeSHi documentation. With a few changes you can have line numbers and other goodies.