Rosetta Code:Village Pump/Syntax highlighting: Difference between revisions

no edit summary
m (Fix link.)
No edit summary
 
(30 intermediate revisions by 16 users not shown)
Line 82:
Note: AutoHotKey currently has two codes, ahk and autohotkey. When AutoHotKey support was added to GeSHi, it was added with the longer code. (lang codes are derived from the filename.) Since there were already code snippets on RC that used ahk for AutoHotKey, I created a symlink that allowed ahk to be used as a language code as well. This should likely be reversed, meaning instances of the ahk tag need to be replaced with the autohotkey tag. --[[User:Short Circuit|Short Circuit]] 07:01, 18 June 2009 (UTC)
 
'''The list moved to [[Help:Syntax Highlighting]].'''
==Recommended language tag usage==
<div style="clear: both; column-count: 3; -webkit-column-count:3; -moz-column-count:3">
* 4D 4d
* 4DOS Batch 4dos
 
A
 
* 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'''
 
B
 
* BASIC '''qbasic''' '''freebasic''' '''thinbasic''' bbcbasic
* Batch File '''dos'''
* Bc bc
* Befunge befunge
* Brainf*** '''bf'''
 
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
 
Z
 
* ZX Spectrum BASIC '''zxbasic'''
</div>
 
== 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>
 
 
= Non-GeSHi-issues to take care of =
Line 486 ⟶ 248:
 
* A syntax highlighting issue with single quotes can be seen here: [[Bitmap/Bézier_curves/Quadratic#Haskell]] and there: [[Conway's_Game_of_Life#Haskell]]
 
== Unix Shell syntax highlighting issues ==
 
* a problem with escaped backticks in strings appears here: [[Simple_database#UNIX_Shell]]
 
 
Line 491 ⟶ 257:
 
* there is a problem with strings containing double quotes as we can see here [[JSON#OCaml]]
* a similar problem occurs with a double quote inside single quotes (the char '"'): [http://rosettacode.org/mw/index.php?title=S-Expressions&oldid=123055#OCaml S-Expressions#OCaml]
 
* the same problem affects Pike, but it doesn't affect Python. <lang ocaml>'"' ocaml</lang><lang pike>'"' pike</lang><lang python>'"' python</lang>
 
== OCaml syntax highlighting issues ==
Line 535 ⟶ 302:
 
* On the [[Comments]] page we can see some languages that use nested comments, here is the list that I can see:
** [[Comments#AppleScript]]
** [[Comments#Haskell]]
** [[Comments#Lua]]
Line 541 ⟶ 309:
** [[Comments#PHP]]
** [[Comments#REBOL]]
** [[Comments#REXX]]
 
** [[Comments#NetRexx]]
 
** [[Comments#ooRexx]]
 
==Regression in Tcl Syntax Highlighting==
Line 906 ⟶ 675:
BTW: The operators: '&amp;#8804;' and '&amp;#8805;' can be done in html as '&amp;le;' and '&amp;ge;' eg '&le;' and '&ge;';
 
There are a few of others: ne: &ne;, cent: &cent; pound: &pound; deg: &deg;, and: &and;, or: &or;, not: &not;, lceil: &lceil;, lfloor: &lfloor;, times: &times;, divide: &divide; larr: &larr;, rarr: &rarr;, uarr: &uarr;, darr: &darr;, and perp: &perp; <!-- The Algol 68 Report used alefsym: &alefsym;, "&#x226E;", "&#x226F;" and &#x2112; http://en.wikipedia.org/wiki/Van_Wijngaarden_grammar -->. But no HTML entities for □, ○, ⎩, ⎧ (Unicode 5.1) and "⏨" (decimal exponentiation - Unicode 5.2).
 
Detecting all the HTML entity defs (http://php.net/manual/en/function.htmlentities.php) is probably the easiest way of doing things.
 
Trivia: Standard Algol 60 required sup: &sup;, equiv: &equiv;, "&#x2423;" and "&#x23E8;" (decimal exponentiation - Unicode 5.2); The Soviet Algol compiler - used for the Buran Space Shuttle reentry software - even had the character: loz: &loz;, together with support for °&#xB0;, &#x2205;, ±&#xB1; and &#x2207; ... I could never figure out what this [http://en.wikipedia.org/wiki/Behenian_fixed_stars#Table_of_Behenian_Stars diamond &loz;] character was used for!!! The Germans also included the unusual "<font size=5>&#x16ED;</font>" (iron/runic cross), I'm not convinced it was used for multiplication. Probably something used for something mundane like printing train time tables, you would have to be German to understand. :-)
 
More Trivia: Most of the HTML entities appear to have arrived via Adobe fonts from an IBM Selectric typewriter font ball that was popular prior to ASCII 69 becoming a mandated US standard. Some of the HTML entities are fairly weird.
Line 1,151 ⟶ 920:
 
: Update: Submitted to the [http://sourceforge.net/tracker/?func=detail&aid=3303485&group_id=114997&atid=670234 GeSHi issue tracker]. [[User:CRGreathouse|CRGreathouse]] 15:50, 18 May 2011 (UTC)
 
= GeShi power appears to be very limited =
 
Look at this: no recogition of embedded command substitution syntax within the string:
 
<lang bash># this is <lang bash>
echo "$(foo "$(bar "asdf\"")")"</lang>
 
Why is the last closing parenthesis green? WTF?
:Because GeSHi doesn't implement recursive matching of strings with nested shell commands (as this would cause quite some trouble with other places. IF you write up some proper PCRE that properly matches such strings, just provide it to me and I'm happy to include it. --[[User:BenBE|BenBE]] 02:38, 28 January 2012 (UTC)
 
Type that same example above into Vim and it's handled perfectly by Vim's recursive, hierarchical language of syntax highlighting regions.
 
Also, what about this:
 
<lang bash>#
cat <<!
echo while true do ; done if fi
what the hell
!</lang>
 
:Use the more common
:<lang bash>#
cat <<HEREDOC
echo while true do ; done if fi
what the hell
HEREDOC</lang>
:and everything is fine. But if you can provide me with a more complete list of allowed characters in the definition of a HEREDOC spec, I'll try to add it. --[[User:BenBE|BenBE]] 01:12, 28 January 2012 (UTC)
 
Keywords are being highlighted inside a here document, which is verbatim text. Shell expressions can occur in a here document, but only as command substitutions $(...).
:GeSHi as used at RC is a mostly context-free parser. If you want something that's context-aware use GeSHi 1.1.X. But unfortunately you can't mix both versions in one script easily. And since GeSHi 1.0.X has a much broader language support, RC is using the stable 1.0.X version. --[[User:BenBE|BenBE]] 01:12, 28 January 2012 (UTC)
 
Sorry, this is not a usable syntax coloring system.
:Write a better one and come back then. --[[User:BenBE|BenBE]] 01:12, 28 January 2012 (UTC)
:: If I write a better one, will Rosetta switch to it? I have absolutely no use for GeShi (and therefore not for any replacement for GeShi, either) except that it's the only system supported in Rosetta. Why would I waste my spare time hacking on this when I can, like, put my spare time programming cycles into something better, like my own project. If we could use some HTML tags, the problem would be solved. Vim does the syntax highlighting perfectly, and can put out HTML that you can cut and paste into a web page or wiki. Say, maybe the HTML put out by Vim can be machine translated into colorized Wikimedia markup [http://en.wikipedia.org/wiki/Help:Wiki_markup#Coloring_text]. This may be the key to a GeShi-free solution, worth looking into.[[Special:Contributions/192.139.122.42|192.139.122.42]] 01:51, 28 January 2012 (UTC)
::: Well, let me thing about this for a moment ... No, you don't really want this. No. You don't! --[[User:BenBE|BenBE]] 02:25, 28 January 2012 (UTC)
::::: Proof of concept:<br><div class="text highlighted_source" style="border:1pt dashed black;white-space:pre;overflow:auto;background:white;color:black;padding:1em;border:1px dashed #2f6fab;color:black;background-color:#f9f9f9;line-height:1.3em"><code><span style="color: #800090; background-color: #f0f0f0">#include </span><span style="color: #077807; background-color: #f0f0f0">&lt;stdio.h&gt;</span><br><br><span style="color: #912f11; background-color: #f0f0f0; font-weight: bold">char</span> input[] =<br>        <span style="color: #077807; background-color: #f0f0f0">&quot;Character,Speech</span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">&quot;</span><br>        <span style="color: #077807; background-color: #f0f0f0">&quot;The multitude,The messiah! Show us the messiah!</span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">&quot;</span><br>        <span style="color: #077807; background-color: #f0f0f0">&quot;Brians mother,&lt;angry&gt;Now you listen here! He's not the messiah; &quot;</span><br>                <span style="color: #077807; background-color: #f0f0f0">&quot;he's a very naughty boy! Now go away!&lt;/angry&gt;</span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">&quot;</span><br>        <span style="color: #077807; background-color: #f0f0f0">&quot;The multitude,Who are you?</span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">&quot;</span><br>        <span style="color: #077807; background-color: #f0f0f0">&quot;Brians mother,I'm his mother; that's who!</span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">&quot;</span><br>        <span style="color: #077807; background-color: #f0f0f0">&quot;The multitude,Behold his mother! Behold his mother!&quot;</span>;<br><br><span style="color: #912f11; background-color: #f0f0f0; font-weight: bold">int</span> main()<br>{<br>        <span style="color: #912f11; background-color: #f0f0f0; font-weight: bold">char</span> *s = input;<br>        printf(<span style="color: #077807; background-color: #f0f0f0">&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;&quot;</span>);<br>        <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">for</span> (s = input; *s; s++) {<br>                <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">switch</span>(*s) {<br>                <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">case</span> <span style="color: #912f11; background-color: #f0f0f0">'\n'</span>: printf(<span style="color: #077807; background-color: #f0f0f0">&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&quot;</span>); <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">break</span>;<br>                <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">case</span> <span style="color: #077807; background-color: #f0f0f0">','</span>:  printf(<span style="color: #077807; background-color: #f0f0f0">&quot;&lt;/td&gt;&lt;td&gt;&quot;</span>); <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">break</span>;<br>                <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">case</span> <span style="color: #077807; background-color: #f0f0f0">'&lt;'</span>:  printf(<span style="color: #077807; background-color: #f0f0f0">&quot;&amp;lt;&quot;</span>); <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">break</span>;<br>                <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">case</span> <span style="color: #077807; background-color: #f0f0f0">'&gt;'</span>:  printf(<span style="color: #077807; background-color: #f0f0f0">&quot;&amp;gt;&quot;</span>); <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">break</span>;<br>                <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">case</span> <span style="color: #077807; background-color: #f0f0f0">'&amp;'</span>:  printf(<span style="color: #077807; background-color: #f0f0f0">&quot;&amp;amp;&quot;</span>); <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">break</span>;<br>                <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">default</span>:   putchar(*s);<br>                }<br>        }<br>        puts(<span style="color: #077807; background-color: #f0f0f0">&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;</span>);<br><br>        <span style="color: #1f3f81; background-color: #f0f0f0; font-weight: bold">return</span> <span style="color: #077807; background-color: #f0f0f0">0</span>;<br>}<br></code></div>[[Special:Contributions/24.85.131.247|24.85.131.247]] 06:59, 28 January 2012 (UTC)
::::::I put <code>text</code> and <code>highlighted_code</code> classes onto the code tag, but nothing. RC's style sheet only asserts this on pre tags. I think that's where the dotted line border style is coming from, without which this is uselessly inconsistent.[[Special:Contributions/24.85.131.247|24.85.131.247]] 07:13, 28 January 2012 (UTC)
::: RC uses GeSHi in part because it's the best out there which can be integrated into PHP (or, at least, has been), and in part because I can trust BenBE enough to ''give him access to the server'', where he handles upgrading GeSHI for me. It reduces my maintenance load. He's also a little easier to work with. Coming in, ranting and raving as you appear to have done, does ''not'' make me want to work with you. --[[User:Short Circuit|Michael Mol]] 03:33, 28 January 2012 (UTC)
 
I'm giving up on defining a syntax coloring scheme for my language, since the official stuff in the GeShi distribution isn't doing the kinds of things that I need to do even a 60% accurate job of it. [[Special:Contributions/192.139.122.42|192.139.122.42]] 23:01, 27 January 2012 (UTC)
: Provide patches upstream and I'm sure to take care of it. Just complaining about the world being stupid doesn't help anyone. --[[User:BenBE|BenBE]] 01:12, 28 January 2012 (UTC)
: GeSHi also has problems with comments in Bash, and with here documents in Ruby. Many of the current syntax-highlighting rules are not correct. --[[User:Kernigh|Kernigh]] 00:32, 28 January 2012 (UTC)
:: And since nobody reported the problems here or upstream its unlikely they will be fixed soon. --[[User:BenBE|BenBE]] 01:12, 28 January 2012 (UTC)
 
= GeShi appears have become 99% transparent =
I just noticed that many code specimen on RC no longer have their Syntax Highlighting apparent. At first I thought it may be just me, but I have the problem in both Firefox and Chrome. So I checked wikipedia and there the Highlighting still appears fine. eg [[wp:ALGOL_68C#The_ENVIRON_and_USING_clauses|ALGOL_68C]], Note the <font color="red">RED</font> where a non standard keyword is used.
By way of contrast <font color="red">ENVIRON</font> in the following is not <font color="red">RED</font> (currently) :
<lang algol68>BEGIN
INT dim = 3; # a constant #
INT a number := 120; # a variable #
ENVIRON EXAMPLE1;
MODE MATRIX = [dim, dim]REAL; # a type definition #
MATRIX m1;
a number := ENVIRON EXAMPLE2;
print((a number))
END</lang>
 
A good place to see the problem is in [[Hello_world]]. eg in [[Hello_world#Python]] & al. I (at least) cannot see any highlighting.
Then when one takes a closer look at the HTML source to the code specimen one finds:
<lang html><pre class="python highlighted_source"><span class="kw1">print</span> <span class="st0">"Goodbye, World!"</span></pre></lang>
 
So it looks like there is a missing style sheet for class="python highlighted_source" & others.
 
Here is the HTML for ALGOL_68:
<lang html><pre class="algol68 highlighted_source">main<span class="sy1">:</span> <span class="br0">(</span><br>
<span class="kw22">printf</span><span class="br0">(</span>$<span class="st0">"Goodbye, World!"</span>l$<span class="br0">)
</span><br><span class="br0">)</span><</pre></lang>
 
A missing style sheet for class="algol68 highlighted_source" maybe?
 
Work around is: think in monochrome! :-)
 
[[User:NevilleDNZ|NevilleDNZ]] 03:49, 20 March 2013 (UTC)
 
Update... today the highlighting is working fine in Algol68 and Python and probably everything else....
 
Problem resolved by some phantom somewhere :-)
 
I note that the wikipedia color schemes are different from rosettacode GeShi color schemes.... Not a big problem, but is there someone somewhere that has proposed a viable "standard" color scheme for syntax highlighting. GeShi itself hints at it, but gedit and vim hint totally different ideas.
 
[[User:NevilleDNZ|NevilleDNZ]] 07:03, 22 March 2013 (UTC)
 
= Highlighting for МК-61 =
I propose to install a syntax highlighting of MK-61/52: [http://pastebin.com/BNByHpac file]. [[User:Русский|Русский]] ([[User talk:Русский|talk]]) 16:02, 11 March 2014 (UTC)
: Or think the highlighting for it is not necessary and the code is clear so? [[User:Русский|Русский]] ([[User talk:Русский|talk]]) 16:09, 12 March 2014 (UTC)
: Do not present the technical opportunities to add new lighting? 19:18, 20 April 2014 (UTC)
:: I think you need to send a pull request if you want to add your language file to GeSHi. The repository is on [https://github.com/GeSHi/geshi-1.0 GitHub]. --[[User:AndiPersti|Andreas Perstinger]] ([[User talk:AndiPersti|talk]]) 06:53, 23 April 2014 (UTC)
::: So, I've finally managed to add a pull request for Phix, any idea how long that will take? [[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 01:00, 25 October 2015 (UTC)
* [https://github.com/GeSHi/geshi-1.0/blob/master/src/geshi/mk-61.php]
*: Is there still someone alive here? When is the update? 14:20, 13 May 2017 (UTC)
 
= AppleScript Comments =
AppleScript '#' comments do not get properly highlighted, nor do nested comments
 
=Tags: lang rsplus vs lang r=
I'm an R user and, like many of the R solutions on this site, when I want to contribute a solution in R, I do what seems to be the natural thing and start my solution with a '''lang r''' tag. This doesn't introduce any special formatting, but I didn't know to expect it to. Recently, I've noticed other R solutions on the site that start their code with '''lang rsplus''' tags and these appear to format the submitted code with nice colours that make R users smile. This raises a few questions that I'd like answered:
 
1) Is there any reason that any one of '''lang r''' or '''lang rsplus''' may be considered the correct option? If so, I'll gladly convert all of my solutions to the correct option.
 
2) Why does '''lang r''' appear to do nothing? Why does it not have the same functionality as '''lang rsplus'''? Is there a template that could be copied to give them the same functionality?
 
3) If the answer to #2 is anything to do with avoiding duplication of work, then is it possible to do a site-wide replacement of one tag for another (e.g. replace all '''lang r''' tags with '''lang rsplus''' tags)? Users would be much less likely to use an incorrect tag if they have never seen it before.
 
As an example of the difference between '''lang r''' and '''lang rsplus''' tags, have a look at the two solutions found at https://rosettacode.org/wiki/Left_factorials#R
--[[User:ReeceGoding|ReeceGoding]] ([[User talk:ReeceGoding|talk]]) 20:03, 18 June 2020 (UTC)
 
= Updating =
Does the site ever update syntax highlighting at all? [[User:Русский|Русский]] ([[User talk:Русский|talk]]) 10:37, 8 March 2021 (UTC)