定制 everyday/html-to-quill 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

everyday/html-to-quill

最新稳定版本:0.4.0

Composer 安装命令:

composer require everyday/html-to-quill

包简介

PHP HTML to Quill Delta converter

README 文档

README

html-to-quill is a PHP library for converting an HTML string to Quill deltas.

Installation

html-to-quill can be installed through Composer.

$ composer require everyday/html-to-quill

Basic Usage

The HtmlConverter class provides a simple interface for converting from HTML to Quill Deltas:

use Everyday\HtmlToQuill\HtmlConverter;

$converter = new HtmlConverter();
echo json_encode($converter->convert("<h1>Hello World!</h1>"));

// {"ops":[{"insert":"Hello World!"},{"insert":"\n","attributes":{"header":1}}]}

Supporting Custom Tag Behaviour

Custom tags can be supported through customer converters. Converters take a DOMNode as an input, and return a DeltaOp. The default converters can be found in src/Converters

Custom converters can be implemented to handle additional behaviour, which are then implemented into an extension of the HtmlConverter.

Example: Parsing <style> tags as code blocks.

To enable parsing style tags, two converters are required. One for the <style> tag itself, and one for the #cdata-section which represents the internal data.

For this example, namespaces will be omitted.

class StyleConverter extends CodeConverter {
	public function getSupportedTags(): array {
		return ['style'];
	}
}
class CDataConverter extends TextConverter {
	public function getSupportedTags(): array {
		return ['#cdata-section'];
	}
}
class StyleCodeBlockEnabledHtmlConverter extends HtmlConverter {
	public function __construct(){
		parent::__construct(); // We want our default converters.
		$this->converters[] = new StyleConverter();
		$this->converters[] = new CDataConverter();
	}
}

These classes combine in the same style as the basic usage example, to produce our usable output:

$converter = new StyleCodeBlockEnabledHtmlConverter();
echo json_encode($converter->convert("<style>.warning {background-color: red;}</style>"));

// {"ops":[{"insert":".warning {background-color: red;}","attributes":{"code":true}},{"insert":"\n"}]}

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2020-05-17