2010-09-19 21:05:36 +02:00
|
|
|
<?php
|
|
|
|
|
2011-07-03 11:28:55 +02:00
|
|
|
namespace Knp\Bundle\MarkdownBundle\Twig\Extension;
|
2010-09-19 21:05:36 +02:00
|
|
|
|
2011-07-03 11:28:55 +02:00
|
|
|
use Knp\Bundle\MarkdownBundle\Helper\MarkdownHelper;
|
2010-09-19 21:05:36 +02:00
|
|
|
|
|
|
|
class MarkdownTwigExtension extends \Twig_Extension
|
|
|
|
{
|
|
|
|
protected $helper;
|
|
|
|
|
2015-08-19 15:51:52 +02:00
|
|
|
public function __construct(MarkdownHelper $helper)
|
2010-09-19 21:05:36 +02:00
|
|
|
{
|
|
|
|
$this->helper = $helper;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFilters()
|
|
|
|
{
|
|
|
|
return array(
|
2015-08-20 12:49:40 +02:00
|
|
|
new \Twig_SimpleFilter('markdown', array($this, 'markdown'), array('is_safe' => array('html'))),
|
2010-09-19 21:05:36 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
public function markdown($text, $parser = null)
|
2010-09-19 21:05:36 +02:00
|
|
|
{
|
2012-10-15 12:24:11 +02:00
|
|
|
return $this->helper->transform($text, $parser);
|
2010-09-19 21:05:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'markdown';
|
|
|
|
}
|
|
|
|
}
|