Help:Syntax Highlighting: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎Recommended language tag usage: don't bother trying to maintain a separate list, just point to official)
m (Geishi no longer supported)
Line 1: Line 1:
Rosetta Code supports syntax highlighting of code using [http://sourceforge.net/projects/geshi/ GeSHi], the Generic Syntax Highlighter.
Rosetta Code supports syntax highlighting of code using [https://pygments.org/ Pygments].


== How to highlight ==
== How to highlight ==
Line 19: Line 19:


== Supported languages ==
== Supported languages ==
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.
Make sure to use the standard identifier for your language even if Pygments 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 Pygments, 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 [[Template:Language|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.
Also, if it hasn't been done yet, add the identifier to your language's category page. Use the "tags" parameter in the [[Template:Language|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.
Line 32: Line 32:


In general, the language parameter should be the lowercase language name bounded by double quotes.
In general, the language parameter should be the lowercase language name bounded by double quotes.

=== GeSHi extension self-report ===
Here is a list of the codes currently provided by GeSHi.
<div style="clear: both; column-count: 3; -webkit-column-count:3; -moz-column-count:3">
<lang list></lang>
</div>

Revision as of 22:50, 28 September 2022

Rosetta Code supports syntax highlighting of code using Pygments.

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:

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

That markup would be rendered thus:

int main (int argc, char* argv[])
{
  return 0;
}

Supported languages

Make sure to use the standard identifier for your language even if Pygments 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 Pygments, 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. AutoGeSHi may be of use, although it isn't nearly as fancy as its name suggests; see this page.

Recommended language tag usage

Rather than trying to keep disparate lists in sync, refer directly to the official Pygments documentation.

Official language list

In general, the language parameter should be the lowercase language name bounded by double quotes.