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

KnpMarkdownBundle

by KnpLabs

Symfony2 wrapper for PHP markdown

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

Build Status

INSTALLATION

Symfony 2.0) Add the following entry to deps the run php bin/vendors install.

[KnpMarkdownBundle]
    git=https://github.com/KnpLabs/KnpMarkdownBundle
    target=/bundles/Knp/Bundle/MarkdownBundle

[dflydev-markdown]
   git=https://github.com/dflydev/dflydev-markdown
   target=dflydev-markdown

And register namespace in app/autoload.php

$loader->registerNamespaces(array(
    // ...
    'dflydev' => __DIR__.'/../vendor/dflydev-markdown/src',
    'Knp'     => __DIR__.'/../vendor/bundles',
));

Symfony 2.1) Add KnpMarkdownBundle to your composer.json

{
    "require": {
        "knplabs/knp-markdown-bundle": "1.2.*@dev"
    }
}

Symfony 2.0 & 2.1) 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 #41 from elnur/support-symfony-2.x
    By pilot, 14 hours ago
  • Merge pull request #41 from elnur/support-symfony-2.x
    By pilot, 14 hours ago
  • Merge pull request #41 from elnur/support-symfony-2.x
    By pilot, 14 hours ago
  • Merge pull request #41 from elnur/support-symfony-2.x
    By pilot, 14 hours ago
  • Merge pull request #41 from elnur/support-symfony-2.x
    By pilot, 14 hours ago
  • Merge pull request #41 from elnur/support-symfony-2.x
    By pilot, 14 hours ago
  • Support all Symfony 2.x versions
    By elnur, 1 month ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Update README.markdown
    By mathewpeterson, 7 months ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Merge pull request #37 from mathewpeterson/patch-1
    By stloyd, 7 months ago
  • Fix rare case when service has not expected tag
    By stloyd, 7 months ago
  • Fix way how Sundown parser is added
    By stloyd, 7 months ago
  • Merge pull request #35 from stof/patch-2
    By stloyd, 7 months ago
  • Fixed the bundle name in the readme
    By stof, 7 months ago
  • Removed hard dependency on MarkdownParser code, now uses `dflydev/markdown` library
    By stloyd, 7 months ago
  • Fix BC break against Symfony 2.0.x
    By stloyd, 7 months ago
  • Merge pull request #29 from craue/patch-2
    By stloyd, 7 months ago
  • Merge pull request #30 from cordoval/feature/addSundownSupport
    By stloyd, 7 months ago
  • address more comments
    By cordoval, 7 months ago
  • address comments
    By cordoval, 7 months ago
  • add check to prevent usage when using sundown
    By cordoval, 7 months ago
  • Fix no_html feature
    By cordoval, 7 months ago
  • add support for sundown extension
    By cordoval, 7 months ago
  • fixed typos in README
    By craue, 7 months ago