deanblackborough/php-quill-renderer

v3.13.1 2018-06-21 23:18 UTC

README

Latest Stable Version Packagist License Minimum PHP Version Build Status Coverage Status

PHP Quill Renderer

Render quill insert deltas to HTML and Markdown

Description

Quill deltas renderer, converts deltas to HTML and Markdown, the Quill attributes supported are listed in the table below, the goal is to eventually support every Quill feature.

Planned features

Over the next few weeks/months I want to continue adding support for additional Quill features and add, flesh out additional output formats, after Markdown I'm planning on plain txt, GitHub flavoured Markdown and possibly RTF/PDF.

Installation

The easiest way to use the PHP Quill Renderer is via composer. composer require deanblackborough/php-quill-renderer, alternatively you can include the classes in my src/ directory directly in your library or app.

Usage via API, single $quill_json

try {
    $quill = new \DBlackborough\Quill\Render($quill_json);
    $result = $quill->render();
} catch (\Exception $e) {
    echo $e->getMessage();
}

echo $result;

Usage via API, multiple $quill_json, passed in via array

try {
    $quill = new RenderMultiple($quill_json, 'HTML');
    
    $result_one = $quill->render('one');
    $result_two = $quill->render('two');
} catch (\Exception $e) {
    echo $e->getMessage();
}

echo $result_one;
echo $result_two;

Usage, direct, parse and then render, single $quill_json - updated in v3.10.0

$parser = new \DBlackborough\Quill\Parser\Html();
$renderer = new \DBlackborough\Quill\Renderer\Html();

$parser->load($quill_json)->parse();

echo $renderer->load($parser->deltas())->render();

Usage, direct, parse and then render, multiple $quill_json - updated in v3.10.0

$parser = new \DBlackborough\Quill\Parser\Html();
$renderer = new \DBlackborough\Quill\Renderer\Html();

$parser->loadMultiple(['one'=> $quill_json_1, 'two' => $quill_json_2)->parseMultiple();

echo $renderer->load($parser->deltasByIndex('one'))->render();
echo $renderer->load($parser->deltasByIndex('two'))->render();

Quill attributes and text flow support

Attribute v1+ v2+ v3 HTML v3 Markdown
Bold Yes Yes Yes Yes
Italic Yes Yes Yes Yes
Link Yes Yes Yes Yes
Strike Yes Yes Yes N/A
Script:Sub Yes Yes Yes N/A
Script:Super Yes Yes Yes N/A
Underline Yes Yes Yes N/A
Header Yes Yes Yes Yes
Image Yes Yes Yes Yes
Video No No Yes Yes
List Yes Yes Yes Yes
Child lists No No In Development In Development
Indent/Outdent No No Planned Planned
Text direction No No Planned N/A
Color No No Planned N/K
Font No No Planned N/K
Text align No No Planned N/A
Block quote No No Planned Planned
Code block No No Planned Planned
Custom attributes No No Yes N/A
Line breaks No No Yes Yes
Paragraphs Yes Yes Yes Yes
Attribute HTML Tag Markdown Token
Bold <strong> **
Italic <em> *
Link <a> [Text](Link)
Strike <s>
Script:Sub <sub>
Script:Super <sup>
Underline <u>
Header <h[n]> #[n]
Image <img> ![Image](\path\to\image)
Video <iframe> ![Video](\path\to\video)
List <ul> <ol> * & [n]

Credits

  • carlos [Bugfix] v1.01.0
  • pdiveris [Issue #43] - Null inserts
  • Mark Davison - Pushed me in the right direction for v3.00.0
  • tominventisbe [Issue #54] - Parser::load() does not reset the deltas array
  • tominventisbe [Issue #55] - Image deltas with multiple attributes incorrectly being passed to Compound delta
  • bcorcoran [Issue #81] - Suggested reverting requirements to necessary requirements
  • kingga [Issue #86] - Video support
  • Jonathanm10 [Issue #87] - Newlines proceeding inserts ignored, bug report
  • raphaelsaunier [Issue #87] - Newlines proceeding inserts ignored, bug location