Giter Club home page Giter Club logo

knpmarkdownbundle's Introduction

Provide markdown conversion (based on Michel Fortin work) to your Symfony 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:

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

knpmarkdownbundle's People

Contributors

ornicar avatar weaverryan avatar pilot avatar stof avatar akovalyov avatar stloyd avatar mbontemps avatar herzult avatar matthieumota avatar cordoval avatar pdenis avatar benji07 avatar soullivaneuh avatar peterrehm avatar battlerattle avatar bakfr avatar elnur avatar l3pp4rd avatar julesbou avatar tamirvs avatar gromnan avatar craue avatar brikou avatar juanlu-martinez avatar docteurklein avatar vierbergenlars avatar mathewpeterson avatar lunetics avatar bocharsky-bw avatar lwagner avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.