mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 21:17:16 +02:00
added a new markdown twig filter
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user