This extension only works with PHP 7.1+ and Silex 2. Version 1.0.0 is compatible with Silex 1.
Install with composer:
composer require mheap/silex-markdown
First, you need to register the Markdown extension. This will use the default settings for the extension.
$app->register(new \SilexMarkdown\MarkdownExtension());
If you'd like to disable certain transformations, you can provide them when registering the extension. This will not convert headers from markdown to HTML.
$app->register(new MarkdownExtension(), array(
'markdown.features' => array(
'header' => false,
)
));
To render markdown, use $app['markdown']
:
$app->get('/', function() use($app) {
$html = $app['markdown']->transform('# Hello World'); // <h1>Hello World</h1>
});
If you're using Twig via Silex\Provider\TwigServiceProvider()
, a markdown
filter will
be automatically registered for you. This allows you do do the following:
// In your route
$app->get('/', function() use($app) {
$text = '# Hello World';
$html = $app['twig']->render('example.twig', array(
'input' => $text
));
});
// In your twig file
{{ input | markdown }}
There are no external dependencies for this library. Just composer install
then run ./vendor/bin/phpunit