/** * @param Paragraph $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement|string */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof Paragraph) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } if ($inTightList) { return $htmlRenderer->renderInlines($block->getInlines()); } else { return new HtmlElement('p', [], $htmlRenderer->renderInlines($block->getInlines())); } }
/** * @param Paragraph $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement|string */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof Paragraph) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } if ($inTightList) { return $htmlRenderer->renderInlines($block->children()); } else { $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } return new HtmlElement('p', $attrs, $htmlRenderer->renderInlines($block->children())); } }
/** * @param Emphasis $inline * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { if (!$inline instanceof Emphasis) { throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); } return new HtmlElement('em', [], $htmlRenderer->renderInlines($inline->getChildren())); }
/** * {@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())); }
/** * @param Strong $inline * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { if (!$inline instanceof Strong) { throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); } $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } return new HtmlElement('strong', $attrs, $htmlRenderer->renderInlines($inline->children())); }
/** * @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 = []; $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->getChildren())); }
/** * @param Header $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof Header) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $tag = 'h' . $block->getLevel(); $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } return new HtmlElement($tag, $attrs, $htmlRenderer->renderInlines($block->getInlines())); }
/** * @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 = []; $attrs['src'] = $htmlRenderer->escape($inline->getUrl(), true); $alt = $htmlRenderer->renderInlines($inline->getChildren()); $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); }
/** * @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())); }
/** * @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); }