Syntax Highlighter

Announcements, comments, ideas, feedback, and "How do I... ?" questions
User avatar
euler
Administrator
Posts: 5095
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Syntax Highlighter

Post by euler »

Recently changes have been made to the syntax highlighter used in the forums on the main website. Rather than just apply a generic highlighting template it will attempt to accommodate the preferred programming language of the member. However, sometimes members solve a problem in a different language, or wish to give examples of code that works in more than one language in the same post. So it is possible to override by using the tag

Code: Select all

.

Support is currently limited to the following languages (the term found in the bracket contains the keyword that language must be set to):

APL/J/K (apl, j, or k) [alias for text]
BASIC (basic)
C/C++ (c++)
C# (c#)
Delphi (delphi)
Haskell (haskell)
Java (java)
Pascal (pascal) [alias for delphi]
Perl (perl)
PHP (php)
Python (python)
Ruby (ruby)
TCL (tcl)
TECO (teco) [alias for text]

If your language is not in the list it will default to generic (which is an adapted form of javascript).

Although I may add support for other languages over time it is essential that we get a workable system before dealing with the details. So please do not use this thread to bombard me with, "Please add support for X" requests.

One thing I can offer at this stage is the use of aliases. I simply do not know enough programming languages to make these calls myself, but if members tell me that language X uses almost identical syntax to a currently supported language then I can at least make their language adopt that particular highlighting template.

However, once we have a reliable system I will open up the options for more languages. I must stress that when we get to this stage the responsibility will fall on you, the members, requiring a general template to be adapted for their language. But more information about this will be published when we get to that point.

In the meantime please report any glitches or general comments in this thread.
Image
impudens simia et macrologus profundus fabulae
miodrag.milenkovic
Posts: 17
Joined: Wed Apr 02, 2008 7:14 pm

Re: Syntax Highlighter

Post by miodrag.milenkovic »

Any chance of incorporating LaTeX formatting?
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Syntax Highlighter

Post by daniel.is.fischer »

Really cute. But there seems to be a problem with the overriding, in thread 198, my C code isn't highlighted at all with

Code: Select all

.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
User avatar
euler
Administrator
Posts: 5095
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Re: Syntax Highlighter

Post by euler »

Fixed.
Image
impudens simia et macrologus profundus fabulae
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Syntax Highlighter

Post by daniel.is.fischer »

Wow. That was fast. :D
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
User avatar
stijn263
Posts: 1505
Joined: Sat Sep 15, 2007 11:57 pm
Location: Netherlands

Re: Syntax Highlighter

Post by stijn263 »

What happens when you quote someone that uses a different language then you do?
User avatar
euler
Administrator
Posts: 5095
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Re: Syntax Highlighter

Post by euler »

Good point, stihn263. I've just modified the script so that if a member is quoted and they've left the tag as [ code ], then it will insert the member's preferred language. If the member's language is not currently supported then the parser will revert to generic, but the advantage is that if support is added in future that quote should work properly.

The problem with tweaking scripts is that flattening the bump in the carpet in one place causes it to appear somewhere else in the room. Please let me know if anything starts misbehaving.
Image
impudens simia et macrologus profundus fabulae
shai-hulud
Posts: 6
Joined: Mon Jan 07, 2008 9:20 am

Re: Syntax Highlighter

Post by shai-hulud »

