1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Add some useful renderables

This commit is contained in:
Aidan Woods 2019-01-20 02:18:08 +00:00
parent c852b487b4
commit 072f91df47
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
3 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,47 @@
<?php
namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
final class Container implements Renderable
{
use CanonicalStateRenderable;
/** @var Renderable[] */
private $Contents;
/**
* @param Renderable[] $Contents
*/
public function __construct($Contents)
{
$this->Contents = $Contents;
}
/**
* @return Renderable[]
*/
public function contents()
{
return $this->Contents;
}
/** @return string */
public function getHtml()
{
return \array_reduce(
$this->Contents,
/**
* @param string $html
* @param Renderable $Renderable
* @return string
*/
function ($html, Renderable $Renderable) {
return $html . $Renderable->getHtml();
},
''
);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
final class Invisible implements Renderable
{
use CanonicalStateRenderable;
public function __construct()
{
}
/** @return string */
public function getHtml()
{
return '';
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
final class RawHtml implements Renderable
{
use CanonicalStateRenderable;
/** @var string */
private $html;
/**
* @param string $html
*/
public function __construct($html = '')
{
$this->html = $html;
}
/** @return string */
public function getHtml()
{
return $this->html;
}
}