mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-20 02:38:39 +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:
parent
9607642414
commit
b05b9f2408
2 changed files with 11 additions and 10 deletions
|
@ -4,18 +4,14 @@
|
||||||
* @group markup
|
* @group markup
|
||||||
*/
|
*/
|
||||||
final class PhabricatorRemarkupRuleDiffusion
|
final class PhabricatorRemarkupRuleDiffusion
|
||||||
extends PhutilRemarkupRule {
|
extends PhabricatorRemarkupRuleObjectName {
|
||||||
|
|
||||||
public function apply($text) {
|
protected function getObjectNamePrefix() {
|
||||||
return preg_replace_callback(
|
return 'r';
|
||||||
'@\br([A-Z]+[a-f0-9]+)\b@',
|
|
||||||
array($this, 'markupDiffusionLink'),
|
|
||||||
$text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function markupDiffusionLink($matches) {
|
protected function getObjectIDPattern() {
|
||||||
return $this->getEngine()->storeText(
|
return '[A-Z]+[a-f0-9]+';
|
||||||
'<a href="/r'.$matches[1].'">r'.$matches[1].'</a>');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,15 @@ abstract class PhabricatorRemarkupRuleObjectName
|
||||||
|
|
||||||
abstract protected function getObjectNamePrefix();
|
abstract protected function getObjectNamePrefix();
|
||||||
|
|
||||||
|
protected function getObjectIDPattern() {
|
||||||
|
return '[1-9]\d*';
|
||||||
|
}
|
||||||
|
|
||||||
public function apply($text) {
|
public function apply($text) {
|
||||||
$prefix = $this->getObjectNamePrefix();
|
$prefix = $this->getObjectNamePrefix();
|
||||||
|
$id = $this->getObjectIDPattern();
|
||||||
return preg_replace_callback(
|
return preg_replace_callback(
|
||||||
"@\b({$prefix})([1-9]\d*)(?:#([-\w\d]+))?\b@",
|
"@\b({$prefix})({$id})(?:#([-\w\d]+))?\b@",
|
||||||
array($this, 'markupObjectNameLink'),
|
array($this, 'markupObjectNameLink'),
|
||||||
$text);
|
$text);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue