Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/markup/PhrictionRemarkupRule.php
| Show All 10 Lines | final class PhrictionRemarkupRule extends PhutilRemarkupRule { | ||||
| public function apply($text) { | 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]); | // If the link contains an anchor, separate that off first. | ||||
| $parts = explode('#', trim($matches[1]), 2); | |||||
| if (count($parts) == 2) { | |||||
| $link = $parts[0]; | |||||
| $anchor = $parts[1]; | |||||
| } else { | |||||
| $link = $parts[0]; | |||||
| $anchor = null; | |||||
| } | |||||
| // Handle relative links. | // Handle relative links. | ||||
| if ((substr($link, 0, 2) === './') || (substr($link, 0, 3) === '../')) { | if ((substr($link, 0, 2) === './') || (substr($link, 0, 3) === '../')) { | ||||
| $base = null; | $base = null; | ||||
| $context = $this->getEngine()->getConfig('contextObject'); | $context = $this->getEngine()->getConfig('contextObject'); | ||||
| if ($context !== null && $context instanceof PhrictionContent) { | if ($context !== null && $context instanceof PhrictionContent) { | ||||
| // Handle content when it's being rendered in document view. | // Handle content when it's being rendered in document view. | ||||
| $base = $context->getSlug(); | $base = $context->getSlug(); | ||||
| Show All 34 Lines | public function markupDocumentLink(array $matches) { | ||||
| $engine = $this->getEngine(); | $engine = $this->getEngine(); | ||||
| $token = $engine->storeText('x'); | $token = $engine->storeText('x'); | ||||
| $metadata = $engine->getTextMetadata( | $metadata = $engine->getTextMetadata( | ||||
| self::KEY_RULE_PHRICTION_LINK, | self::KEY_RULE_PHRICTION_LINK, | ||||
| array()); | array()); | ||||
| $metadata[] = array( | $metadata[] = array( | ||||
| 'token' => $token, | 'token' => $token, | ||||
| 'link' => $link, | 'link' => $link, | ||||
| 'anchor' => $anchor, | |||||
| 'explicitName' => $name, | 'explicitName' => $name, | ||||
| ); | ); | ||||
| $engine->setTextMetadata(self::KEY_RULE_PHRICTION_LINK, $metadata); | $engine->setTextMetadata(self::KEY_RULE_PHRICTION_LINK, $metadata); | ||||
| return $token; | return $token; | ||||
| } | } | ||||
| public function didMarkupText() { | public function didMarkupText() { | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | foreach ($metadata as $spec) { | ||||
| $name = $visible_documents[$slug] | $name = $visible_documents[$slug] | ||||
| ->getContent() | ->getContent() | ||||
| ->getTitle(); | ->getTitle(); | ||||
| $is_interesting_name = true; | $is_interesting_name = true; | ||||
| } | } | ||||
| } | } | ||||
| $uri = new PhutilURI($link); | $uri = new PhutilURI($link); | ||||
| $slug = $uri->getPath(); | $slug = $uri->getPath(); | ||||
| $fragment = $uri->getFragment(); | |||||
| $slug = PhabricatorSlug::normalize($slug); | $slug = PhabricatorSlug::normalize($slug); | ||||
| $slug = PhrictionDocument::getSlugURI($slug); | $slug = PhrictionDocument::getSlugURI($slug); | ||||
| $href = (string)id(new PhutilURI($slug))->setFragment($fragment); | |||||
| $anchor = idx($spec, 'anchor'); | |||||
| $href = (string)id(new PhutilURI($slug))->setFragment($anchor); | |||||
| $text_mode = $this->getEngine()->isTextMode(); | $text_mode = $this->getEngine()->isTextMode(); | ||||
| $mail_mode = $this->getEngine()->isHTMLMailMode(); | $mail_mode = $this->getEngine()->isHTMLMailMode(); | ||||
| if ($this->getEngine()->getState('toc')) { | if ($this->getEngine()->getState('toc')) { | ||||
| $text = $name; | $text = $name; | ||||
| } else if ($text_mode || $mail_mode) { | } else if ($text_mode || $mail_mode) { | ||||
| $href = PhabricatorEnv::getProductionURI($href); | $href = PhabricatorEnv::getProductionURI($href); | ||||
| Show All 32 Lines | |||||