getCurrentPage() public méthode

public getCurrentPage ( )
Exemple #1
0
 /**
  * @param AbstractInline|Link $inline
  * @param ElementRendererInterface $htmlRenderer
  * @return HtmlElement
  * @throws Exception
  */
 public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
 {
     // This can't be in the method type as
     // the method is an abstract and should
     // have the same interface
     if (!$inline instanceof Link) {
         throw new \RuntimeException('Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ . " the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" . get_class($inline) . "' was provided");
     }
     $element = parent::render($inline, $htmlRenderer);
     $url = $inline->getUrl();
     // Absolute urls, empty urls and anchors
     // should not go through the url resolver
     if (empty($url) || $url[0] == '#' || preg_match('|^(?:[a-z]+:)?//|', $url)) {
         return $element;
     }
     $file = $this->resolveInternalFile($url);
     $url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl());
     $element->setAttribute('href', $url);
     return $element;
 }
Exemple #2
0
 /**
  * @param AbstractInline|Link $inline
  * @param ElementRendererInterface $htmlRenderer
  * @return HtmlElement
  * @throws LinkNotFoundException
  */
 public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
 {
     // This can't be in the method type as
     // the method is an abstract and should
     // have the same interface
     if (!$inline instanceof Link) {
         throw new \RuntimeException('Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ . " the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" . get_class($inline) . "' was provided");
     }
     $element = parent::render($inline, $htmlRenderer);
     $url = $inline->getUrl();
     // empty urls and anchors should
     // not go through the url resolver
     if (!$this->isValidUrl($url)) {
         return $element;
     }
     // Absolute urls, shouldn't either
     if ($this->isExternalUrl($url)) {
         $element->setAttribute('class', 'external');
         return $element;
     }
     // if there's a hash component in the url, ensure we
     // don't put that part through the resolver.
     $urlAndHash = explode('#', $url);
     $url = $urlAndHash[0];
     try {
         $file = $this->resolveInternalFile($url);
         $url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl());
     } catch (LinkNotFoundException $e) {
         if ($this->daux->isStatic()) {
             throw $e;
         }
         $element->setAttribute('class', 'broken');
     }
     if (isset($urlAndHash[1])) {
         $url .= '#' . $urlAndHash[1];
     }
     $element->setAttribute('href', $url);
     return $element;
 }