After installation the plugin has to be enabled. So do it here

  1. Login into your website admin and go to Extensions > Plugin Manager.
  2. Look for Content – Code Highlighter (GeSHi) and enable it. Done!

 

Customizing and using Joomla Syntax Highlighter Geshi

There are only 3 files that need to be edited a little, however it is really very quick and easy to do.

The files that need editing are:

  • geshi.php
  • index.php of your template
  • your template CSS file

Editing geshi.php gives following

There are three reasons:

  • To disable the option that automatically generates keyword links within your code.
  • To style the header of the code block
  • To display name of programming/scripting/markup language

Editing template index.php gives following

To include a few lines of javascript required to give the lines of code an alternating colour.

Editing template CSS gives following

To add a few quick styles so that we can make the code blocks look awesome!

 

Edit geshi.php

File location: plugins/content/geshi/geshi/geshi.php

Add language name to the header of the block

  1. var $header_content = '';

Change to:

  1. var $header_content = '{LANGUAGE} Code';

Add style to the header of the block

  1. var $header_content_style = '';

Change to:

  1. var $header_content_style = 'background: none repeat scroll 0 0 #C95000;border-bottom: 3px solid #FEA104;color:#fff;font-size: 1.3em;padding-left: 3px;text-transform: uppercase;';

Disabling Keyword linking

  1. var $keyword_links = true;

Change to:

  1. var $keyword_links = false;

Save and upload to your server

 

Edit your template’s index.php

This edit is to add a few lines of javascript required to colour the lines of code with an alternating colour.

File location: templates/YOUR_TEMPLATE_NAME/index.php

Open index.php with your source code editor or open the php file which is used as a template’s index file

Between the <head> tags, include the following code:

  1. <script type="text/javascript">
  2. ( function($) {
  3. $(document).ready(function(){
  4. $('.php li:nth-child(odd)').addClass('odListItem');
  5. $('.php li:nth-child(even)').addClass('evenListItem');
  6. $('.html4strict li:nth-child(odd)').addClass('odListItem');
  7. $('.html4strict li:nth-child(even)').addClass('evenListItem');
  8. $('.css li:nth-child(odd)').addClass('odListItem');
  9. $('.css li:nth-child(even)').addClass('evenListItem');
  10. $('.javascript li:nth-child(odd)').addClass('odListItem');
  11. $('.javascript li:nth-child(even)').addClass('evenListItem');
  12. });
  13. } )
  14. ( jQuery );
  15. </script>

Save and upload to your server

 

Edit your template’s CSS file

File location: templates/YOUR_TEMPLATE_NAME/css/CSS_FILE.css

Open your CSS file

Anywhere in your CSS file, add this code

  1. pre{
  2. background: none repeat scroll 0 0 #F1F1F1;
  3. border: 1px dotted #D3D3D3;
  4. margin-bottom:10px;
  5. white-space: pre-wrap; /* css-3 */
  6. white-space: -moz-pre-wrap; /* Mozilla */
  7. white-space: -pre-wrap; /* Opera 4-6 */
  8. white-space: -o-pre-wrap; /* Opera 7 */
  9. word-wrap: break-word; /* Internet Explorer 5.5+ */
  10. }
  11. pre ol li{
  12. margin: 0 0 0 20px !important;
  13. padding: 4px;
  14. }
  15. pre ol {
  16. margin: 0 0 0 10px !important;
  17. }
  18. .odListItem{
  19. background:#fff
  20. }
  21. .evenListItem{
  22. background:#EFFEFF
  23. }

Save and upload to your server

 

Writing Code using the Joomla Syntax Highlighter

Now that the plugin is enabled, if you want to show code in your articles you should switch to HTML view in your WYSIWYG editor and use this format:

<pre xml:lang="java" lines="true">
</pre>

 

<pre xml:lang="php" lines="true">
</pre>

 

<pre xml:lang="css" lines="true">
</pre>

 

etc.

 

JCE Editor Configuration

If you are using the JCE editor, please follow the below steps to make it work.

Login to the Joomla Administrator and go to System->Global Configuration

Go to the Text Filters tab.

For Administrator the Textfilter option should be ‘No Filtering’

syntax highlight using geshi in joomla

Now click on Components->JCE Editor

syntax highlight using geshi in joomla

Click on Editor Global Configuration and check the following settings are there.

syntax highlight using geshi in joomla

Click on Control Panel on left side and click on Editor Profiles from the right panel menu.

syntax highlight using geshi in joomla

Now click on profile – Default

syntax highlight using geshi in joomla

Click on Editor Parameters tab and after that click on Cleanup & Output. Look at the below settings are there

syntax highlight using geshi in joomla

Now click on Advanced tab and look for the below settings.

syntax highlight using geshi in joomla

That’s all.