Help:Syntax Highlighting: Difference between revisions

From Rosetta Code
Content added Content deleted
(Move the list of language tags from Rosetta Code:Village Pump/Syntax Highlighting. The other page is too long.)
m (→‎Supported languages: left a word out)
 
(32 intermediate revisions by 24 users not shown)
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 ==
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:
Prefix your code with <code>&lt;syntaxhighlight lang="foo"&gt;</code> (where ''foo'' is the language to use for highlighting) and suffix it with <code>&lt;/syntaxhighlight&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:


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


That markup would be rendered thus:
That markup would be rendered thus:


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


== 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.


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. [http://rosettacode.org/geshi/ AutoGeSHi] may be of use, although it isn't nearly as fancy as its name suggests; see [[Rosetta Code:AutoGeSHi|this page]].
If you'd like to, it's not difficult to write a new language definition for Pygments. See [https://pygments.org/docs/lexerdevelopment/ Write your own lexer] for more on adding support for a new language.


<div style="background-color:#eee;padding:1em;>
===Recommended language tag usage===
'''''Note:''' There will likely be significant lag between a new lexer being added to Pygments, and the new syntax highlighting being available on Rosetta Code.''
<div style="clear: both; column-count: 3; -webkit-column-count:3; -moz-column-count:3">
* 4D 4d
* 4DOS Batch 4dos


''Once the new lexer is added to Pygments, it won't be available until Pygments has a release.''
A


''We would then need to wait for MediaWiki to bump the Pygments version in the package and release a new version.''
* ALGOL 60 algol60
* ALGOL 68 algol68
* APL apl
* AWK '''awk'''
* ActionScript '''actionscript'''
* Ada '''ada'''
* Agda2 agda2
* AmigaE amigae
* AppleScript '''applescript'''
* Assembly '''asm''' (for x86)
* AutoHotkey '''autohotkey'''


'''''Then''' we would need to wait for Miraheze to update to the version of MediaWiki software that includes the updated Pygments package.''
B


''A multiple month delay is expected, a several year delay is not out of the question.''</div>
* BASIC '''qbasic''' '''freebasic''' '''thinbasic''' bbcbasic
* Batch File '''dos'''
* Bc bc
* Befunge befunge
* Brainf*** '''bf'''


===Recommended language tag usage===
C

* C '''c'''
* C# '''csharp'''
* C++ '''cpp'''
* Caml caml
* Clean clean
* Clojure '''lisp'''
* CMake '''cmake'''
* Cobol '''cobol'''
* ColdFusion '''cfm'''
* Common Lisp '''lisp'''
* Component Pascal '''pascal'''
* Coq coq
* C Shell csh

D

* D '''d'''
* Dao dao
* Dc dc
* Delphi '''delphi'''
* DWScript '''delphi'''

E

* E '''e'''
* EC ec
* ELLA ella
* ESQL '''sql'''
* Eiffel '''eiffel'''
* Emacs Lisp lisp
* Erlang erlang
* Euphoria euphoria

F

* F f
* F# '''fsharp'''
* FALSE false
* FP fp
* Factor factor
* Fan fan
* Forth forth
* Fortran '''fortran'''

G

* GAP gap
* Gnuplot '''gnuplot'''
* Go go
* Groovy '''groovy'''

H

* HaXe haxe
* Haskell '''haskell'''

I

* IDL '''idl'''
* Icon '''icon'''
* Io '''io'''

J

* J '''j'''
* JSON json
* JScript.NET jscript
* Java '''java''' '''java5'''
* JavaScript '''javascript'''
* JoCaml jocaml
* Joy joy
* JudoScript judoscript

L

* LSE64 lse64
* LaTeX '''latex'''
* LabVIEW labview
* Lisaac lisaac
* Lisp '''lisp'''
* Locomotive BASIC '''locobasic'''
* Logo logo
* Logtalk logtalk
* LotusScript '''lotusscript'''
* Lua '''lua'''
* Lucid lucid

M

* M4 m4
* MAXScript maxscript
* MIRC Scripting Language '''mirc'''
* MS SQL '''sql'''
* Make '''make'''
* Maple maple
* Mathematica mathematica
* MATLAB '''matlab'''
* Maxima maxima
* Metafont metafont
* Modula-3 '''modula3'''

N

* NewLISP '''lisp'''
* Nial nial

O

* OCaml '''ocaml'''
* Oberon-2 '''oberon2'''
* Object Pascal '''pascal'''
* Objective-C '''objc'''
* Octave octave
* Omega omega
* OpenEdge/Progress '''progress'''
* Oz oz

P

* PHP '''php'''
* PL/I pli
* PL/SQL '''plsql'''
* Pascal '''pascal'''
* Perl '''perl'''
* Perl 6 '''perl6'''
* Pike '''pike'''
* PlainTeX tex
* Pop11 pop11
* PostScript postscript
* PowerShell '''powershell'''
* Prolog '''prolog'''
* Python '''python'''

Q

* Q q

R

* R r
* REXX rexx
* RapidQ rapidq
* Raven raven
* Rhope rhope
* Ruby '''ruby'''

S

* SAS '''sas'''
* SETL setl
* SMEQL smeql
* SNUSP snusp
* SQL '''sql'''
* Scala '''scala'''
* Scheme '''scheme'''
* Script3D script3d
* Seed7 seed7
* Self self
* Sinclair BASIC '''zxbasic'''
* Slate slate
* Smalltalk '''smalltalk'''
* Standard ML sml

T

* TI-83 BASIC ti83b
* TI-89 BASIC ti89b
* Tcl '''tcl'''
* Toka toka
* Tr tr
* Transact-SQL '''sql'''
* Twelf twelf

U

* Unicon '''unicon'''
* UNIX Shell '''bash'''
* UnixPipes '''bash'''
* Unlambda unlambda

V

* V v
* VBScript vbscript
* Vedit macro language vedit
* Visual Basic '''vb'''
* Visual Basic .NET '''vbnet'''
* Visual Objects visobj

W

* Wrapl wrapl

X

* XQuery xquery
* XSLT '''xml'''
* XTalk xtalk


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


[https://pygments.org/languages/ Official language list]
* ZX Spectrum BASIC '''zxbasic'''
</div>


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>

Latest revision as of 23:55, 3 May 2023

Rosetta Code supports syntax highlighting of code using Pygments.

How to highlight

Prefix your code with <syntaxhighlight lang="foo"> (where foo is the language to use for highlighting) and suffix it with </syntaxhighlight>. 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 not difficult to write a new language definition for Pygments. See Write your own lexer for more on adding support for a new language.

Note: There will likely be significant lag between a new lexer being added to Pygments, and the new syntax highlighting being available on Rosetta Code.

Once the new lexer is added to Pygments, it won't be available until Pygments has a release.

We would then need to wait for MediaWiki to bump the Pygments version in the package and release a new version.

Then we would need to wait for Miraheze to update to the version of MediaWiki software that includes the updated Pygments package.

A multiple month delay is expected, a several year delay is not out of the question.

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.