2015-10-27 16:03:58 +01:00
|
|
|
<?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;
|
2019-11-28 22:36:26 +01:00
|
|
|
use League\CommonMark\Util\ConfigurationAwareInterface;
|
|
|
|
use League\CommonMark\Util\ConfigurationInterface;
|
2015-10-27 16:03:58 +01:00
|
|
|
|
2019-11-28 22:36:26 +01:00
|
|
|
class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
2015-10-27 16:03:58 +01:00
|
|
|
{
|
2019-11-28 22:36:26 +01:00
|
|
|
/**
|
|
|
|
* @var ConfigurationInterface
|
|
|
|
*/
|
|
|
|
protected $config;
|
|
|
|
|
2019-11-28 23:32:33 +01:00
|
|
|
/**
|
2019-11-28 23:41:53 +01:00
|
|
|
* @var \League\CommonMark\Inline\Renderer\ImageRenderer
|
2019-11-28 23:32:33 +01:00
|
|
|
*/
|
|
|
|
protected $parent;
|
|
|
|
|
2019-11-28 22:36:26 +01:00
|
|
|
public function __construct() {
|
|
|
|
$this->parent = new \League\CommonMark\Inline\Renderer\ImageRenderer();
|
|
|
|
}
|
|
|
|
|
2015-10-27 16:03:58 +01:00
|
|
|
/**
|
|
|
|
* @param Image $inline
|
|
|
|
* @param ElementRendererInterface $htmlRenderer
|
|
|
|
*
|
|
|
|
* @return HtmlElement
|
|
|
|
*/
|
|
|
|
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
|
|
|
{
|
2016-07-29 22:38:03 +02:00
|
|
|
if (!($inline instanceof Image)) {
|
|
|
|
throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline));
|
|
|
|
}
|
|
|
|
|
2015-10-27 16:03:58 +01:00
|
|
|
// External Images need special handling
|
|
|
|
if (strpos($inline->getUrl(), 'http') === 0) {
|
2015-11-06 22:44:34 +01:00
|
|
|
return new HtmlElement(
|
|
|
|
'ac:image',
|
|
|
|
[],
|
|
|
|
new HtmlElement('ri:url', ['ri:value' => $inline->getUrl()])
|
|
|
|
);
|
2015-10-27 16:03:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::render($inline, $htmlRenderer);
|
|
|
|
}
|
2019-11-28 22:36:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ConfigurationInterface $configuration
|
|
|
|
*/
|
|
|
|
public function setConfiguration(ConfigurationInterface $configuration)
|
|
|
|
{
|
|
|
|
$this->parent->setConfiguration($configuration);
|
|
|
|
}
|
2015-10-27 16:03:58 +01:00
|
|
|
}
|