Fixing Geshi on line 2132
Saturday, June 13th, 2009I recently noticed that some of my blog posts, most notably my Templates in YARPP 3 article, was producing a PHP error:
Warning: preg_match() [function.preg-match]: Compilation failed: unrecognized character after (?< at offset 3 in /…/html/blog/wp-content/plugins/wp-syntax/geshi/geshi.php on line 2132
This seemed to be coming from the version 1.0.8.4 version of Geshi I had installed. A quick google search for “geshi line 2132” gives you over a thousand errors, so this seems to be common issue. Geshi is a fabulous and popular syntax highlighter and is the core component of the WP-Syntax plugin for WordPress.
I did some digging around and realized that the issue was with the compilation of this monstrosity of a regular expression, used (as far as I can tell) to identify PHP code snippets, for example the <?php … ?> keywords:
/(?<start><\\?(?>php\b)?)(?: (?>[^\"'?\\/<]+)| \\?(?!>)| (?>'(?>[^'\\\\]|\\\\'|\\\\\\\|\\\\)*')| (?>\"(?>[^\"\\\\]|\\\\\"|\\\\\\\\|\\\\)*\")| (?>\\/\\*(?>[^\\*]|(?!\\*\\/)\\*)*\\*\\/)| \\/\\/(?>.*?$)| \\/(?=[^*\\/])| <(?!<<)| <<<(?<phpdoc>\w+)\s.*?\s\k<phpdoc> )*(?<end>\\?>|\Z)/sm
Not knowing exactly where to start in diagnosing this crazy expression, I simply disabled those “script delimiters” in the geshi/php.php file. The sections I commented out are lines 1080-1101. Now the script delimiters like <?php don’t get highlighted nicely, but I feel that’s a small price to pay for eliminating these errors. Another solution for the WP-Syntax users seems to be to downgrade to 0.9.4. Hopefully in the near future an update to Geshi will come out which fixes this issue once and for all.