Drupal - GeSHi Syntax Highlighter

in

GeSHi filter module provides a filter for source code syntax highlighting for a wide range of languages.This module requires third-party GeSHi (Generic Syntax Highlighter) PHP library (1.0.x branch).
After installation go to "administer > site configuration > geshi filter". For compatibility Wiki filter check the "try to auto-configure other filters" option and enable the filter on the wiki input format. Make sure that filters have the order: PEAR wiki filter >> Template filter >> GeSHi filter.
Source code can be entered with for example <code type="java">...</code> or <blockcode language="python">...</blockcode>. Starting from version 5.x-2.0 it is also possible to define your own generic and language specific tags (e.g. <java>) or to work with square bracket style tags (e.g. [python]). Automatically adding line numbers is possible too with for example [ruby linenumbers="normal"].
It is not easy to integrate GeSHI with Wysywyg (another story). The problem is that FCKEditor converts all special html characters to html entities and then geshi forces these to output to to browser as literal text.
Solution:I still haven't found the perfect solution but this is what I did to make things work better:

  • To allow us to easily use the geshi filter styles, add custom styles to the style menu by editing fckstyles.xml (I set up 3 styles - php html and css, commits 498, 502, 508, 510):
  1. <Style type="text/css" name="Php Code block" element="code">
  2.          <Attribute name="language" value="php"></Attribute>
  3. </Style>
  4.          <Style type="text/css" name="HTML Code block" element="code">
  5. <Attribute name="language" value="html"></Attribute>
  6. </Style>
  7. <Style type="text/css" name="CSS Code block" element="code">
  8.          <Attribute name="language" value="css"></Attribute>
  9. </Style>
  • To stop FCKEditor messing things up when switching between source and WYSIWYG views, you need to add this to your fckeditor.config.js file:
  1. FCKConfig.ProtectedSource.Add( /<(code|blockcode|codeblock)[\s\S]*?\/(code|blockcode|codeblock)>/g );

Another solution is GeshiPro plugin (download v1.2 from github, commits 505, 506, 507). This solution has a drawback: the code block is formatted when it's inserted, and after that you don't have control over it.

Comments

BTW, later I ceased to use and configured GeSHi to use .... The good thing is that FCKeditor keeps formatting of sections by default. Only s have to be configured, in an evident manner.

From what I see on your page, it does not work because you use the tag itself to carry language name, e.g. or instead of as described here. For your case to work I would suggest this regular expression
FCKConfig.ProtectedSource.Add( /<(php|vbs|c)[\s\S]*?\/(php|vbs|c)>/g );

Thanks, but adding this line does'nt work for me. I have to add code for specific language.
http://www.techpint.com/programming/syntax-highlighting-using-geshi-filt...

Post new comment

The content of this field is kept private and will not be shown publicly.
To prevent automated spam submissions leave this field empty.