KnpMarkdownBundle/README.markdown

81 lines
2.4 KiB
Markdown
Raw Normal View History

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-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/):
```
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`.
2016-05-04 20:39:37 +02:00
Next, register the bundle in ``app/AppKernel.php``
```php
$bundles = array(
// ...
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
);
```
2010-05-05 18:38:36 +02:00
## USAGE
```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
// 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
```twig
{# Use default parser #}
{{ my_data|markdown }}
{# Or select specific parser #}
{{ my_data|markdown('parserName') }}
```
2010-09-19 21:05:36 +02:00
## Change the parser implementation
Create a service implementing `Knp\Bundle\MarkdownBundle\MarkdownParserInterface`,
then configure the bundle to use it:
```yaml
knp_markdown:
parser:
service: my.markdown.parser
```
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:
- 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-16 10:52:58 +02:00
``markdown.parser.sundown`` requires the [php sundown extension](https://github.com/chobie/php-sundown).
For more details, see the implementations in Parser/Preset.
2010-07-22 12:06:54 +02:00
## TEST
phpunit -c myapp vendor/bundles/Knp/Bundle/MarkdownBundle