Loading...
 
Features / Usability

Features / Usability


GeSHi as a Wiki plugin

posts: 31 United Kingdom

Hi All !

I've recently installed TikiWiki as a prototype intranet at the company I work at.

One thing we'd like to be able to do is to post snippets of C#, C++, or VB code in a nicely formatted manner. At the moment we're using the CODE plugin, but we'd like to include a bit of syntax highlighting. I noticed that some work had been done to implement GeSHi, but I can't find the plugin anywhere in CVS.

Does anyone know how I can implement GeSHi as a Wiki plugin? Bear in mind that I've never programmed in php so please keep things simple!

))RikRak((

posts: 4 Germany

> Hi All !
> One thing we'd like to be able to do is to post snippets of C#, C++, or VB code in a nicely formatted manner. At the moment we're using the CODE plugin, but we'd like to include a bit of syntax highlighting. I noticed that some work had been done to implement GeSHi, but I can't find the plugin anywhere in CVS.
>
> Does anyone know how I can implement GeSHi as a Wiki plugin? Bear in mind that I've never programmed in php so please keep things simple!

Hi, I'm using this solution for my work:
1) Edit tikiwiki-1.9.2\lib\wiki-plugins\wikiplugin_code.php from line 44

Image
Copy to clipboard
if (isset($colors)){ include_once('geshi.php'); $out.= "".geshi_highlight(decodeHTML(trim($code)), $colors, '' , true).""; }


2) copy geshi and its files to tikiwiki-1.9.2\ and tikiwiki-1.9.2\geshi

This solution works fine for HTML-Output. However with PDF I get bad results.

Regards

JMan

posts: 31 United Kingdom

Thanks JMan,

It seems to work partially, but the code has no colours. Am I missing something?


))RikRak((

posts: 4 Germany

Hi,

you have to use the colors= attribute to specify your language.

eg. {CODE()}

Copy to clipboard
java.lang.String string = "Hallo";


This uses the Geshi-Template gshi/java.php

Regards

JMAn

posts: 30

>
> Hi, I'm using this solution for my work:
> ...
> This solution works fine for HTML-Output. However with PDF I get bad results.
>
> Regards
>
> JMan

JMan, thanks for posting this enhancement. I modified your snippet to also implement the line numbering option with geshi, and force links to open in new windows. Hopefully, this will be useful to others.

Copy to clipboard
if (isset($colors)) { include_once ('lib/geshi.php'); $w_geshi = new GeSHi(decodeHTML(trim($code)), $colors, ''); $w_geshi->set_header_type(GESHI_HEADER_NONE); $w_geshi->set_link_target("_blank"); if (isset($ln) && $ln ==1) { $w_geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } $out.= "".$w_geshi->parse_code().""; } else { if (isset($wrap) && $wrap == 1) { ...


I also opted to copy geshi.php and the /geshi subdirectory under /lib instead of the main tikiwiki directory, just my preference.

posts: 1
This is great. Thx
posts: 5

Hi all,

I've just added GeSHI support to the CODE wiki-plugin of Tikiwiki 1.10 CVS, based on your suggestions.

GeSHI now simply needs to be downloaded in lib/geshi/ to work (we can't include it in Tiki due to the license). Both stable and dev versions are supported. You can also install the php-geshi package under Debian or Ubuntu linux distributions. I hope to also have a mod, to make it even easier.

Thanks,
Nyloth.


Upcoming Events

1)  18 Apr 2024 14:00 GMT-0000
Tiki Roundtable Meeting
2)  16 May 2024 14:00 GMT-0000
Tiki Roundtable Meeting
3)  20 Jun 2024 14:00 GMT-0000
Tiki Roundtable Meeting
4)  18 Jul 2024 14:00 GMT-0000
Tiki Roundtable Meeting
5)  15 Aug 2024 14:00 GMT-0000
Tiki Roundtable Meeting
6)  19 Sep 2024 14:00 GMT-0000
Tiki Roundtable Meeting
7) 
Tiki birthday
8)  17 Oct 2024 14:00 GMT-0000
Tiki Roundtable Meeting
9)  21 Nov 2024 14:00 GMT-0000
Tiki Roundtable Meeting
10)  19 Dec 2024 14:00 GMT-0000
Tiki Roundtable Meeting