FOSCommentBundle功能包:使用Sundown PECL扩展

简介:

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!

Return to the index.

返回到指南索引页




本文转自 firehare 51CTO博客,原文链接:http://blog.51cto.com/firehare/1259386,如需转载请自行联系原作者
相关文章
|
10月前
|
编译器 API PHP
深入PHP扩展开发:打造高效自定义模块
【4月更文挑战第30天】 在追求性能优化和特定功能实现的道路上,PHP提供了一种强大机制——扩展。本文将引导读者通过编写一个简单的PHP扩展来探索扩展开发的世界。我们将涉及从环境搭建到代码实现,再到扩展的编译与加载的完整流程,确保读者能够理解并实践如何创建高效的自定义PHP模块。
|
开发框架 应用服务中间件 API
扩展Nginx的无限可能:掌握常见扩展模块和第三方插件的使用方法
扩展Nginx的无限可能:掌握常见扩展模块和第三方插件的使用方法
862 0
|
存储 运维 安全
4.3 PTK方式安装
4.3 PTK方式安装
349 1
|
Web App开发 Java Unix
常用的包管理工具的简单使用
brew 是macOS系统的包管理软件。Homebrew是以最简单,最灵活的方式来安装苹果公司在MacOS中不包含的UNIX工具。 homebrew基于Git仓库管理的。
229 0
|
缓存 NoSQL 应用服务中间件
nginx安装配置Lua模块的支持
nginx安装配置Lua模块的支持
erlang高性能网络库esockd的编译和使用(五)-热更新
erlang高性能网络库esockd的编译和使用(五)-热更新
153 0