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。
1
|
pecl
install
sundown.
|
You will want to create the service below in one of your application bundles.
您需要在您的应用程序功能包中创建以下服务。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<?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
并在服务定义中启用该解析器桥
1
2
3
4
5
6
7
8
9
10
11
|
# app/config/config.yml
services:
# ...
markup.sundown_markdown:
class
: Vendor\CommentBundle\Markup\Sundown
# ...
fos_comment:
# ...
service:
markup: markup.sundown_markdown
# ...
|
That is it!
本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/1259386,如需转载请自行联系原作者