58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php namespace Todaymade\Daux\Format\Confluence\ContentTypes\Markdown;
|
|
|
|
use League\CommonMark\ElementRendererInterface;
|
|
use League\CommonMark\HtmlElement;
|
|
use League\CommonMark\Inline\Element\AbstractInline;
|
|
use League\CommonMark\Inline\Element\Image;
|
|
use League\CommonMark\Util\ConfigurationAwareInterface;
|
|
use League\CommonMark\Util\ConfigurationInterface;
|
|
|
|
class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
|
{
|
|
/**
|
|
* @var ConfigurationInterface
|
|
*/
|
|
protected $config;
|
|
|
|
/**
|
|
* @var \League\CommonMark\Inline\Renderer\LinkRenderer
|
|
*/
|
|
protected $parent;
|
|
|
|
public function __construct() {
|
|
$this->parent = new \League\CommonMark\Inline\Renderer\ImageRenderer();
|
|
}
|
|
|
|
/**
|
|
* @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));
|
|
}
|
|
|
|
// External Images need special handling
|
|
if (strpos($inline->getUrl(), 'http') === 0) {
|
|
return new HtmlElement(
|
|
'ac:image',
|
|
[],
|
|
new HtmlElement('ri:url', ['ri:value' => $inline->getUrl()])
|
|
);
|
|
}
|
|
|
|
return parent::render($inline, $htmlRenderer);
|
|
}
|
|
|
|
/**
|
|
* @param ConfigurationInterface $configuration
|
|
*/
|
|
public function setConfiguration(ConfigurationInterface $configuration)
|
|
{
|
|
$this->parent->setConfiguration($configuration);
|
|
}
|
|
}
|