FOSCommentBundle功能包:使用Sundown PECL扩展

  • 原文出处:9b-sundown_markdown_parser.md

  • 原文作者:FriendsOfSymfony

  • 授权许可:创作共用协议

  • 翻译人员:FireHare

  • 校对人员:

  • 适用版本:FOSCommentBundle 2.0.5

  • 文章状态:草译阶段

Step 9b: Using the Sundown PECL extension

The markup system in FOSCommentBundle is flexible and allows you to use anysyntax language that a parser exists for. PECL has an extension for markdown parsing called Sundown, which is faster than pure PHP implementations of a markdown parser.

FOSCommentBundle功能包的标识系统是灵活的,它允许您使用现存任何语法语言的解析器。PECL有一个被称为Sundown的markdown解析扩展,它是比纯PHP更快的markdown解析实现。


FOSCommentBundle doesnt ship with a bridge for this extension, but it is trivial to implement.

FOSCommentBundle没有与该扩展相关的桥,但实现它易如翻掌。


First, you will need to use PECL to install Sundown.

首先,您需要使用PECL安装Sundown。

pecl install sundown.


You will want to create the service below in one of your application bundles.

您需要在您的应用程序功能包中创建以下服务。

<?php
// src/Vendor/CommentBundle/Markup/Sundown.php
namespace Vendor\CommentBundle\Markup;
use FOS\CommentBundle\Markup\ParserInterface;
use Sundown\Markdown;
class Sundown implements ParserInterface
{
    private $parser;
    protected function getParser()
    {
        if (null === $this->parser) {
            $this->parser = new Markdown(
                new \Sundown\Render\HTML(array('filter_html' => true)),
                array('autolink' => true)
            );
        }
        return $this->parser;
    }
    public function parse($raw)
    {
        return $this->getParser()->render($raw);
    }
}


And the service definition to enable this parser bridge

并在服务定义中启用该解析器桥

# app/config/config.yml
services:
    # ...
    markup.sundown_markdown:
        class: Vendor\CommentBundle\Markup\Sundown
    # ...
fos_comment:
    # ...
    service:
        markup: markup.sundown_markdown
    # ...

That is it!

Return to the index.

返回到指南索引页。


你可能感兴趣的:(Bundle,symfony2,pecl扩展,功能包,使用Sundown)