added a new markdown twig filter

This commit is contained in:
Andy Miller
2015-02-09 18:56:12 -07:00
parent d69a0a9b06
commit 5c139e4b3c

View File

@@ -1,6 +1,8 @@
<?php
namespace Grav\Common;
use Grav\Common\Markdown\Parsedown;
use Grav\Common\Markdown\ParsedownExtra;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
@@ -49,7 +51,8 @@ class TwigExtension extends \Twig_Extension
new \Twig_SimpleFilter('ksort', [$this,'ksortFilter']),
new \Twig_SimpleFilter('contains', [$this, 'containsFilter']),
new \Twig_SimpleFilter('nicetime', [$this, 'nicetimeFilter']),
new \Twig_SimpleFilter('absolute_url', [$this, 'absoluteUrlFilter'])
new \Twig_SimpleFilter('absolute_url', [$this, 'absoluteUrlFilter']),
new \Twig_SimpleFilter('markdown', [$this, 'markdownFilter'])
];
}
@@ -325,6 +328,23 @@ class TwigExtension extends \Twig_Extension
}
public function markdownFilter($string)
{
$page = $this->grav['page'];
$defaults = $this->grav['config']->get('system.pages.markdown');
// Initialize the preferred variant of Parsedown
if ($defaults['extra']) {
$parsedown = new ParsedownExtra($page);
} else {
$parsedown = new Parsedown($page);
}
$string = $parsedown->text($string);
return $string;
}
/**
* Repeat given string x times.
*