Developed with love by KnpLabs Hire us for your project!
184

KnpMarkdownBundle

by KnpLabs

Symfony2 wrapper for PHP markdown

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

Build Status

INSTALLATION

Add KnpMarkdownBundle to your composer.json

{
    "require": {
        "knplabs/knp-markdown-bundle": "~1.3"
    }
}

Register the bundle in app/AppKernel.php

$bundles = array(
    // ...
    new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
);

USAGE

// Use the service
$html = $this->container->get('markdown.parser')->transformMarkdown($text);

// Use the helper with default parser
echo $view['markdown']->transform($text);

// Use the helper and a select specific parser
echo $view['markdown']->transform($text, $parserName);

If you have enabled the Twig markdown filter, you can use the following in your Twig templates:

{# 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.

TEST

phpunit -c myapp vendor/bundles/Knp/Bundle/MarkdownBundle
Copyright (c) 2010 knpLabs

The MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
knp_markdown:
parser:
service: markdown.parser.max
sundown:
extensions:
fenced_code_blocks: false
no_intra_emphasis: false
tables: false
autolink: false
strikethrough: false
lax_html_blocks: false
space_after_headers: false
superscript: false
render_flags:
filter_html: false
no_images: false
no_links: false
no_styles: false
safe_links_only: false
with_toc_data: false
hard_wrap: false
xhtml: false
  • Merge pull request #45 from vierbergenlars/fix-nohtml
    By pilot, 3 years ago
  • Use no_html option on the parser itself
    By vierbergenlars, 3 years ago
  • Merge pull request #62 from mhor/update_php_markdown_dependency
    By pilot, 3 years ago
  • update php-markdown dependency
    By maxime horcholle, 3 years ago
  • Merge pull request #60 from peterrehm/patch-2
    By pilot, 3 years ago
  • Updated version constraint according to discussion
    By peterrehm, 3 years ago
  • Merge pull request #59 from BattleRattle/fix-travis-php
    By pilot, 3 years ago
  • remove fixation on symfony version
    By , 3 years ago
  • use hhvm stable instead of nightly
    By BattleRattle, 3 years ago
  • Merge pull request #58 from peterrehm/patch-1
    By pilot, 3 years ago
  • Updated version string according to discussion
    By peterrehm, 3 years ago
  • Test newer PHP versions
    By BattleRattle, 3 years ago
  • Updated the recommended composer installation version
    By peterrehm, 3 years ago
  • Merge pull request #56 from elnur/sundown-parameters
    By pilot, 3 years ago
  • Make the Sundown service classes overridable using parameters
    By elnur, 3 years ago
  • Merge pull request #53 from stof/patch-3
    By pilot, 3 years ago
  • Merge pull request #54 from stof/bc_interface
    By pilot, 3 years ago
  • Reverted the interface renaming done in #50
    By stof, 3 years ago
  • Fixed the branch alias for master
    By stof, 3 years ago
  • Switch to the php 5.3.9, drop support symfony 2.0
    By pilot, 3 years ago
  • Merge pull request #51 from elnur/sundown-fix
    By pilot, 3 years ago
  • Make the Sundown parser implement the renamed method from the parser interface
    By elnur, 3 years ago
  • Merge pull request #50 from iammichiel/master
    By pilot, 3 years ago
  • Updating testsuite to Michel Fortin implementation.
    By iammichiel, 3 years ago
  • Merge pull request #48 from tamirvs/feat-images-option
    By pilot, 3 years ago
  • Removing overriden method for fencedCodeBlocks.
    By iammichiel, 3 years ago
  • Drop support symfony 2.0
    By pilot, 3 years ago
  • Remove deps base installation instruction
    By pilot, 3 years ago
  • Migration to MichelFortin's implementation.
    By iammichiel, 3 years ago
  • Added default option to Light and Medium parsers
    By tamirvs, 3 years ago