• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

KnpLabs/KnpMarkdownBundle: Symfony wrapper for PHP markdown

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

KnpLabs/KnpMarkdownBundle

开源软件地址(OpenSource Url):

https://github.com/KnpLabs/KnpMarkdownBundle

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

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

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 = $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)
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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap