1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-20 11:51:28 +02:00

Flextype Core: Markdown parser #212 #186

- Add Markdown service
This commit is contained in:
Awilum
2019-08-11 19:31:50 +03:00
parent ce471d9b9a
commit 92c777ed4b

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/**
* Flextype (http://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype;
use Twig_Extension;
use Twig_SimpleFilter;
class MarkdownTwigExtension extends Twig_Extension
{
/**
* Flextype Dependency Container
*/
private $flextype;
/**
* Constructor
*/
public function __construct($flextype)
{
$this->flextype = $flextype;
}
/**
* Returns a list of filters to add to the existing list.
*
* @return array
*/
public function getFilters() : array
{
return [
new Twig_SimpleFilter('markdown', [$this, 'markdown']),
];
}
/**
* Markdown process
*/
public function markdown($value) : string
{
if ($value !== null) {
return $this->flextype->markdown->text($value);
}
return '';
}
}