Howto use geshifilter with FCKEditor in Drupal
If you need to do syntax highlighting in your Drupal posts then geshifilter is the module you are looking for. However, if you also have FCKEditor enabled to give you WYSIWYG editing capabilities then you will need to do a little tweaking to get them to work well together.
The problem
The problem, as far as I can tell, is that FCKEditor converts all special html characters to html entities and then geshi forces these to output to to browser as literal text, so for example:
I want this to display exactly like this
Will probably end up looking more like this, especially if you switch between FCKEditor's source view and WYSIWYG vew:
<p>I want this to display <b>exactly</b> like this</p>
The 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 the style control to the FCKEditor toolbar by editing fckeditor.config.js:
FCKConfig.ToolbarSets['DrupalFull'] = [ ... ['FontFormat','FontName','FontSize', 'Style'], ... ];
- And then add some custom styles to the style menu by editing fckstyles.xml (I set up 3 styles - php html and css).
<style element="codeblock" name="Php Code block" type="text/css"> <Attribute name="language" value="php" ></Attribute> </style> <style element="codeblock" name="HTML Code block" type="text/css"> <Attribute name="language" value="html" ></Attribute> </style> <style element="codeblock" name="CSS Code block" type="text/css"> <Attribute name="language" value="css" ></Attribute> </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:
FCKConfig.ProtectedSource.Add( /<codeblock language[\s\S]*?<\/codeblock>/gi );
Caveats
As I said, it's not perfect. You must be in source mode to enter/edit your geshi filtered code, otherwise the HTML entity conversion will still happen. Once you have entered the code in source mode, you can freely switch between WYSIWYG and source modes, however, you will find that the code does not display correctly when in WYSIWYG mode (but it will display fine in your final output).
Similar articles on this site
LATEST ARTICLES
TODAY'S MOST POPULAR
-
4th Sep 08
-
8th Aug 08
-
20th Sep 08
MOST POPULAR ARTICLES
RECENT COMMENTS
-
1 day 6 hours ago
-
3 days 19 hours ago
-
4 days 31 min ago
-
4 days 6 hours ago
-
4 days 23 hours ago

Comments
21st Jun 2009, 4:54pm
Hi there,
thanks for this info - very useful
Just one minor correction - style - has to be Style with a capital S
25th Feb 2010, 5:00am
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-filter-and-fckeditor-drupal
Please share your thoughts, comments and suggestions...