-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSmartyPantsTwigExtension.php
53 lines (42 loc) · 1.49 KB
/
SmartyPantsTwigExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Grav\Plugin;
use \Grav\Common\Grav;
class SmartyPantsTwigExtension extends \Twig_Extension
{
protected $config;
public function __construct()
{
$this->config = Grav::instance()['config'];
}
/**
* Returns extension name.
*
* @return string
*/
public function getName()
{
return 'SmartyPantsTwigExtension';
}
public function getFilters()
{
return [
new \Twig_SimpleFilter('smartypants', [$this, 'smartypantsFilter']),
];
}
public function smartypantsFilter($content, $options = null)
{
if (!$options) {
$options = $this->config->get('plugins.smartypants.options');
}
$smartypants = new \Michelf\SmartyPantsTypographer($options);
if ($this->config->get('plugins.smartypants.dq_open'))
$smartypants->smart_doublequote_open = $this->config->get('plugins.smartypants.dq_open');
if ($this->config->get('plugins.smartypants.dq_close'))
$smartypants->smart_doublequote_close = $this->config->get('plugins.smartypants.dq_close');
if ($this->config->get('plugins.smartypants.sq_open'))
$smartypants->smart_singlequote_open = $this->config->get('plugins.smartypants.sq_open');
if ($this->config->get('plugins.smartypants.sq_close'))
$smartypants->smart_singlequote_close = $this->config->get('plugins.smartypants.sq_close');
return $smartypants->transform($content);
}
}