From b05b9f2408657db50ad4f5aa1824194c9f89cba1 Mon Sep 17 00:00:00 2001 From: vrana Date: Wed, 12 Dec 2012 13:46:28 -0800 Subject: [PATCH] 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 --- .../rule/PhabricatorRemarkupRuleDiffusion.php | 14 +++++--------- .../rule/PhabricatorRemarkupRuleObjectName.php | 7 ++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleDiffusion.php b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleDiffusion.php index 18bf6831aa..0b74d3f35a 100644 --- a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleDiffusion.php +++ b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleDiffusion.php @@ -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( - 'r'.$matches[1].''); + protected function getObjectIDPattern() { + return '[A-Z]+[a-f0-9]+'; } } diff --git a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObjectName.php b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObjectName.php index 188da30235..5d11ae0131 100644 --- a/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObjectName.php +++ b/src/infrastructure/markup/rule/PhabricatorRemarkupRuleObjectName.php @@ -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); }