maglnet/magl-markdown 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maglnet/magl-markdown

Composer 安装命令:

composer require maglnet/magl-markdown

包简介

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

README 文档

README

Build Status Latest Stable Version License Scrutinizer Code Quality Code Coverage Dependency Status

Introduction

MaglMarkdown is a ZF2 module that adds a View Helper to transform Markdown. To change between different renderers have a look at the config section

You can use one of the following parsers for your Markdown:

Installation

You can install the module with composer by adding the following "require" to your composer.json

{
	"require": {
		"maglnet/magl-markdown": "~1.1"
	}
}

after that you need to run

$ php composer.phar update

and enable the module within your application.config.php

array(
	'modules' => array(
		'Application',
		'MaglMarkdown',
	),
);

Usage

View Helper

Simply use it within your Views like this

$this->markdown('Yes, **this** is *Markdown*!');

Service Manager

You can get the MarkdownService through the Service Manager, to use the render() method wherever you like within you zf2 application. MarkdownService automatically uses caching if it has been enabled within the config.

/* @var $markdownService MaglMarkdown\Service\Markdown */
$markdownService = $serviceManager->get('MaglMarkdown\MarkdownService');
$html = $markdownService->render('Yes, **this** is *Markdown*!');

You can also get a MarkdownAdapter through the Service Manager and use transformText() to get your Markdown rendered to HTML.
This is NOT recommended anymore. Use the above mentioned MarkdownService instead because it can use the provided caching mechanism.

/* @var $markdownAdapter MaglMarkdown\Adapter\MarkdownAdapterInterface */
$markdownAdapter = $serviceManager->get('MaglMarkdown\MarkdownAdapter');
$html = $markdownAdapter->transformText('Yes, **this** is *Markdown*!');

Security warning:
You should be aware, that your markdown could contain insecure content (e.g. user generated content). So use something like HTMLPurifier to sanitize your output.

Configuration

Copy the provided config file config/maglmarkdown.local.php to your autoloading directory YourZF2Application/config/autoload/maglmarkdown.local.php and adjust it to your needs.
By default PHP-MarkdownExtra parser by Michel Fortin is used.

Cache

By default, caching is disabled. Set cache_enabled to true within config/maglmarkdown.local.php to enable the caching. Caching could be very helpful if you have large markdown files/texts or if you're using an Adapter that relies on third-party APIs that either are rate limited or take a long time to render.

A simple filesystem cache is configured by default, but feel free to configure your own adapter.

Adding own parsers

It is possible to add your own parser implementation.
All you have to do, is to write a class that implements the MaglMarkdown\Adapter\MarkdownAdapterInterface interface and make it available through the service manager.
After that override the alias MaglMarkdown\MarkdownAdapterto point to your custom adapter.
MaglMarkdown will then use this class to transform the Markdown.

array(
	'aliases' => array(
		'MaglMarkdown\MarkdownAdapter' => 'Your\Own\MarkdownAdapter', //needs to implement MaglMarkdown\Adapter\MarkdownAdapterInterface
	),
)

Events

The markdown service triggers two events you can listen to:

  • markdown.render.pre before rendering (with the markdown text as parameter)
  • markdown.render.post after rendering (with the rendered markdown as parameter)

These events are currently used for the integrated caching feature only, but do whatever you like with these events.

Contributors

MaglMarkdown is developed by Matthias Glaub and contributors.

License

MaglMarkdown is licensed under the MIT license.
See the included LICENSE file.

Based on PHP Markdown Lib
Copyright (c) 2004-2013 Michel Fortin
http://michelf.ca/
All rights reserved.

Based on parsedown
Copyright (c) 2013 Emanuil Rusev
http://erusev.com/
All rights reserved.

Based on The PHP League's Common Mark implementation
Copyright (c) 2014, Colin O'Dell
https://github.com/thephpleague/commonmark
All rights reserved.

Based on Markdown
Copyright (c) 2003-2005 John Gruber
http://daringfireball.net/
All rights reserved.

maglnet/magl-markdown 适用场景与选型建议

maglnet/magl-markdown 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 198.16k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2014 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「zf2」 「markdown」 「Zend Framework」 「parsedown」 「gfm」 「github flavoured markdown」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 maglnet/magl-markdown 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 maglnet/magl-markdown 我们能提供哪些服务?
定制开发 / 二次开发

基于 maglnet/magl-markdown 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 198.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 27
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 4
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-22