Help:Syntax Highlighting

From Rosetta Code
Revision as of 14:51, 9 November 2009 by rosettacode>Mwn3d (Note about language template "tags" parameter)

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

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.

Also, if it hasn't been done yet, add the identifier to your language's category page. Use the "tags" parameter in the language template to specify it (e.g. "tags=foo" for the example above). If you find that your language already has a tag listed there that isn't in the Village Pump post, add it to the post as well.

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.