1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 10:52:41 +01:00
phorge-phorge/src/infrastructure/markup/rule/PhabricatorRemarkupRulePhriction.php

41 lines
992 B
PHP
Raw Normal View History

<?php
/**
* @group markup
*/
final class PhabricatorRemarkupRulePhriction
extends PhutilRemarkupRule {
public function apply($text) {
return preg_replace_callback(
'@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U',
array($this, 'markupDocumentLink'),
$text);
}
public function markupDocumentLink($matches) {
$link = trim($matches[1]);
$name = trim(idx($matches, 2, $link));
$name = explode('/', trim($name, '/'));
$name = end($name);
$uri = new PhutilURI($link);
$slug = $uri->getPath();
$fragment = $uri->getFragment();
$slug = PhabricatorSlug::normalize($slug);
$slug = PhrictionDocument::getSlugURI($slug);
$href = (string) id(new PhutilURI($slug))->setFragment($fragment);
return $this->getEngine()->storeText(
phutil_render_tag(
'a',
array(
'href' => $href,
'class' => 'phriction-link',
),
phutil_escape_html($name)));
}
}