GeSHi: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
__TOC__ | |||
== Overview== | |||
[http://qbnz.com/highlighter/index.php GeSHi] or the Generic Syntax Highlighter is a PHP program which enables you to have your code highlighted in color, like you would see in Emacs, Visual Studio, Matlab, etc. Once you have it installed, it's really simple to use the code highlighting feature while writing your pages. Simply place the name of the language you would like to use in brackets before/after the code, like so <tt><myLanguage> for cur=1 blah return </myLanguage></tt>. | |||
===Example=== | |||
<ul> | |||
If we have some Matlab code we want to include in our page we would just need to place it within a <tt>Matlab</tt> block, like so: | |||
<pre> | <pre> | ||
< | <Matlab>for cur=1 | ||
blah | |||
</ | return | ||
</Matlab> | |||
</pre> | </pre> | ||
Which would give you the following: | |||
<matlab>for cur=1 | |||
blah | |||
return | |||
</matlab> | |||
<i>Note:</i> The first line of code was placed on the same line as the <tt>Matlab</tt> block to avoid a leading carriage return. | |||
The following languages are currently supported: | See the [[GeSHi#GeshiHighlight.php|GeshiHighlight.php]] section in the installation instructions for another example of code highlighting with PHP. | ||
</ul> | |||
===Supported Languages=== | |||
<ul> | |||
The following languages are currently supported by GeSHi: | |||
<pre> | <pre> | ||
"actionscript-french" "actionscript" "ada" "apache" | "actionscript-french" "actionscript" "ada" "apache" | ||
Line 17: | Line 31: | ||
"blitzbasic" "caddcl" "cadlisp" "c_mac" | "blitzbasic" "caddcl" "cadlisp" "c_mac" | ||
"c" "cpp" "csharp" "css" | "c" "cpp" "csharp" "css" | ||
"delphi" "diff" | "delphi" "diff" "dos" | ||
"d" "eiffel" "freebasic" "gml" | "d" "eiffel" "freebasic" "gml" | ||
"html4strict" "ini" "inno" "java" | "html4strict" "ini" "inno" "java" | ||
Line 28: | Line 42: | ||
"vb" "vhdl" "visualfoxpro" "xml" | "vb" "vhdl" "visualfoxpro" "xml" | ||
</pre> | </pre> | ||
</ul> | |||
== Installation == | |||
To install the GeSHi plugin you need to: | |||
# Download the latest version of GeSHi from the [http://qbnz.com/highlighter/ GeSHi homepage] | |||
# Extract the .tar.gz into your <tt>extensions</tt> directory (you should end up with <tt>extensions/geshi</tt>) | |||
# Create a new file named <tt>GeSHiHighlight.php</tt> your <tt>extensions</tt> directory. And paste in the code from the [[GeSHi#GeshiHighlight.php|GeshiHighlight.php]] section (everything between <tt><?php ?></tt>) | |||
#*If you need to change the location of your GeSHi installation be sure to change <tt>extensions/geshi/geshi/</tt>, on lines 12 and 48, to the appropriate directory. | |||
# Ensure that your directory structure looks similar to [[GeSHi#Directory Structure|Directory Structure]] | |||
# Edit your wiki's LocalSettings.php file and add the line | |||
:<php>include_once( 'extensions/GeSHiHighlight.php' );</php> | |||
:I typically add this above the <tt>$wgSiteName</tt> line.</li> | |||
:*Make sure that the filename and path match your configuration (i.e. if you didn't do the fancy GeSHi capitalization or put it in another directory) | |||
* Done, if you want to change the colors a particular language is using you can edit the definitions inside the geshi directory. | |||
Your extensions directory should now look something like this (see [[GeSHi#Directory Structure|Directory Structure]] for more detailed output) | |||
<bash>myWiki/extensions/geshi/ ] ls | |||
contrib docs geshi geshi.php | |||
</bash> | |||
===Directory Structure=== | |||
<ul> | |||
For example if have the <tt>tree</tt> command you would see something similar to this inside your extensions directory: | |||
<bash>tree extensions/ | |||
extensions/ | |||
|-- GeSHiHighlight.php | |||
`-- geshi | |||
|-- contrib | |||
| |-- cssgen.php | |||
| `-- example.php | |||
|-- docs | |||
| |-- BUGS | |||
| |-- CHANGES | |||
| |-- COPYING | |||
| |-- README | |||
| |-- THANKS | |||
| |-- TODO | |||
| |-- api | |||
| | |-- __filesource | |||
| | | |-- fsource_core__contribcssgen.php.html | |||
| | | | ... <snip> ... | |||
| | | `-- fsource_core__geshixml.php.html | |||
| | |-- blank.html | |||
| | |-- classtrees_core.html | |||
| | |-- core | |||
| | | |-- GeSHi.html | |||
| | | |-- _contrib_cssgen_php.html | |||
| | | | ... <snip> ... | |||
| | | `-- _geshi_xml_php.html | |||
| | |-- elementindex.html | |||
| | |-- elementindex_core.html | |||
| | |-- errors.html | |||
| | |-- index.html | |||
| | |-- li_core.html | |||
| | |-- media | |||
| | | |-- banner.css | |||
| | | |-- images | |||
| | | | |-- AbstractClass.png | |||
| | | | | ... <snip> ... | |||
| | | | `-- up_button.png | |||
| | | |-- lib | |||
| | | | `-- classTree.js | |||
| | | `-- stylesheet.css | |||
| | |-- packages.html | |||
| | `-- todolist.html | |||
| |-- geshi-doc.html | |||
| `-- geshi-doc.txt | |||
|-- geshi | |||
| |-- actionscript-french.php | |||
| | ... <snip> ... | |||
| `-- xml.php | |||
`-- geshi.php | |||
10 directories, 241 files | |||
</bash> | |||
</ul> | |||
==GeshiHighlight.php== | ===GeshiHighlight.php=== | ||
<ul> | |||
The code for adding GeSHi to MediaWiki is shown below (with some slight modifications) and can also be found at <tt>http://www.wickle.com/wiki/index.php/Geshi_Syntax_Highlight_extension</tt> and <tt>http://meta.wikimedia.org/wiki/User_talk:Coffman/Geshi_Syntax_Highlight_extension</tt>. | The code for adding GeSHi to MediaWiki is shown below (with some slight modifications) and can also be found at <tt>http://www.wickle.com/wiki/index.php/Geshi_Syntax_Highlight_extension</tt> and <tt>http://meta.wikimedia.org/wiki/User_talk:Coffman/Geshi_Syntax_Highlight_extension</tt>. | ||
<php><?php | <php><?php | ||
Line 66: | Line 160: | ||
"blitzbasic", "caddcl", "cadlisp", "c_mac", | "blitzbasic", "caddcl", "cadlisp", "c_mac", | ||
"c", "cpp", "csharp", "css", | "c", "cpp", "csharp", "css", | ||
"delphi", "diff", | "delphi", "diff", "dos", | ||
"d", "eiffel", "freebasic", "gml", | "d", "eiffel", "freebasic", "gml", | ||
"html4strict", "ini", "inno", "java", | "html4strict", "ini", "inno", "java", | ||
Line 90: | Line 184: | ||
?> | ?> | ||
</php> | </php> | ||
</ul> | </ul> | ||
Latest revision as of 19:19, 10 October 2006
Overview
GeSHi or the Generic Syntax Highlighter is a PHP program which enables you to have your code highlighted in color, like you would see in Emacs, Visual Studio, Matlab, etc. Once you have it installed, it's really simple to use the code highlighting feature while writing your pages. Simply place the name of the language you would like to use in brackets before/after the code, like so <myLanguage> for cur=1 blah return </myLanguage>.
Example
-
If we have some Matlab code we want to include in our page we would just need to place it within a Matlab block, like so:
<Matlab>for cur=1 blah return </Matlab>
Which would give you the following: <matlab>for cur=1
blah
return </matlab> Note: The first line of code was placed on the same line as the Matlab block to avoid a leading carriage return.
See the GeshiHighlight.php section in the installation instructions for another example of code highlighting with PHP.
Supported Languages
-
The following languages are currently supported by GeSHi:
"actionscript-french" "actionscript" "ada" "apache" "applescript" "asm" "asp" "bash" "blitzbasic" "caddcl" "cadlisp" "c_mac" "c" "cpp" "csharp" "css" "delphi" "diff" "dos" "d" "eiffel" "freebasic" "gml" "html4strict" "ini" "inno" "java" "javascript" "lisp" "lua" "matlab" "mpasm" "mysql" "nsis" "objc" "ocaml-brief" "ocaml" "oobas" "oracle8" "pascal" "perl" "php-brief" "php" "python" "qbasic" "ruby" "scheme" "sdlbasic" "smarty" "sql" "vbnet" "vb" "vhdl" "visualfoxpro" "xml"
Installation
To install the GeSHi plugin you need to:
- Download the latest version of GeSHi from the GeSHi homepage
- Extract the .tar.gz into your extensions directory (you should end up with extensions/geshi)
- Create a new file named GeSHiHighlight.php your extensions directory. And paste in the code from the GeshiHighlight.php section (everything between <?php ?>)
- If you need to change the location of your GeSHi installation be sure to change extensions/geshi/geshi/, on lines 12 and 48, to the appropriate directory.
- Ensure that your directory structure looks similar to Directory Structure
- Edit your wiki's LocalSettings.php file and add the line
- <php>include_once( 'extensions/GeSHiHighlight.php' );</php>
- I typically add this above the $wgSiteName line.
- Make sure that the filename and path match your configuration (i.e. if you didn't do the fancy GeSHi capitalization or put it in another directory)
- Done, if you want to change the colors a particular language is using you can edit the definitions inside the geshi directory.
Your extensions directory should now look something like this (see Directory Structure for more detailed output)
<bash>myWiki/extensions/geshi/ ] ls
contrib docs geshi geshi.php
</bash>
Directory Structure
-
For example if have the tree command you would see something similar to this inside your extensions directory:
<bash>tree extensions/
extensions/
|-- GeSHiHighlight.php
`-- geshi
|-- contrib
| |-- cssgen.php
| `-- example.php
|-- docs
| |-- BUGS
| |-- CHANGES
| |-- COPYING
| |-- README
| |-- THANKS
| |-- TODO
| |-- api
| | |-- __filesource
| | | |-- fsource_core__contribcssgen.php.html
| | | | ... <snip> ...
| | | `-- fsource_core__geshixml.php.html
| | |-- blank.html
| | |-- classtrees_core.html
| | |-- core
| | | |-- GeSHi.html
| | | |-- _contrib_cssgen_php.html
| | | | ... <snip> ...
| | | `-- _geshi_xml_php.html
| | |-- elementindex.html
| | |-- elementindex_core.html
| | |-- errors.html
| | |-- index.html
| | |-- li_core.html
| | |-- media
| | | |-- banner.css
| | | |-- images
| | | | |-- AbstractClass.png
| | | | | ... <snip> ...
| | | | `-- up_button.png
| | | |-- lib
| | | | `-- classTree.js
| | | `-- stylesheet.css
| | |-- packages.html
| | `-- todolist.html
| |-- geshi-doc.html
| `-- geshi-doc.txt
|-- geshi
| |-- actionscript-french.php
| | ... <snip> ...
| `-- xml.php
`-- geshi.php
10 directories, 241 files
</bash>
GeshiHighlight.php
-
The code for adding GeSHi to MediaWiki is shown below (with some slight modifications) and can also be found at http://www.wickle.com/wiki/index.php/Geshi_Syntax_Highlight_extension and http://meta.wikimedia.org/wiki/User_talk:Coffman/Geshi_Syntax_Highlight_extension.
<php><?php
- GeshiHighlight.php
- By: E. Rogan Creswick (aka: Largos)
- largos@ciscavate.org
- ciscavate.org/wiki/
- Loosely based on SyntaxHighlight.php by Coffman, (www.wickle.com)
- Code arranged and packaged by Coffman (www.wickle.com) ;) 10-nov-2004
- Bug fix by Douglas McLaughlin (www.stricq.com) 9-Oct-2005
- $langArray = array("actionscript","ada","apache","asm","asp","bash",
- "caddcl","cadlisp","c","cpp","css","delphi",
- "html4strict","java","javascript","lisp", "lua",
- "nsis","oobas","pascal","perl","php-brief","php",
- "python","qbasic","sql","vb","visualfoxpro","xml");
- If GeSHI doesn't work then try commenting out the previous line and uncomment this next line to
- see the errors that GeSHI is encountering. This will output the error stream rather than the parsed stream
- $geshi->error();');