Go to file
Ryan Weaver 9a8e23f69f minor #117 Abandon this bundle (bocharsky-bw)
This PR was squashed before being merged into the 1.5.x-dev branch.


Abandon this bundle

Closes #116


091cff2 Abandon this bundle
2022-02-01 12:06:52 -05:00
.github/workflows Run PHPUnit tests only on PR 2022-01-26 11:34:45 +02:00
DependencyInjection Revert removing Sundown 2022-01-25 18:32:36 +02:00
Helper update test methods to parent signatures 2021-11-30 07:32:02 -05:00
Parser Get rid of property types for now 2022-01-25 19:02:38 +02:00
Resources/config Revert removing Sundown 2022-01-25 18:32:36 +02:00
tests Bump Symfony lowest to ^4.4 2022-01-25 20:18:11 +02:00
Twig/Extension remove deprecations 2021-11-05 12:50:12 -04:00
.gitignore Ignore PHPUnit cache file and var/ dir 2022-01-25 19:43:26 +02:00
.travis.yml add PHP 8 2021-01-20 18:31:15 +01:00
CHANGELOG.md Making the templating component an optional dependency 2018-01-22 20:45:26 -05:00
composer.json Abandon this bundle 2022-02-01 12:06:50 -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 Do not fail on incomplete - we do have incomplete tests 2022-01-26 00:04:56 +02:00
README.markdown Abandon this bundle 2022-02-01 12:06:50 -05:00

WARNING: This bundle is abandoned in favor of markdown_to_html Twig filter. Please, consider using it instead. Migration should be easy because it also supports michelf/php-markdown Markdown parser that is used in this project under the hood.

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

Build Status

ci.yml php.yml


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!


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 = $this->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 }}

{# If my_data is entered by a user, escape HTML tags before printing it #}
{{ my_data|escape|markdown }}
{# or strip HTML tags #}
{{ my_data|striptags|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:

# Symfony 3: app/config/config.yml
# Symfony 4: config/packages/knp_markdown.yaml (you'll need to create this)
        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 bin/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.