Village Pump:Home/Syntax Highlighting ( archived 2009-06-18 )

From Rosetta Code
Revision as of 16:29, 7 July 2008 by rosettacode>Mwn3d (Re: raw files and new languages)

I'm going to make some major changes to the Syntax Highlighting extension this weekend. Instead of denoting a block of C code as:

<C>(some code)</C>

Code will be denoted as:

<code lang="C">(some code)<code>

This will significantly clean up the Mediawiki extension namespace, and make formatting tricks with CSS easier. I'd rather create an attribute to <pre>, but that appears as though it could be more complicated. --Short Circuit 05:52, 2 July 2008 (UTC)

Will we need to go and change all of the previous highlighting then? --Mwn3d 06:11, 2 July 2008 (UTC)
Yes. Both approaches will be supported for a little while, I expect, but the current system will definitely be phased out. --Short Circuit 23:42, 2 July 2008 (UTC)
Isn't it possible to access the raw files behind the Wiki, so one could run a simple replace operation on all of them? Also, is there any way to add syntax highlighting for languages for which it isn't supported yet? --Dirkt 11:07, 6 July 2008 (UTC)
I'm not sure about the raw files idea (it sounds easy enough), but the new languages idea gets a bit hairy. The latest GeSHi (v1.0.7.22) has support for 96 languages (counting things like "java" and "java5" as different languages). These languages don't necessarily overlap with the 103 here. Newer languages like Rhope and non-computer languages like TI-83 BASIC will probably never have highlighting. In order to add a new language, we would need to make a special PHP file for it with lists of the following:
  • All keywords that could be highlighted (in a jagged two dimensional array, separated into groups which get different kinds of highlighting)
  • Style codes for each group of keywords, comments, escape characters, brackets, strings, numbers, function names, symbols, scripts, and regex's
  • URLs for each group (if you want keywords to link anywhere like javadocs for Java)
  • Quote characters
  • Symbols from the language (besides math operators)
  • Comment characters
Also it would need a regular expression for comments. It would probably be best to talk to the people working on the GeSHi project about adding new languages.--Mwn3d 16:29, 7 July 2008 (UTC)