That's actually a cool idea, good job @sijad!
I glanced at your repository and I have a couple of notes that should help keep your code nice and tight. The first is that you don't have to use (?:^|\b)
in regexps; The start of a string is a boundary, which means you can use \b
and it'll still match at the start of the string. That applies to PCRE and JavaScript expressions.
The second is that in XSL, you can evaluate expressions inside of attributes using curly braces. That's a handy notation that will save you tons of keystrokes. It's also a tiny bit more performant so even if you don't use it, the library will simplify the template for you. For instance, here's what the template for the issue link looks like once it's simplified:
echo $configurator->tags['GITHUBISSUE']->template;
<a class="github-issue-link" href="https://github.com/{@repo}/issues/{@issue}"><xsl:value-of select="@repo"/>#<xsl:value-of select="@issue"/></a>
Finally, I'm about 99% sure that you don't have to create a custom plugin for it and you can rely on the Preg plugin instead. That's what the mentions extension uses.
$configurator->Preg->replace(
'!\\bhttps?://github\\.com/(?<repo>[\\w-]+/[\\w-]+)/commit/(?<commit>[0-9a-f]{7,40})!Si',
$template,
'GITHUBCOMMIT'
);
// match() works like replace() except it doesn't create a tag
$configurator->Preg->match(
'!(?<repo>[\\w-]+/[\\w-]+)@(?<commit>[0-9a-f]{7,40})!Si',
'GITHUBCOMMIT'
);
$configurator->Preg->replace(
'!\\bhttps?://github\\.com/(?<repo>[\\w-]+/[\\w-]+)/issues/(?<issue>\\d+)!Si',
$template,
'GITHUBISSUE'
);
$configurator->Preg->match(
'!\\b(?<repo>[\\w-]+/[\\w-]+)#(?<issue>\\d+)!Si',
'GITHUBISSUE'
);
I'm subscribed to this thread to keep tabs on it. Feel free to tag me if you need help with s9e\TextFormatter.