How to use the GeSHi plugin/mambot

Written by Cory | July 22, 2008 | Add Comment (0)

Joomla! comes with a plugin/mambot called GeSHi that comes in quite handy if you have a site like HowToJoomla.net in which you share code snippets with your readers. I recently tried to use GeSHi on a Joomla! 1.5 site, and I found that it works differently in Joomla! 1.5 than it does in Joomla! 1.0. Read on to see how to use it in both.

What is GeSHi?

GeSHi stands for "Generic Syntax Highlighter", and it is used to highlight code snippets in different web languages like PHP, HTML, and CSS. It also converts tags in those languages so that they will not render like regular tags.

For example, if you want to share some HTML code, you have to use something like GeSHi, or the browser will treat your HTML code like regular HTML code.

The following code is done without GeSHi:

Without GeSHi

The following code is done with GeSHi:

 
<p><strong>With GeSHi</strong></p>
 

Not that in the code with GeSHi, you can see the HTML tags, and in the code without GeSHi, you cannot see the HTML tags. The words "Without GeSHi" are rendered like regular HTML

How to use GeSHi in Joomla! 1.0

To use GeSHi in Joomla! 1.0, you use the following HTML code:

 
<pre lang="html">
 <!-- your HTML code here -->
</pre>
 

You can change 'lang="html"' to other languages like 'lang="php"' so that GeSHi highlights it according to the language you are using.

How to use GeSHi in Joomla! 1.5

GeSHi has a very slight difference in Joomla! 1.5. Here is an example:

 
<pre xml:html>
 <!-- your HTML code here -->
</pre>
 

Note that instead of 'lang="html"', you use 'xml:html'. That is the only difference. I'm not sure why they did it that way, but they did so if yo plan on using GeSHi for Joomla! 1.5, you need to be aware of this.

Questions/Comments

As always, questions and comments are welcome.

Trackback(0)

Comments (17)Add Comment

244
...
written by Jason Boyette, July 24, 2008
Thanks for this. Do you know of any place where you can get all the syntax requirements for GeSHi in 1.5?
62
...
written by Cory, July 24, 2008
Hi Jason...I'm not sure if I understand the question.
244
...
written by Jason Boyette, July 24, 2008
You say for 1.0,
You can change 'lang="html"' to other languages like 'lang="php"' so that GeSHi highlights it according to the language you are using.


In 1.5, if you want to display PHP code, do you change it to ? How about CSS? I'm looking for a resource for the syntax inside the tag.

Maybe I'll just use the old trial-and-error method.
244
...
written by Jason Boyette, July 24, 2008
Shoot, the comment system removed my tags!
62
...
written by Cory, July 24, 2008
in 1.5, instead of

lang="php"


you use

xml:php


you could trade out php for html, css, etc. I'm not sure of all the languages it supports...
244
...
written by Jason Boyette, July 24, 2008
Thanks! That's what I was looking for. If I find any more information, I'll write back.
0
...
written by wene, September 24, 2008
hello
i had a problem using a custom language file with geshi and j1.5.
the working syntax is for me :
0
...
written by wene, September 24, 2008
xml:lang="mylang"
0
...
written by Spacemonkey, October 15, 2008
Ok, will see if you got GeSHi firing on your comments, bwaahahahaha...



For [removed]



0
...
written by Spacemonkey, October 15, 2008
Dang, used a forbidden word in my code example.

*sniff*
0
...
written by Slavko, November 01, 2008
Thankd for explanation usage of the GeShi in J1.5 smilies/wink.gif
0
...
written by Kenneth Crowder, November 11, 2008
I'm not sure of all the languages it supports...

From: libraries/geshi/geshi.php
actionscript, ada, apache, asm, asp, bash, c, c_mac, caddcl, cadlisp, cdfg, cpp, csharp, css, delphi, html4strict, java, javascript, lisp, lua, mpasm, nsis, objc, oobas, oracle8, pascal, perl, php, python, qbasic, sas, smarty, vb, vbnet, visualfoxpro, xml
0
...
written by Webagentur, December 10, 2008
How I Use geshi in typo3?
62
...
written by Cory Webb, December 10, 2008
Hi Webagentur... I don't know how you would use it in typo3. You would have to ask someone who is more familiar with that platform.
0
...
written by smalls, December 30, 2008
how do you get multiple lines of code to show up with formatting when i try to place code into an article using you tutorial all the formatting is gone.

Also, you don't mention that i need to turn off the WYSIWYG why not?

thanks
507
Translation
written by Federico Capoano, March 06, 2009
Could I translate this article and publish it giving the credits?
0
showng xml file contents?
written by Dylan, May 11, 2009
How do I show the contents of an xml file?

Using xml:html, xml:xhtml or even xml:xml all do not get the intended result.

It would simply show something like
my_template as simply my_template without the tags. It does show it in the proper font though ;-)

You could of cours always use the corresponding ampersand-something but that seems a drag

Write comment

security code
Write the displayed characters


busy

Join the HowToJoomla Community!

  • Create a profile
  • Connect with other members
    of the community
  • All for FREE

Sign up now!

 

Already a member? Login here.

HowToJoomla is proudly hosted by Eleven2

 
 
 

Search the Joomla! Community for Resources

 
 

Latest Community Activity

Yesterday
Cory and depika are now friends 12:47 PM
2 days ago
shashidhar replied in a discussion Need help 07:11 AM
shashidhar joined a group HowToJoomla! 07:10 AM
5 days ago
Shine Rankin replied in a discussion Need help 05:00 AM
Shine Rankin joined a group HowToJoomla! 04:59 AM
3 weeks ago
michael cuanico added Feeds application Jun 14
John joined a group HowToJoomla! Jun 10
 

Welcome to Our Newest Community Members

wil san
Ty Moyer
namal
krishan
shashidhar
leland
Jack Barakitis
Jim Livingstone
Robert Teufel
Amirul Azizi
James Hafner
Mahmood Anwar
 
 

Latest Comments

How to embed a Googl

I have embedded many times google maps to joomla, ...

Beginning Joomla! We

Thank you for given this great post.... ...

How to embed a YouTu

Hello, I have installed this plug in its working g ...

Blank Joomla! 1.5 Te

can rebrand to control panel logo? ...

How to Move Your Joo

Thank you for this. It worked like a dream for me ...