SHARE
TWEET

MarkdownExtension.php

eniine Aug 26th, 2017 32 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: eni
  5.  * Date: 17-08-25
  6.  * Time: 8.47.MD
  7.  */
  8.  
  9. namespace AppBundle\Twig;
  10.  
  11. use AppBundle\Service\MarkdownTransformer;
  12.  
  13.  
  14. class MarkdownExtension extends \Twig_Extension
  15. {
  16.     private $markdownTransformer;
  17.  
  18.     public function __construct(MarkdownTransformer $markdownTransformer)
  19.     {
  20.         $this->markdownTransformer = $markdownTransformer;
  21.     }
  22.  
  23.     public function getFilters()
  24.     {
  25.         return [
  26.             new \Twig_SimpleFilter('markdownify', array($this, 'parseMarkdown'), [
  27.                 'is_safe' => ['html']
  28.             ])
  29.         ];
  30.     }
  31.  
  32.     public function parseMarkdown($str)
  33.     {
  34.         return $this->markdownTransformer->parse($str);
  35.     }
  36.  
  37.     public function getName()
  38.     {
  39.         return 'app_markdown';
  40.  
  41.  
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top