New Syntax Highlighter

Announcements, comments, ideas, feedback, and "How do I... ?" questions

New Syntax Highlighter

Postby euler » Fri Sep 28, 2012 4:39 pm

The syntax highlighter at PE has changed from a system based on google-code-prettify to highlight.js. It should be made clear that no system is perfect given the number of languages which members are using, but one of the reasons for the change is due to the number of complaints about the old system. I thought the old system was doing a reasonable job, but others didn't agree; in fairness it has not been updated for a number of years and it had limited support for differentl languages. In contrast, highlight.js is still being developed and currently supports 52 languages, even if a number of those are completely obscure.

To use code in the problem threads on the main website please wrap your script between [code] [/code] tags. To specify a particular language then you can use [code=X] [/code], where X is the name of the language.

If you do not specify the language then the parser will use the language you have selected in your profile.

If the language specified (either directly or from your profile) is not recognised then it will attempt to auto-detect.

If you do not wish the parser to use the language specified in your profile then you can force auto-detect by using [code=?].

You can force the parser to not highlight a block of code at all by using an asterisk in the specified language. For example, [code=python*] or [code=*]. In the former case it will indicate that Python is the language on the clickable link at the top of the code box, but no highlighting will be applied to the code within.

As mentioned, currently the script supports 52 languages, but that may change in the future. If your profile language is set to X and you have posted a solution in a different language, Y, then you should specify that language: [code=Y], even if that language is not currently supported. It is generally recommended to not specify a language if the language you're posting is the same as your profile and that is not likely to change. Especially if you're doing that because your current language is not supported but you've found that language Z is a reasonable second best. You may come to regret forcing the parser to use a different language now because it looks reasonable when in the future after full support for your language has been added it would have looked perfect; after all you're not likely to go back and edit all your posts. If in doubt or you really hate the way it is rendering it currently then use [code=*] with every post and it will not highlight your scripts at all.
Image
impudens simia et macrologus profundus fabulae
User avatar
euler
Administrator
 
Posts: 2215
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England

Re: New Syntax Highlighter

Postby Francky » Fri Sep 28, 2012 4:57 pm

It's perfect, for me.

And now // is not the start of a comment in python code.

+1 for this new feature.
:D
ImageEntia non sunt multiplicanda praeter necessitatem
User avatar
Francky
 
Posts: 90
Joined: Sat May 07, 2011 2:49 pm
Location: South of France

Re: New Syntax Highlighter

Postby thundre » Fri Sep 28, 2012 5:06 pm

Thank you, Euler!

The old highlighter seemed to think "base" and "next" were reserved words (they aren't, at least not in Java).

I just checked some code that I previously posted, and it looks better. This is definitely a step up for Java. And props to you for the fact that it works retroactively -- due to sound site design no doubt.

The new highlighter is still not as good as the Eclipse editor, but that one may actually use the Java compiler to detect some things (for example, fields are displayed in a different color than method variables, and static fields are italicized).
Image
thundre
 
Posts: 355
Joined: Sun Mar 27, 2011 9:01 am

Re: New Syntax Highlighter

Postby xoru » Mon Oct 29, 2012 7:03 am

Hi there,

First of all, thanks for the new highlighter. Lua is now finally getting some nice colours in the
solutions forums. I have a tiny remark though, it seems that in the Lua language, the keyword
'function' isn't highlighted.

Thanks,
Bas
xoru
 
Posts: 3
Joined: Sun May 13, 2012 11:09 am

Re: New Syntax Highlighter

Postby euler » Mon Oct 29, 2012 9:02 am

As mentioned in the post the first post, the syntax highlighter uses highlight.js; I have simply integrated it into the forums so that when posts are parsed it selects the appropriate module or uses auto-detect.

What I suggest is for anyone who wishes to improve the highlighting is to check out the website above and if you think you can help then get in touch with the script developers to help add support for your language.
Image
impudens simia et macrologus profundus fabulae
User avatar
euler
Administrator
 
Posts: 2215
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England

Re: New Syntax Highlighter

Postby xoru » Mon Oct 29, 2012 10:02 am

Thank you, I will check out the github and see if I can help anywhere on the Lua language.

A tip for Lua scripters to get the function keyword to highlight: If you have your arguments list
directly after the function keyword 'function(a, b)', it will not highlight. Place a space between
the keyword and parenthesis 'function (a, b)', that fixes it.
xoru
 
Posts: 3
Joined: Sun May 13, 2012 11:09 am

Re: New Syntax Highlighter

Postby domenico_scarlatti » Fri Dec 07, 2012 10:01 am

Hello!
Thank you, I really appreciate the new highlighter:D!
domenico_scarlatti
 
Posts: 1
Joined: Fri Dec 07, 2012 9:52 am


Return to News, Suggestions, and FAQ

Who is online

Users browsing this forum: No registered users and 2 guests