Syntax Highlighting using GeSHi Filter and FCKeditor in Drupal
When I was developing this site, I knew I would be publishing a lot of Source Code. After some googling I foung GeSHi Filter for Source Code Syntax Highlighting. This module integrates the third party PHP library GeSHi (Generic Syntax Highlighter) into Drupal. GeSHi Filter, syntax highlight your source code between <blockcode>tag.
This module works very well for me unless I installed FCKeditor for Rich Text Editing. FCK editor twist your source code when you toggle between Source Code and Rich text editing in it. But with some manual configuration we can stop FCKeditor from twisting the source code.
FCKeditor Documentation suggests the use of
FCKConfig.ProtectedSource.Add(Regular Expression) ;
method to protect any string from FCKeditor. Any text which mataches the given Regular Expression will not be touched by FCKeditor. We have to add the following code in fckeditor.cofig.js to protect our code from FCKeditor.
FCKConfig.ProtectedSource.Add( /<php>[\s\S]*?<\/php>/g ); FCKConfig.ProtectedSource.Add( /<csharp>[\s\S]*?<\/csharp>/g ); FCKConfig.ProtectedSource.Add( /<c>[\s\S]*?<\/c>/g ); FCKConfig.ProtectedSource.Add( /<javascript>[\s\S]*?<\/javascript>/g ); FCKConfig.ProtectedSource.Add( /<vbnet>[\s\S]*?<\/vbnet>/g ); FCKConfig.ProtectedSource.Add( /<sql>[\s\S]*?<\/sql>/g );
- <php></php>, <csharp></csharp> etc are the tags used by GeSHi filter for Syntax Highlighting.
- Likewise you can add code for any Language.
- When you toggle to Rich Text Editing Mode, your source code will not be visible, but it will be published.
- After editing fckeditor.config.js, you should clear the cached data of your Drupal website.
Thanks, this is what I was
Thanks, this is what I was looking for so long.
Thanks for sharing.
Thanks
<?php
echo "Thank you, good to know";
?>
Ah, that was
Ah, that was missing?
great share! that's exactly
great share! that's exactly what i was looking for, thanks!
I have heard many saying
I have heard many saying drupal emerging as one of the leading CMS platform for all content publishing needs, though currently wordpress holds the market but looking to all this post it seems in near future Drupal will become a tough competitor for Word press.
Post new comment