## New Syntax Highlighter

Comments, ideas, feedback, and "How do I... ?" questions

### New Syntax Highlighter

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.

impudens simia et macrologus profundus fabulae

euler

Posts: 2006
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England

### Re: New Syntax Highlighter

It's perfect, for me.

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

+1 for this new feature.
Entia non sunt multiplicanda praeter necessitatem

Francky

Posts: 90
Joined: Sat May 07, 2011 2:49 pm
Location: South of France

### Re: New Syntax Highlighter

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).
thundre

Posts: 331
Joined: Sun Mar 27, 2011 9:01 am

### Re: New Syntax Highlighter

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

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.

impudens simia et macrologus profundus fabulae

euler

Posts: 2006
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England

### Re: New Syntax Highlighter

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

Hello!
Thank you, I really appreciate the new highlighter:D!
domenico_scarlatti

Posts: 1
Joined: Fri Dec 07, 2012 9:52 am

### Re: New Syntax Highlighter

Hi!
YES! me too. It's great!
rubys00

Posts: 3
Joined: Fri Dec 14, 2012 8:53 pm

### Re: New Syntax Highlighter

euler wrote: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.

Code: Select all

tags. To specify a particular language then you can use
Code: Select all

, 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 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.

I really enjoyed the new features of SyntaxHighlighter It's really have the ability to dynamically load them without having to load. Thanks
davidshawn86

Posts: 2
Joined: Tue Jul 23, 2013 4:13 pm