/** * {@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 FencedCode $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof FencedCode) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $infoWords = $block->getInfoWords(); $attr = count($infoWords) === 0 || strlen($infoWords[0]) === 0 ? [] : ['class' => 'language-' . $htmlRenderer->escape($infoWords[0], true)]; return new HtmlElement('pre', [], new HtmlElement('code', $attr, $htmlRenderer->escape($block->getStringContent()))); }
/** * @param AbstractBlock $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof IndentedCode) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } return new HtmlElement('pre', [], new HtmlElement('code', $attrs, $htmlRenderer->escape($block->getStringContent()))); }
/** * @param Code $inline * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { if (!$inline instanceof Code) { 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('code', $attrs, $htmlRenderer->escape($inline->getContent())); }
/** * @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 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 FencedCode $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof FencedCode) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } $infoWords = $block->getInfoWords(); if (count($infoWords) !== 0 && strlen($infoWords[0]) !== 0) { $attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' : ''; $attrs['class'] .= 'language-' . $htmlRenderer->escape($infoWords[0], true); } return new HtmlElement('pre', [], new HtmlElement('code', $attrs, $htmlRenderer->escape($block->getStringContent()))); }
/** * @param Text $inline * @param ElementRendererInterface $htmlRenderer * * @return string */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { if (!$inline instanceof Text) { throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); } return $htmlRenderer->escape($inline->getContent()); }
/** * @param AbstractBlock $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof IndentedCode) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } return new HtmlElement('pre', [], new HtmlElement('code', [], $htmlRenderer->escape($block->getStringContent()))); }
/** * @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())); }
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof TableRow) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } $separator = $htmlRenderer->getOption('inner_separator', "\n"); return new HtmlElement('tr', $attrs, $separator . $htmlRenderer->renderBlocks($block->children()) . $separator); }
/** * @param Heading $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof Heading) { 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->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); }
public function getLanguage($infoWords, ElementRendererInterface $htmlRenderer) { if (count($infoWords) === 0 || strlen($infoWords[0]) === 0) { return false; } $language = $htmlRenderer->escape($infoWords[0], true); if (array_key_exists($language, $this->known_conversions)) { $language = $this->known_conversions[$language]; } if (in_array($language, $this->supported_languages)) { return $language; } return false; }
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof TableCell) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } if ($block->align) { $attrs['align'] = $block->align; } return new HtmlElement($block->type, $attrs, $htmlRenderer->renderInlines($block->getInlines())); }
/** * @param ListBlock $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof ListBlock) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $listData = $block->getListData(); $tag = $listData->type === ListBlock::TYPE_UNORDERED ? 'ul' : 'ol'; $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } if ($listData->start !== null && $listData->start !== 1) { $attrs['start'] = (string) $listData->start; } return new HtmlElement($tag, $attrs, $htmlRenderer->getOption('inner_separator', "\n") . $htmlRenderer->renderBlocks($block->getChildren(), $block->isTight()) . $htmlRenderer->getOption('inner_separator', "\n")); }
/** * @param AbstractInline $inline * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { if (!$inline instanceof TaskListsCheckbox) { throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline)); } $attrs = []; foreach ($inline->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } $attrs['type'] = 'checkbox'; $attrs['disabled'] = ''; if ($inline->isChecked()) { $attrs['checked'] = 'checked'; } return new HtmlElement('input', $attrs); }
/** * @param ListItem $block * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return string */ public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false) { if (!$block instanceof ListItem) { throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } $contents = $htmlRenderer->renderBlocks($block->children(), $inTightList); if (substr($contents, 0, 1) === '<') { $contents = "\n" . $contents; } if (substr($contents, -1, 1) === '>') { $contents .= "\n"; } $attrs = []; foreach ($block->getData('attributes', []) as $key => $value) { $attrs[$key] = $htmlRenderer->escape($value, true); } $li = new HtmlElement('li', $attrs, $contents); return $li; }