Extension.php in Markdown 3.0.x
File
src/Twig/Markdown/Extension.php
View source
<?php
namespace Drupal\markdown\Twig\Markdown;
use Drupal\markdown\MarkdownInterface;
class Extension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface {
protected $markdown;
public function __construct(MarkdownInterface $markdown) {
$this->markdown = $markdown;
}
public function getName() {
return 'markdown';
}
public function getGlobals() {
return [
'markdown' => $this->markdown,
];
}
public function getFilters() {
return [
'markdown' => new \Twig_SimpleFilter('markdown', [
$this,
'parse',
], [
'is_safe' => [
'html',
],
]),
];
}
public function getFunctions() {
return [
'markdown' => new \Twig_SimpleFunction('markdown', [
$this,
'parse',
], [
'is_safe' => [
'html',
],
]),
];
}
public function getTokenParsers() {
return [
new TokenParser($this->markdown),
];
}
public function parse($markdown) {
return $this->markdown
->getParser()
->parse($markdown);
}
}