Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/markup/PhrictionRemarkupRule.php
| Show All 9 Lines | public function apply($text) { | ||||
| return preg_replace_callback( | return preg_replace_callback( | ||||
| '@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U', | '@\B\\[\\[([^|\\]]+)(?:\\|([^\\]]+))?\\]\\]\B@U', | ||||
| array($this, 'markupDocumentLink'), | array($this, 'markupDocumentLink'), | ||||
| $text); | $text); | ||||
| } | } | ||||
| public function markupDocumentLink(array $matches) { | public function markupDocumentLink(array $matches) { | ||||
| $link = trim($matches[1]); | $link = trim($matches[1]); | ||||
| // Handle relative links. | |||||
| if (substr($link, 0, 2) === './') { | |||||
epriestley: This could go elsewhere, but `../x/y` is probably fine to trigger this too. | |||||
Not Done Inline ActionsI'll leave this as-is for now and we can update it later if people expect it to work (because easier to add a Remarkup rule later than remove them). hach-que: I'll leave this as-is for now and we can update it later if people expect it to work (because… | |||||
| $base = null; | |||||
| $context = $this->getEngine()->getConfig('contextObject'); | |||||
| if ($context !== null && $context instanceof PhrictionContent) { | |||||
| // Handle content when it's being rendered in document view. | |||||
| $base = $context->getSlug(); | |||||
| } | |||||
| if ($context !== null && is_array($context) && | |||||
| idx($context, 'phriction.isPreview')) { | |||||
| // Handle content when it's a preview for the Phriction editor. | |||||
| $base = idx($context, 'phriction.slug'); | |||||
| } | |||||
| if ($base !== null) { | |||||
| $base_parts = explode('/', rtrim($base, '/')); | |||||
| $rel_parts = explode('/', substr(rtrim($link, '/'), 2)); | |||||
| foreach ($rel_parts as $part) { | |||||
| if ($part === '.') { | |||||
Not Done Inline ActionsConsider structuring this more explicitly to improve clarity. epriestley: Consider structuring this more explicitly to improve clarity. | |||||
Not Done Inline ActionsI think the linter ate the newlines here. I'll throw in a comment to stop it condensing this block (but also explain the treatment of .). hach-que: I think the linter ate the newlines here. I'll throw in a comment to stop it condensing this… | |||||
| // Consume standalone dots in a relative path, and do | |||||
| // nothing with them. | |||||
| } else if ($part === '..') { | |||||
| if (count($base_parts) > 0) { | |||||
| array_pop($base_parts); | |||||
| } | |||||
| } else { | |||||
| array_push($base_parts, $part); | |||||
| } | |||||
| } | |||||
| $link = implode('/', $base_parts).'/'; | |||||
| } | |||||
| } | |||||
| $name = trim(idx($matches, 2, $link)); | $name = trim(idx($matches, 2, $link)); | ||||
| if (empty($matches[2])) { | if (empty($matches[2])) { | ||||
| $name = explode('/', trim($name, '/')); | $name = explode('/', trim($name, '/')); | ||||
| $name = end($name); | $name = end($name); | ||||
| } | } | ||||
| $uri = new PhutilURI($link); | $uri = new PhutilURI($link); | ||||
| $slug = $uri->getPath(); | $slug = $uri->getPath(); | ||||
| Show All 26 Lines | |||||
This could go elsewhere, but ../x/y is probably fine to trigger this too.