Fixing syntax highlighter xRegExp error
Posted by: nixd3v | Last edited on: April 30-th 2012 | Posted on: September 21-st 2011 | Has comments: 0
Tagged by: javascript, jquery

I've ran into this issue while using jQuery syntax highlighter plugin (by Alex Gorbatchev). Errors that I've been getting are these:

'XRegExp' is undefined

and also (IE only and only if I would use and jQuery "colorbox" or "pretty photo" plugins on the same page):

object doesn't support this property or method (XRegExp.js)

I really needed syntax highlighter to work as it's IMHO the best syntax highlighting script available. First thing that I discovered is that you can download syntax highlighter from either github, bitbuket or author's home page. What I didn't expect was - that the content of downloaded package would actually differ depending on where you downloaded it from.

More precisely: if downloded from github or bitbucket - XRegExp.js file exists in scripts directory as a separate file and if downloaded from author's personal page - it's quote "bundled with the final shCore.js during build". Now - I didn't dig any deeper - but it looks like author uses Phing to build a project and a final version is only available from author's page (?or not - but it's unclear as I couldn't find more information). If github is used for development version only - there probably should be readme.md that clarifies that:) Would really save me much time.

So - if you've gotten the first error("XRegExp is undefined") - it's most likely caused by the fact that if you downloaded syntax highlighter from github or bitbucket - you also must explicitly include XRegExp.js before shCore.js. But since it's possibly not only thing that differs github version from version on author's page - just download the version that's on the author's page and not from github.

Second issue (namely: "object doesn't support this property or method" in IE) took me a bit more time. And actually I found the solution while reading this bug report over here: bug report

It looks like the problem was a bug in XRegExp library that only surfaced in IE and only if I used colorbox plugin. Some nice dude (Andrey Mironov / andrey.mir) fixed it and uploaded a patched XRegExp.js file and patched shCore.js file. So - there - to fix the second problem (that only happened in older IE versions for me) - simply replace shCore.js file (if downloded syntax highlighter from author's page) or ** XRegExp.js** file (if downloaded from github) with version patched by Andrey Mironov. Don't forget - that if downloaded version from github or bitbucket - you must explicitly include XRegExp.js file on your page!

There! I hope this helps.

ALSO - do not use files in src folder as they also don't include XRegExp library, do use files with same names in scripts directory: xregexp issue.