mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Allow Phriction [[links]] to link to non-Phriction URIs
Summary: If the link text is a URI, just treat it as a nameable (and possibly relative) URI link. See tasks. Test Plan: Copy/pasted the doc example into Phriction, links worked. Reviewers: skrul, hunterbridges, jungejason, tuomaspelkonen, aran Reviewed By: jungejason CC: aran, jungejason Differential Revision: 882
This commit is contained in:
parent
c544f78015
commit
0e40b3c5b2
2 changed files with 21 additions and 5 deletions
|
@ -187,3 +187,9 @@ With a pipe (##|##), you can retitle the link. Use this to mislead your
|
||||||
opponents:
|
opponents:
|
||||||
|
|
||||||
Check out these [[legal/boring_documents/ | exciting legal documents]]!
|
Check out these [[legal/boring_documents/ | exciting legal documents]]!
|
||||||
|
|
||||||
|
You can also use this as an explicit syntax for other web links, either within
|
||||||
|
Phabricator or on the internet at large:
|
||||||
|
|
||||||
|
[[/herald/transcript/ | Herald Transcripts]]
|
||||||
|
[[http://www.boring-legal-documents.com/ | exciting legal documents]]
|
|
@ -33,18 +33,28 @@ class PhabricatorRemarkupRulePhriction
|
||||||
|
|
||||||
$slug = trim($matches[1]);
|
$slug = trim($matches[1]);
|
||||||
$name = trim(idx($matches, 2, $slug));
|
$name = trim(idx($matches, 2, $slug));
|
||||||
$name = explode('/', $name);
|
|
||||||
$name = end($name);
|
|
||||||
|
|
||||||
$slug = PhrictionDocument::normalizeSlug($slug);
|
// If whatever is being linked to begins with "/" or has "://", treat it
|
||||||
$uri = PhrictionDocument::getSlugURI($slug);
|
// as a URI instead of a wiki page.
|
||||||
|
$is_uri = preg_match('@(^/)|(://)@', $slug);
|
||||||
|
if ($is_uri) {
|
||||||
|
$uri = $slug;
|
||||||
|
// Leave the name unchanged, i.e. link the whole URI if there's no
|
||||||
|
// explicit name.
|
||||||
|
} else {
|
||||||
|
$name = explode('/', trim($name, '/'));
|
||||||
|
$name = end($name);
|
||||||
|
|
||||||
|
$slug = PhrictionDocument::normalizeSlug($slug);
|
||||||
|
$uri = PhrictionDocument::getSlugURI($slug);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->getEngine()->storeText(
|
return $this->getEngine()->storeText(
|
||||||
phutil_render_tag(
|
phutil_render_tag(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
'href' => $uri,
|
'href' => $uri,
|
||||||
'class' => 'phriction-link',
|
'class' => $is_uri ? null : 'phriction-link',
|
||||||
),
|
),
|
||||||
phutil_escape_html($name)));
|
phutil_escape_html($name)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue