Go to file
Ryan Weaver 91a268692e Making the templating component an optional dependency
It already basically was, but we were requiring it.
2018-01-22 20:45:26 -05:00
DependencyInjection Making the templating component an optional dependency 2018-01-22 20:45:26 -05:00
Helper Making the templating component an optional dependency 2018-01-22 20:45:26 -05:00
Parser Merge pull request #82 from lunetics/master 2016-04-27 19:40:49 -05:00
Resources/config Fix bad argument on MardownHelper service 2016-05-03 10:18:39 +02:00
Tests Adding public alias and autowiring aliases 2017-11-29 13:29:54 -05:00
Twig/Extension Marking new service has private, then adding a workaround for the integration test 2015-12-16 10:54:17 -05:00
.gitignore removing unnecessary gitignore entry 2015-12-16 10:53:59 -05:00
.travis.yml removing support for 5.3, 5.4, hhvm 2017-11-29 13:11:20 -05:00
CHANGELOG.md Making the templating component an optional dependency 2018-01-22 20:45:26 -05:00
composer.json Making the templating component an optional dependency 2018-01-22 20:45:26 -05:00
KnpMarkdownBundle.php Removed hard dependency on MarkdownParser code, now uses dflydev/markdown library 2012-10-15 17:28:35 +02:00
LICENSE Initial commit 2010-05-05 17:11:02 +02:00
MarkdownParserInterface.php Reverted the interface renaming done in #50 2014-02-20 11:34:05 +01:00
phpunit.xml.dist Exclude vendors from the code coverage 2015-09-29 16:47:42 +02:00
README.markdown Adding public alias and autowiring aliases 2017-11-29 13:29:54 -05:00

Provide markdown conversion (based on Michel Fortin work) to your Symfony2 projects.

Build Status

INSTALLATION

Add KnpMarkdownBundle to your project via Composer:

composer require knplabs/knp-markdown-bundle

If you're not using Symfony Flex, you will also need to enable the bundle in your app/AppKernel.php file (new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle()).

That's it! Start using it!

USAGE

Once the bundle is installed, you can autowire a MarkdownParserInterface into any service or controller:

use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;

// from inside a controller
public function index(MarkdownParserInterface $parser)
{
    $html = $parser->transformMarkdown($text);
}

// or from inside a service
private $parser;

public function __construct(MarkdownParserInterface $parser)
{
    $this->parser = $parser;
}

public function someMethod()
{
    $html = $parser->transformMarkdown($text);
}

There is also a public markdown.parser service you can use.

In Twig, you can use the markdown filter:

{# Use default parser #}
{{ my_data|markdown }}

{# Or select specific parser #}
{{ my_data|markdown('parserName') }}

Change the parser implementation

Create a service implementing Knp\Bundle\MarkdownBundle\MarkdownParserInterface, then configure the bundle to use it:

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)

markdown.parser.sundown requires the php sundown extension.

For more details, see the implementations in Parser/Preset.