Anonymous user
Rosetta Code:Village Pump/Syntax highlighting: Difference between revisions
Rosetta Code:Village Pump/Syntax highlighting (view source)
Revision as of 10:38, 8 March 2021
, 3 years agono edit summary
(Recommand 'delphi' for DWScript highlighting) |
No edit summary |
||
(40 intermediate revisions by 17 users not shown) | |||
Line 16:
--[[User:BenBE|BenBE]] 10:00, 17 July 2011 (UTC)
:The snippet fetching has been completed and resulted in about 30k of code snippets in all languages used for highlighting on RosettaCode which are about 100 languages. Most samples are highlighted as text (about 70%), but even then this gives a really nice code base for the project I'm working on. The collection will be available soon under the terms of the GFDL v1.2. More information will be available [http://blog.benny-baumann.de/ in my blog] or on the RosettaCode Planet. :There will be a project related to GeSHi which I'll detail there too.
:The snippet fetching has been removed from the RC site again as the purpose for which I added it has ben fulfilled. Stay tuned for updates!
:--[[User:BenBE|BenBE]] 22:37, 3 August 2011 (UTC)
== 2011/07/05 - GeSHi update to GeSHi 1.0.8.11pre1==
Line 57 ⟶ 63:
Rosetta Code first started using GeSHi for syntax highlighting a long while back, but due to our nature, we quickly discovered, and frequently continue to discover, programming languages which GeSHi does not provide highlighting functionality. Additionally, we've uncovered bugs in various releases of the software, and the GeSHi folks have been welcoming of fixes sent to them.
Due to the way language support is managed in GeSHi, it's fairly trivial for someone who can follow PHP syntax to create a PHP file that adds support for the language of their choice. GeSHi's support for [[Oberon-2]], [[Modula-3]] and [[
I am now also part of the GeSHi project focusing for now on adding and improving support for programming languages present on Rosetta Code. As a community of language aficionados and enthusiasts, Rosetta Code is a hotbed for opportunities for improving GeSHi, and improvement of GeSHi is extremely helpful for improving the readability code on Rosetta Code. --[[User:Short Circuit|Short Circuit]] 06:43, 18 June 2009 (UTC)
Line 76 ⟶ 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]].'''
= Non-GeSHi-issues to take care of =
Line 474 ⟶ 245:
= Known bugs with GeSHi Syntax Highlighting =
==
* 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]]
== OCaml syntax highlighting issues, '''bis''' ==
* 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 ==
:* I've added some Modules for now. For the star-ed Modules I'd need to have the Parent Module name or the Doc-Link that I should be generating. As each Group requires some overhead I'd suggest linking only those with at least 2 or 3 Submodules in it (e.g. Array) and simply highlighting (without Link) the others. Could you compile me that list? --[[User:BenBE|BenBE]] 00:29, 18 February 2010 (UTC)
:: Here are the full links of the star'ed modules:
Line 627 ⟶ 270:
Scanning => http://caml.inria.fr/pub/docs/manual-ocaml/libref/Scanf.Scanning.html
State => http://caml.inria.fr/pub/docs/manual-ocaml/libref/Random.State.html
* this type is currently linked to the url [1], which is wrong, the right url is [2]
<lang ocaml>file_descr
[1] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#TYPEfile_descr
[2] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html#TYPEfile_descr
</lang>
* I think that some links could be modified:
<lang ocaml>
int32 => http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int32.html
int64 => http://caml.inria.fr/pub/docs/manual-ocaml/libref/Int64.html
nativeint => http://caml.inria.fr/pub/docs/manual-ocaml/libref/Nativeint.html
</lang>
* The parser brackets ('''[<''' and '''>]''') should be completely highlighted:
Line 708 ⟶ 295:
</blockquote>
:* Tweaked in language file but needs CSS class sy0 to be set for this to show. --[[User:BenBE|BenBE]] 00:29, 18 February 2010 (UTC)
:: Unfortunately this sy0 CSS class is the same than when '''<''' appears alone (the ''lower than'' opperator), and here the '''[''' is CSS'ed in the same way than when it appears alone too. A different class for when they appear un pairs would be better ('''[<''' and '''>]'''). [[User:Blue Prawn|Blue Prawn]] 19:54, 18 August 2011 (UTC)
== Comments highlighting issues ==
* 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]]
** [[Comments#Modula-3]]
** [[Comments#Perl_6]]
** [[Comments#PHP]]
** [[Comments#REBOL]]
** [[Comments#REXX]]
** [[Comments#NetRexx]]
** [[Comments#ooRexx]]
==Regression in Tcl Syntax Highlighting==
Line 1,073 ⟶ 675:
BTW: The operators: '&#8804;' and '&#8805;' can be done in html as '&le;' and '&ge;' eg '≤' and '≥';
There are a few of others: ne: ≠, cent: ¢ pound: £ deg: °, and: ∧, or: ∨, not: ¬, lceil: ⌈, lfloor: ⌊, times: ×, divide: ÷ larr: ←, rarr: →, uarr: ↑, darr: ↓, and perp: ⊥ <!-- The Algol 68 Report used alefsym: ℵ, "
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: ⊃, equiv: ≡, "
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,318 ⟶ 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"><stdio.h></span><br><br><span style="color: #912f11; background-color: #f0f0f0; font-weight: bold">char</span> input[] =<br> <span style="color: #077807; background-color: #f0f0f0">"Character,Speech</span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">"</span><br> <span style="color: #077807; background-color: #f0f0f0">"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">"</span><br> <span style="color: #077807; background-color: #f0f0f0">"Brians mother,<angry>Now you listen here! He's not the messiah; "</span><br> <span style="color: #077807; background-color: #f0f0f0">"he's a very naughty boy! Now go away!</angry></span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">"</span><br> <span style="color: #077807; background-color: #f0f0f0">"The multitude,Who are you?</span><span style="color: #912f11; background-color: #f0f0f0">\n</span><span style="color: #077807; background-color: #f0f0f0">"</span><br> <span style="color: #077807; background-color: #f0f0f0">"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">"</span><br> <span style="color: #077807; background-color: #f0f0f0">"The multitude,Behold his mother! Behold his mother!"</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">"<table><tr><td>"</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">"</td></tr><tr><td>"</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">"</td><td>"</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">"&lt;"</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">"&gt;"</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">"&amp;"</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">"</td></tr></table>"</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)
|