public static isLinkPotentiallyUnsafe ( string $url ) : boolean | ||
$url | string | |
리턴 | boolean |
/** * @param Link $inline * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { if (!$inline instanceof Link) { throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); } $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } if (!($this->config->getConfig('safe') && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl()))) { $attrs['href'] = $htmlRenderer->escape($inline->getUrl(), true); } if (isset($inline->data['title'])) { $attrs['title'] = $htmlRenderer->escape($inline->data['title'], true); } return new HtmlElement('a', $attrs, $htmlRenderer->renderInlines($inline->children())); }
private function buildLink($inline, $htmlRenderer) { $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } if (!($this->config->getConfig('safe') && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl()))) { $attrs['href'] = $htmlRenderer->escape($inline->getUrl(), true); } if (isset($inline->data['title'])) { $attrs['title'] = $htmlRenderer->escape($inline->data['title'], true); } if ($this->isExternalUrl($inline->getUrl())) { $attrs['rel'] = 'nofollow'; $attrs['target'] = '_blank'; } return new HtmlElement('a', $attrs, $htmlRenderer->renderInlines($inline->children())); }
/** * @param Image $inline * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { if (!$inline instanceof Image) { throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); } $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } if ($this->config->getConfig('safe') && RegexHelper::isLinkPotentiallyUnsafe($inline->getUrl())) { $attrs['src'] = ''; } else { $attrs['src'] = $htmlRenderer->escape($inline->getUrl(), true); } $alt = $htmlRenderer->renderInlines($inline->children()); $alt = preg_replace('/\\<[^>]*alt="([^"]*)"[^>]*\\>/', '$1', $alt); $attrs['alt'] = preg_replace('/\\<[^>]*\\>/', '', $alt); if (isset($inline->data['title'])) { $attrs['title'] = $htmlRenderer->escape($inline->data['title'], true); } return new HtmlElement('img', $attrs, '', true); }