daux.io/libs/Format/Confluence/IndentedCodeRenderer.php
Stéphane Goetz 1fe3e62df3 Improve confluence export
Migrate from Parsedown to Commonmark
2015-07-20 20:49:19 +02:00

31 lines
1017 B
PHP

<?php namespace Todaymade\Daux\Format\Confluence;
use League\CommonMark\Block\Element\AbstractBlock;
use League\CommonMark\Block\Element\IndentedCode;
use League\CommonMark\Block\Renderer\BlockRendererInterface;
use League\CommonMark\HtmlElement;
use League\CommonMark\HtmlRendererInterface;
class IndentedCodeRenderer implements BlockRendererInterface
{
/**
* @param AbstractBlock $block
* @param HtmlRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement
*/
public function render(AbstractBlock $block, HtmlRendererInterface $htmlRenderer, $inTightList = false)
{
if (!($block instanceof IndentedCode)) {
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
}
return new HtmlElement(
'ac:structured-macro',
['ac:name' => 'code'],
new HtmlElement('ac:plain-text-body', [], '<![CDATA['.$block->getStringContent().']]>')
);
}
}