mheap / silex-markdown
Markdown extension for Silex
Installs: 2 920
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: >=7.0.0
- knplabs/knp-markdown-bundle: ^1.5
Requires (Dev)
- phpunit/phpunit: ^6
- silex/silex: ~2.0
- squizlabs/php_codesniffer: ^3.1
- twig/twig: >=1.2.0
This package is auto-updated.
Last update: 2020-11-26 18:29:45 UTC
README
Requirements
This extension only works with PHP 7.1+ and Silex 2. Version 1.0.0 is compatible with Silex 1.
Installation
Install with composer:
composer require mheap/silex-markdown
Usage
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 }}
Running the tests
There are no external dependencies for this library. Just composer install
then run ./vendor/bin/phpunit