League\CommonMark\ElementRendererInterface::escape PHP Method

escape() public method

public escape ( string $string, boolean $preserveEntities = false ) : string
$string string
$preserveEntities boolean
return string
    public function escape($string, $preserveEntities = false);

Usage Example

 /**
  * {@inheritdoc}
  */
 public function render(AbstractInline $inline, ElementRendererInterface $html_renderer)
 {
     if (!$inline instanceof Link) {
         throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline));
     }
     $attributes = [];
     foreach ($inline->getData('attributes', []) as $key => $value) {
         $attributes[$key] = $html_renderer->escape($value, TRUE);
     }
     // Retrieve the URL.
     $url = $inline->getUrl();
     $external = $this->isExternalUrl($url);
     $attributes['href'] = $html_renderer->escape($url, TRUE);
     // Make external links open in a new window.
     if ($this->getSetting('external_new_window') && $external) {
         $attributes['target'] = '_blank';
     }
     // rel="nofollow"
     $no_follow = $this->getSetting('no_follow');
     if ($no_follow === 'all' || $external && $no_follow === 'external' || !$external && $no_follow === 'internal') {
         $attributes['rel'] = 'nofollow';
     }
     if (isset($inline->data['title'])) {
         $attributes['title'] = $html_renderer->escape($inline->data['title'], TRUE);
     }
     return new HtmlElement('a', $attributes, $html_renderer->renderInlines($inline->getChildren()));
 }
All Usage Examples Of League\CommonMark\ElementRendererInterface::escape