Help:Syntax Highlighting: Difference between revisions

From Rosetta Code
Content added Content deleted
(Fix example instructions, I don't think we need the old style example anymore)
(Largely rewrote. (I removed the <lang list> here to encourage users to check the hand-maintained list on the Village Pump.))
Line 1: Line 1:
This wiki supports syntax highlighting in code examples using the [http://sourceforge.net/projects/geshi/ GeSHi] project (version number shown below).
Rosetta Code supports syntax highlighting of code using [http://sourceforge.net/projects/geshi/ GeSHi], the Generic Syntax Highlighter.


At the moment, the wiki is in transition from old style to new style highlighting; old style highlighting will still be valid for some time.
At the moment, the wiki is switching from old-style to new-style highlighting. Old-style highlighting will still work for a while, but only the new style is documented below.


== New style ==
== How to highlight ==
Prefix your code with <code>&lt;lang ''foo''&gt;</code> (where ''foo'' is the language to use for highlighting) and suffix it with <code>&lt;/lang&gt;</code>. Be sure not to insert extra space between the tags and your code. For example, here's how you'd highlight a C program:

Code examples are enclosed by '''&lt;lang&gt;''' tags. The '''lang''' argument selects the language used for highlighting. Example:


<pre>
<pre>
<lang c>int main (int argc, char* argv[])
<lang c>
int main (int argc, char* argv[])
{
{
return 0;
return 0;
}</lang>
}
</lang>
</pre>
</pre>


That markup would be rendered thus:
looks like


<lang c>int main (int argc, char* argv[])
<lang c>
{
int main (int argc, char* argv[])
return 0;
{
}</lang>
return 0;
}
</lang>

A list of supported languages, and their corresponding PHP files for GeSHi, can be found here:
http://geshi.svn.sourceforge.net/viewvc/geshi/tags/RELEASE_1_0_7_22/geshi-1.0.X/src/geshi/ (change version number to match the one below).


== Supported languages ==
Ideally, one should also use the lang tags for languages that are not yet supported, because that will avoid additional editing if these languages will become supported in a future release of GeSHi.
See [[Rosetta Code:Village Pump/Syntax Highlighting#Language tags|this post on the Village Pump]] for a list of language names. Make sure to use the standard identifier for your language even if GeSHi doesn't know how to highlight it yet. If your language isn't in the list, make up an identifier (consisting entirely of lowercase alphanumeric ASCII characters; make it short yet unambiguous) and add it to the list. That way, if your language is supported in a future release of GeSHi, Rosetta Code can immediately benefit.


If you'd like to, it's surprisingly easy to write a new language definition for GeSHi. See [[Rosetta Code:Village Pump/Syntax Highlighting#Relationship Between Rosetta Code and GeSHi|this post]] for more on the relationship between GeSHi and Rosetta Code.
It's in principle possible to write additional PHP files for unsupported languages and include them. Please contact one of the administrators for details.
<div style="clear: both; column-count: 3; -webkit-column-count:3; -moz-column-count:3"><lang list></lang></div>

Revision as of 14:39, 9 November 2009

Rosetta Code supports syntax highlighting of code using GeSHi, the Generic Syntax Highlighter.

At the moment, the wiki is switching from old-style to new-style highlighting. Old-style highlighting will still work for a while, but only the new style is documented below.

How to highlight

Prefix your code with <lang foo> (where foo is the language to use for highlighting) and suffix it with </lang>. Be sure not to insert extra space between the tags and your code. For example, here's how you'd highlight a C program:

<lang c>int main (int argc, char* argv[])
{
  return 0;
}</lang>

That markup would be rendered thus:

<lang c>int main (int argc, char* argv[]) {

 return 0;

}</lang>

Supported languages

See this post on the Village Pump for a list of language names. Make sure to use the standard identifier for your language even if GeSHi doesn't know how to highlight it yet. If your language isn't in the list, make up an identifier (consisting entirely of lowercase alphanumeric ASCII characters; make it short yet unambiguous) and add it to the list. That way, if your language is supported in a future release of GeSHi, Rosetta Code can immediately benefit.

If you'd like to, it's surprisingly easy to write a new language definition for GeSHi. See this post for more on the relationship between GeSHi and Rosetta Code.