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

From Rosetta Code
Content added Content deleted
(Re: raw files and new languages)
(SE for new languages)
Line 19: Line 19:
::::*Comment characters
::::*Comment characters
::::Also it would need a regular expression for comments. It would probably be best to talk to the people working on [http://sourceforge.net/projects/geshi/ the GeSHi project] about adding new languages.--[[User:Mwn3d|Mwn3d]] 16:29, 7 July 2008 (UTC)
::::Also it would need a regular expression for comments. It would probably be best to talk to the people working on [http://sourceforge.net/projects/geshi/ the GeSHi project] about adding new languages.--[[User:Mwn3d|Mwn3d]] 16:29, 7 July 2008 (UTC)

==Adding new languages==

Ok, I had a look at the source in the SVN. Doesn't seem too difficult to add new languages; basically all one has to do is to copy the php files for one of the existing languages and change it to suit the new one. I guess I could make for Haskell, say, in less than an hour. BTW, I cannot see 96 languages, the SVN just has C, Codeworker, C#, CSS, Delphi, Doxygen, Eiffel, HTML, Java, Javascript,
PHP, QBasic, SQL, VHDL and Web3D. Unless I looked in the wrong place.

I'd like to propose the following:

* Add a page about syntax highlighting, what languages are available, and what one must do to extend/change the existing highlighting.
* Link that page from the homepage.
* Make a copy of the php-files with the syntax highlighting code available via the Wiki. Then people can just grab the code that fits best, and turn it into code for a new language.
* When they've done that, they should ask someone with admin rights to incorporate the changes. That shouldn't happen too frequently, so the workload for the admins should be tolerable. For security reasons, it's probably a bad idea to allow editing of "life" php code.
* Make <code lang="xyz">...</code> act the same as <pre>...</pre>, if there's no syntax highlightling definition for '''xyz'''. This will allow to write syntax highlighting tags ''right now'', instead of having to replace them all later when syntax highlighting for that languages becomes available
* Once the php code has settled, one can submit it back upstream.

Rationale:

* Rosetta is the ideal place to write and test syntax highlighting. There are already many code examples available, and it will be immediately useful. And it will also offer motivation to make syntax highlightling for more esoteric languages.
* I'd like the "feedback loop" to be as short as possible, in true Wiki style. People contribute because they can immediately see the results. If one first has to contact the upstream developers, then wait until the next version of Geshi comes out, then wait until it's installed at Rosetta, etc., I guess the motivation to do something will be pretty low. It's already bad that one ask to one of the admins to "go live" with it, but I guess otherwise the security risk is just too great.
* I offer to do all of the work outlined above myself as far as I am able to :-) So I need someone with admin rights to make a copy of the php scripts of the currently installed available through the Wiki, but I can write the other Wiki pages etc.

Comments? --[[User:Dirkt|Dirkt]] 09:29, 8 July 2008 (UTC)

Revision as of 09:29, 8 July 2008

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)

Adding new languages

Ok, I had a look at the source in the SVN. Doesn't seem too difficult to add new languages; basically all one has to do is to copy the php files for one of the existing languages and change it to suit the new one. I guess I could make for Haskell, say, in less than an hour. BTW, I cannot see 96 languages, the SVN just has C, Codeworker, C#, CSS, Delphi, Doxygen, Eiffel, HTML, Java, Javascript, PHP, QBasic, SQL, VHDL and Web3D. Unless I looked in the wrong place.

I'd like to propose the following:

  • Add a page about syntax highlighting, what languages are available, and what one must do to extend/change the existing highlighting.
  • Link that page from the homepage.
  • Make a copy of the php-files with the syntax highlighting code available via the Wiki. Then people can just grab the code that fits best, and turn it into code for a new language.
  • When they've done that, they should ask someone with admin rights to incorporate the changes. That shouldn't happen too frequently, so the workload for the admins should be tolerable. For security reasons, it's probably a bad idea to allow editing of "life" php code.
  • Make <code lang="xyz">...</code> act the same as <pre>...</pre>, if there's no syntax highlightling definition for xyz. This will allow to write syntax highlighting tags right now, instead of having to replace them all later when syntax highlighting for that languages becomes available
  • Once the php code has settled, one can submit it back upstream.

Rationale:

  • Rosetta is the ideal place to write and test syntax highlighting. There are already many code examples available, and it will be immediately useful. And it will also offer motivation to make syntax highlightling for more esoteric languages.
  • I'd like the "feedback loop" to be as short as possible, in true Wiki style. People contribute because they can immediately see the results. If one first has to contact the upstream developers, then wait until the next version of Geshi comes out, then wait until it's installed at Rosetta, etc., I guess the motivation to do something will be pretty low. It's already bad that one ask to one of the admins to "go live" with it, but I guess otherwise the security risk is just too great.
  • I offer to do all of the work outlined above myself as far as I am able to :-) So I need someone with admin rights to make a copy of the php scripts of the currently installed available through the Wiki, but I can write the other Wiki pages etc.

Comments? --Dirkt 09:29, 8 July 2008 (UTC)