hi,
it should be possible to disable syntax highlighting completely. the generic template doesn't work good on TECO code and I really don't want to bother you to write one which does (if that's even possible with your current system)

cheers
User avatar
euler
Administrator
Posts: 5095
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Re: Syntax Highlighter

Post by euler »

I've created an alias that renders TECO as "text"; similarly with APL/J/K.
Image
impudens simia et macrologus profundus fabulae
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Syntax Highlighter

Post by hk »

As far as I can see Delphi syntax is in fact the same as Pascal. (Delphi is in fact Pascal)
So you could let both be rendered by the Delphi highlighting.
Image
War ruins the life and health of untold numbers of innocent children.
User avatar
euler
Administrator
Posts: 5095
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Re: Syntax Highlighter

Post by euler »

Thanks for that, Hans. Pascal is now an alias for Delphi.
Image
impudens simia et macrologus profundus fabulae
User avatar
taylor_venable
Posts: 1
Joined: Fri Jun 27, 2008 1:06 am
Location: Fort Wayne, Indiana, United States
Contact:

Re: Syntax Highlighter

Post by taylor_venable »

In lieu of full Lua support (which I'd be happy to help with if desired), I'd like to ask that Lua be aliased to text, since otherwise the odd comment style (eliding some detail, "--" for line-based and "--[[" to "]]" for block-based) causes some errors when using the default JavaScript-based highlighter. (Namely, unmatched quotation marks [e.g. in contractions] inside comments create an unterminated string. See my post for problem #058 for an example.) Thanks!
davidb
Posts: 1
Joined: Fri Jul 11, 2008 8:59 pm

Re: Syntax Highlighter

Post by davidb »

I wonder how hard it would be to use GeSHi syntax highlighter. That would give you support for 90+ languages. And it would work with TCL, which I've used for most of my solutions.

David
User avatar
euler
Administrator
Posts: 5095
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Re: Syntax Highlighter

Post by euler »

Actually, I use the GeSHi engine, but due to the way that the forum is parsed it requires a little work to integrate languages. I've just added support for TCL.
Image
impudens simia et macrologus profundus fabulae
albert
Posts: 61
Joined: Sat Aug 02, 2008 12:36 pm

Re: Syntax Highlighter

Post by albert »

Dear all,

My language (Forth) would also improve if it was rendered as plain text,
instead of the way it is now.

(I would be willing to contribute a highlighter for Forth, if provided with
information about tags.)

Groetjes Albert
User avatar
chizhek
Posts: 17
Joined: Fri Jul 02, 2010 8:45 am

Re: Syntax Highlighter

Post by chizhek »

I tried to switch off the default syntax highlighting of Mathematica code (which is alwrong) by

Code: Select all

, [code=APL], [code=J], [code=K], and [code=text], all without success: the default highlighting doggedly persists.
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Syntax Highlighter

Post by hk »

If you could mention the problem where you tried it, I could have a look into it.

Edit, found it: 276.
I changed [ code=text ] into [ code=TECO ] and all is fixed. So I don't know what went wrong.
Image
War ruins the life and health of untold numbers of innocent children.
User avatar
chizhek
Posts: 17
Joined: Fri Jul 02, 2010 8:45 am

Re: Syntax Highlighter

Post by chizhek »

Yes, TECO does it, but APL, J, K, and text still have no effect. But woe, when the code is hidden, it is announced as a TECO code. Oh yeah, I did perpetrate some short programs in TECO a-noise-on-the-line-language, but that was so loooooooooong ago... These days I'd rather die than be accused of authoring a piece of TECO code. So I have chosen the lesser evil and switched back to the colorful

Code: Select all

.

The right thing would be for [code=mathematica] to switch off the highligting, without any detrimental side effects, such as being forced to go incognito under the name of some other programming language. Mathematica code does not need highlithing for presentation, it is quite readable in black'n'white, without any bold or italic keywords, or any other visual effects, or whatever.

Perhaps the simplest solution would be to make no-highlithing-at-all the default syntax highlighting.  Yes, I know about the dangers of tweaking scripts, as "euler" aptly decribes them:

"The problem with tweaking scripts is that flattening the bump in the carpet in one place causes it to appear somewhere else in the room."

But surely, the decision "I don't know what to do, so I will do nothing at all" cannot be so hard to implement, even in a script all tangled up from numerous additions, modifications, tweaks and kludges?
otac0n
Posts: 13
Joined: Mon Jun 14, 2010 6:55 pm

Re: Syntax Highlighter

Post by otac0n »

LaTeX formatting should be possible, shouldn't it?

See mathoverflow.net for a proof of concept.

Basically, on their site, anything in-between dollar signs is rendered as LaTeX, and it just uses a client side script. (Specifically, jsMath)
Image Image
Mr.Wizard
Posts: 26
Joined: Sun Jan 02, 2011 9:20 am

Re: Syntax Highlighter

Post by Mr.Wizard »

Is it possible to write a syntax file for the site? I will try my hand at an improved Mathematica highlighter if it can be used.
ImageImage
Post Reply