mirror of
https://github.com/flextype/flextype.git
synced 2025-08-20 11:51:28 +02:00
53
flextype/twig/MarkdownTwigExtension.php
Normal file
53
flextype/twig/MarkdownTwigExtension.php
Normal 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 '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user