I am using the Syntax Highlighter built with Javascript by Alex Gorbatchev (http://alexgorbatchev.com/SyntaxHighlighter/download/)
The Javascript has separate “brush” js file for each language that it has syntax support for, these brush file are just regex for all the syntax matching for that particular language, it matches items and then wraps them in CSS classes.
Currently the PHP brush file matches pretty much everything but lacks 1 thing, PHPDoc comment variables.
/**
* @author Jason Davis
* @copyright 2011
*/
the @author and @copyright are what I am talking about in this example.
So I now have some regex that will match these however it is not working because the current comment regex is stopping it…
Here is a snippet of the regex code that matches the PHP comments
SyntaxHighlighter.brushes.Php = function ()
{
this.regexList = [
// Multi Line Comments
{ regex: /\/\*[\s\S]*?\*\//gm,
css: 'php-comment comments' },
// More regex for all the other stuff is below here.......
];
};
Now if I add in my NEW code for PHPDoc comment variables…
// PHPDoc Comment Variables (ie @author)
{ regex: /@[a-z]+/g,
css: 'php-phpdoc phpdoc' }
It will not work, even though my new regex works. If I disable the comment regex above my new code then it works and wraps my PHPDoc comment variables with the CSS class.
So I am thinking, maybe if I can modify my PHPDoc regex to rest inside of a comment regex maybe that would work? IF you have any ideas or can help I could really use it and appreciate it
UPDATE
I think I found the code that is preventing it from working…
My code is nested inside of a Comment match and this code’s note says that it prevents this, maybe this can be modified to allow my PHPDoc to remain nested instead of removing it
It is found here https://github.com/alexgorbatchev/SyntaxHighlighter/blob/master/scripts/shCore.js on line 1318
/**
* Checks to see if any of the matches are inside of other matches.
* This process would get rid of highligted strings inside comments,
* keywords inside strings and so on.
*/
removeNestedMatches: function(matches)
{
// Optimized by Jose Prado (http://joseprado.com)
for (var i = 0; i < matches.length; i++)
{
if (matches[i] === null)
continue;
var itemI = matches[i],
itemIEndPos = itemI.index + itemI.length
;
for (var j = i + 1; j < matches.length && matches[i] !== null; j++)
{
var itemJ = matches[j];
if (itemJ === null)
continue;
else if (itemJ.index > itemIEndPos)
break;
else if (itemJ.index == itemI.index && itemJ.length > itemI.length)
matches[i] = null;
else if (itemJ.index >= itemI.index && itemJ.index < itemIEndPos)
matches[j] = null;
}
}
return matches;
},
You could match a
@foostring inside of a comment block by asserting that a*/will follow it (and do so before any following/*appears):Explanation: