• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Syntax Highlighting in XF 2

enivid

Active member
#1
XF 2 will have a native support for syntax highlighting with Prism. It is a simple client-side solution that can work for many forums. Currently, quite a lot of XF 1 forums are using GeSHi Syntax Highlighter, which is based on GeSHi. The latter is a server-side solution, which considerably more powerful than Prism. It is easier to define new languages and update the existing ones in GeSHi. For example, it is possible to define groups of functions with different rules within one language. It is possible to define URLs (to documentation for example) to groups of functions. The language files are also more human-readable compared to those in Prism.

Is anyone else interested in XF 2 native support for GeSHi in addition or in place of Prism?
 

Chris D

XenForo developer
Staff member
#3
I promise we didn't copy you! :D

Really for us we just had choice between highlight.js or Prism and Prism for us was the clear winner despite highlight.js perhaps being more popular.
 

digitalpoint

Well-known member
#4
I promise we didn't copy you! :D
I didn't code Prism, I just wanted something better than what GeSHi was doing for me. :)

But even if you did, it would have been fine by me... just one less addon to build and maintain in XF2. Been happy to see all sorts of small/hidden features in XF2 that I had to do with addons.
 

enivid

Active member
#5

digitalpoint

Well-known member
#6
It's been awhile, so I don't remember all the reasons GeSHi wasn't working how i wanted it. But it had a lot to do with GeSHi just needing a ground up rewrite from scratch. The code is so old and not really maintained any longer (the last release was more than 5 years ago). It wasn't designed to be styled with CSS/HTML5, etc.

Just out of curiosity, what language are you looking to add that Prism doesn't support? And yes, you *can* add your own custom languages to Prism, just like you can with PHP.

If you look at the examples between GeSHi and Prism, Prism to me is much cleaner and easier to read:

http://qbnz.com/highlighter/examples.php?c=php&e=phpbb-index

http://prismjs.com/#examples
 

enivid

Active member
#7

digitalpoint

Well-known member
#8
Honestly, I don't see anything amazing or not doable with the MQL* highlighting there... I don't know what MQL is, but doesn't look like anything difficult to do really.
 

enivid

Active member
#9
1. Code readability is much worse with Prism than with Geshi. You are basically forced to code in regex in prism. Consider the following example of how the comments highlighting is defined in Prism:

JavaScript:
    'comment': [
        {
            pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
            lookbehind: true
        },
        {
            pattern: /(^|[^\\:])\/\/.*/,
            lookbehind: true
        }
    ],
and in Geshi:

PHP:
    'COMMENT_SINGLE' => array(1 => '//'),
    'COMMENT_MULTI' => array('/*' => '*/'),
This directly affects the ability of the developer to keep the language library up-to-date.

2. I could not find in Prism how to define multiple groups of functions each with its own set of styling rules.

3. In Geshi, it is possible to add reference links to functions. And these links can also have different templates depending on the function's group.

4. If you look at the Geshi example in my previous post, there is a special complex highlighting rule where some variable is defined as an input (using the keyword 'extern') and is then highlighted with a different color (rusty red) throughout the code.