1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Link hashes in Remarkup commit links

Summary: Also generalize the code a bit.

Test Plan:
rPF57bc7f#inline-874
rPF57bc7f#874

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4168
This commit is contained in:
vrana 2012-12-12 13:46:28 -08:00
parent 9607642414
commit b05b9f2408
2 changed files with 11 additions and 10 deletions

View file

@ -4,18 +4,14 @@
* @group markup
*/
final class PhabricatorRemarkupRuleDiffusion
extends PhutilRemarkupRule {
extends PhabricatorRemarkupRuleObjectName {
public function apply($text) {
return preg_replace_callback(
'@\br([A-Z]+[a-f0-9]+)\b@',
array($this, 'markupDiffusionLink'),
$text);
protected function getObjectNamePrefix() {
return 'r';
}
public function markupDiffusionLink($matches) {
return $this->getEngine()->storeText(
'<a href="/r'.$matches[1].'">r'.$matches[1].'</a>');
protected function getObjectIDPattern() {
return '[A-Z]+[a-f0-9]+';
}
}

View file

@ -8,10 +8,15 @@ abstract class PhabricatorRemarkupRuleObjectName
abstract protected function getObjectNamePrefix();
protected function getObjectIDPattern() {
return '[1-9]\d*';
}
public function apply($text) {
$prefix = $this->getObjectNamePrefix();
$id = $this->getObjectIDPattern();
return preg_replace_callback(
"@\b({$prefix})([1-9]\d*)(?:#([-\w\d]+))?\b@",
"@\b({$prefix})({$id})(?:#([-\w\d]+))?\b@",
array($this, 'markupObjectNameLink'),
$text);
}