mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-13 18:32:41 +01:00
5b1d73e5dd
Summary: use PhutilURI class to get the slug and the fragment, normalize the slug, and then glue it back together with another PhutilURI fixes https://github.com/facebook/phabricator/issues/228 Test Plan: had a few links like [[ example/doc#title | wiki fun ]] and verified links generated were correct Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3894
40 lines
992 B
PHP
40 lines
992 B
PHP
<?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)));
|
|
}
|
|
|
|
}
|