oberon/quill-rendering 问题修复 & 功能扩展

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

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

oberon/quill-rendering

Composer 安装命令:

composer require oberon/quill-rendering

包简介

Render 'insert' Delta's of a Quill Editor. Inspired by D. Blackborough's Quill Renderer package

README 文档

README

Installation

Use composer

composer require oberon/quill-rendering

Usage

$quillOps = "{\"ops\":[
    {\"insert\":\"Lorem ipsum dolor sit amet, \"},
    {\"insert\":\" consectetur\",\"attributes\":{\"bold\":true}},
    {\"insert\":\" adipiscing elit. Sed volutpat lectus non \"},
    {\"insert\":\"pellentesque volutpat\",\"attributes\":{\"italic\":true}},
    {\"insert\":\". Phasellus in lectus pulvinar lorem vestibulum pellentesque.\"}
]}";

try {
    $quill = new RenderQuill();
    $quill->setParsers(\Oberon\Quill\Render\Html\DefaultHtmlParsers::get());
    $quill->load($quillOps);
    echo $quill->render(true);
} catch (Exception $e) {
    echo $e->getMessage();
}

Output should be:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed volutpat lectus non pellentesque volutpat. Phasellus in lectus pulvinar lorem vestibulum pellentesque.

Most important components

  • Renderer

    Has function render which returns a string with formatted contents

  • Parser

    When given a Quill op and renderers[] return true if op was handled and an appropriate Renderer was added to provided renderers[], false otherwise

Convenient classes/methods

DefaultHtmlParsers::get() returns a Parser[] for most basic HTML functionality including

  • Bold
  • Underline
  • Strikethrough
  • Italic
  • Ordered/Unordered lists
  • Links
  • Images
  • Headers
  • Sub/SuperScript

HtmlParser::withQuill($quillOps) will render the provided Quill-text with the DefaultHtmlParsers.

Adding a custom Parser and Renderer

Example: You want to use <b> instead of <strong> for bold.

  1. Create a Renderer
class Bold implements Renderer {
	
	private $text;
	
	public function __construct($insert) {
		$this->text = $insert;
	}
	
	public function render() {
		return '<b>'.$this->text.'</b>';
	}
}
  1. Create a Parser
class BoldParser implements Parser {
	
	public function handleOp(array $op, array & $renderers) {
		
		//Check if your parser is going to handle the op
		if (array_key_exists('attributes', $op)
			&& is_array($op['attributes'])
			&& is_string($op['insert'])
			&& array_key_exists(Attribute::BOLD, $op['attributes'])) {
			
			//Instantiate your Bold Renderer
			$boldRenderer = new Bold($op['insert']);
			
			//It is inline, so add it to a Paragraph-block. The InlineUtil can do that
			InlineUtil::addToParagraph($boldRenderer, $renderers);
			
			return true;
		} else {
			// If your parser does not handle the op return false;
			return false;
		}
	}
}
  1. Register the Parser with the RenderQuill
//Start with the other HTML parsers
$parsers = DefaultHtmlParsers::get();

//Add to the beginning of the array,
//so it is checked before BasicHtmlParser which would also handle the bold attribute
$parsers = array_unshift($parsers, new BoldParser());

$quill = new RenderQuill();
//register
$quill->setParsers($parsers);

Note: This code is an example and needs modification if you would use it. For example: this does not handle cases where the attributes contain bold and some other attribute.

Notes

The load method immediately uses the provided Parsers, so Parsers should be set first.

Other Ops than insert exist: those will not be rendered. Use the Quill-Delta library at https://packagist.org/packages/oberon/quill-delta

oberon/quill-rendering 适用场景与选型建议

oberon/quill-rendering 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.18k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 oberon/quill-rendering 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 16.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-12