/twig-markdowner

Twig extension to turn Markdown formatted text into HTML

Primary LanguagePHP

TwigMarkdowner

Converts text with Markdown syntax into HTML in Twig templates.

Authors

Installation

  1. Add TwigMarkdowner to your dependencies

     // composer.json
    
     {
         // ...
         "require": {
             // ...
             "misd/twig-markdowner": "1.0.*"
         }
     }
    
  2. Use Composer to download and install TwigMarkdowner

     $ php composer.phar update misd/twig-markdowner
    
  3. Instantiate a MarkdownParser and add the extension to the Twig environment

     $parser = new \dflydev\markdown\MarkdownParser();
    
     /** @var $twig Twig_Environment */
     $twig->addExtension(new Misd\TwigMarkdowner\Twig\Extension\MarkdownerExtension($parser));
    

Usage

In a Twig template:

    {{ "My *Markdown* text"|markdown }}

or

    {{ object.property|markdown }}

Please note

This filter does not prevent the injection of arbitrary HTML and JavaScript; the output should be filtered (using HTMLPurifier, or equivalent) before being output in a template.