2015-05-05 11:36:51 +02:00
|
|
|
Provide markdown conversion (based on [Michel Fortin work](https://github.com/michelf/php-markdown)) to your Symfony2 projects.
|
2011-04-07 08:35:00 +02:00
|
|
|
|
2011-12-03 16:25:22 +01:00
|
|
|
[![Build Status](https://secure.travis-ci.org/KnpLabs/KnpMarkdownBundle.png)](http://travis-ci.org/KnpLabs/KnpMarkdownBundle)
|
2011-11-19 15:48:33 +01:00
|
|
|
|
2010-05-05 18:38:36 +02:00
|
|
|
## INSTALLATION
|
|
|
|
|
2016-05-04 20:39:37 +02:00
|
|
|
Add KnpMarkdownBundle to your project via [Composer](https://getcomposer.org/):
|
2011-08-25 02:54:09 +02:00
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
```
|
2016-05-04 20:39:37 +02:00
|
|
|
composer require knplabs/knp-markdown-bundle
|
|
|
|
```
|
|
|
|
|
|
|
|
Based on your Composer install, you might need to use `php composer.phar require knplabs/knp-markdown-bundle`.
|
2011-08-25 02:54:09 +02:00
|
|
|
|
2016-05-04 20:39:37 +02:00
|
|
|
Next, register the bundle in ``app/AppKernel.php``
|
2012-10-15 12:24:11 +02:00
|
|
|
|
|
|
|
```php
|
|
|
|
$bundles = array(
|
|
|
|
// ...
|
|
|
|
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
|
|
|
|
);
|
|
|
|
```
|
2010-05-05 18:38:36 +02:00
|
|
|
|
|
|
|
## USAGE
|
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
```php
|
|
|
|
// Use the service
|
|
|
|
$html = $this->container->get('markdown.parser')->transformMarkdown($text);
|
|
|
|
|
|
|
|
// Use the helper with default parser
|
|
|
|
echo $view['markdown']->transform($text);
|
2010-05-06 15:20:04 +02:00
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
// Use the helper and a select specific parser
|
|
|
|
echo $view['markdown']->transform($text, $parserName);
|
|
|
|
```
|
2010-07-22 12:06:54 +02:00
|
|
|
|
2012-10-04 18:42:02 +02:00
|
|
|
If you have enabled the Twig markdown filter, you can use the following in your Twig templates:
|
2010-09-19 21:05:36 +02:00
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
```twig
|
|
|
|
{# Use default parser #}
|
|
|
|
{{ my_data|markdown }}
|
|
|
|
|
|
|
|
{# Or select specific parser #}
|
|
|
|
{{ my_data|markdown('parserName') }}
|
|
|
|
```
|
2010-09-19 21:05:36 +02:00
|
|
|
|
2011-04-07 08:35:00 +02:00
|
|
|
## Change the parser implementation
|
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
Create a service implementing `Knp\Bundle\MarkdownBundle\MarkdownParserInterface`,
|
2011-04-07 08:35:00 +02:00
|
|
|
then configure the bundle to use it:
|
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
```yaml
|
|
|
|
knp_markdown:
|
|
|
|
parser:
|
|
|
|
service: my.markdown.parser
|
|
|
|
```
|
2011-04-07 08:35:00 +02:00
|
|
|
|
2012-10-10 18:01:45 +02:00
|
|
|
Alternatively if you are using the ``markdown.parser.sundown`` there are
|
|
|
|
options for enabling sundown extensions and render flags, see the
|
|
|
|
default Configuration with:
|
|
|
|
|
|
|
|
php app/console config:dump-reference knp_markdown
|
|
|
|
|
|
|
|
This bundle comes with 5 parser services, 4 based on the same algorithm
|
|
|
|
but providing different levels of compliance to the markdown specification,
|
|
|
|
and one which is uses the php sundown extension:
|
2011-04-07 08:35:00 +02:00
|
|
|
|
2012-10-15 12:24:11 +02:00
|
|
|
- markdown.parser.max // fully compliant = slower (default implementation)
|
|
|
|
- markdown.parser.medium // expensive and uncommon features dropped
|
|
|
|
- markdown.parser.light // expensive features dropped
|
|
|
|
- markdown.parser.min // most features dropped = faster
|
|
|
|
- markdown.parser.sundown // faster and fully compliant (recommended)
|
2012-10-10 18:01:45 +02:00
|
|
|
|
2012-10-16 10:52:58 +02:00
|
|
|
``markdown.parser.sundown`` requires the [php sundown extension](https://github.com/chobie/php-sundown).
|
2011-04-07 08:35:00 +02:00
|
|
|
|
|
|
|
For more details, see the implementations in Parser/Preset.
|
|
|
|
|
2010-07-22 12:06:54 +02:00
|
|
|
## TEST
|
|
|
|
|
2011-07-03 11:28:55 +02:00
|
|
|
phpunit -c myapp vendor/bundles/Knp/Bundle/MarkdownBundle
|