All Projects → nadar → Quill Delta Parser

nadar / Quill Delta Parser

Licence: mit
A PHP library to parse and render Quill WYSIWYG Deltas into HTML - Flexibel and extendible for custom elements.

Projects that are alternatives of or similar to Quill Delta Parser

Diff2html
Pretty diff to html javascript library (diff2html)
Stars: ✭ 1,867 (+2863.49%)
Mutual labels:  hacktoberfest, parser
Demoinfocs Golang
High performance CS:GO demo parser for Go (demoinfo)
Stars: ✭ 288 (+357.14%)
Mutual labels:  hacktoberfest, parser
Rats
Movie Ratings Synchronization with Python
Stars: ✭ 156 (+147.62%)
Mutual labels:  hacktoberfest, parser
Readability
Readability is Elixir library for extracting and curating articles.
Stars: ✭ 188 (+198.41%)
Mutual labels:  hacktoberfest, parser
Valveresourceformat
🔬 Valve's Source 2 resource file format parser and decompiler
Stars: ✭ 638 (+912.7%)
Mutual labels:  hacktoberfest, parser
Spectre.cli
An extremely opinionated command-line parser.
Stars: ✭ 121 (+92.06%)
Mutual labels:  hacktoberfest, parser
Getjs
A tool to fastly get all javascript sources/files
Stars: ✭ 190 (+201.59%)
Mutual labels:  hacktoberfest, parser
Solid
Liquid template engine in Elixir
Stars: ✭ 68 (+7.94%)
Mutual labels:  hacktoberfest, parser
Verible
Verible is a suite of SystemVerilog developer tools, including a parser, style-linter, and formatter.
Stars: ✭ 384 (+509.52%)
Mutual labels:  hacktoberfest, parser
Anglesharp
👼 The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.
Stars: ✭ 4,018 (+6277.78%)
Mutual labels:  hacktoberfest, parser
Termimad
A library to display rich (Markdown) snippets and texts in a rust terminal application
Stars: ✭ 293 (+365.08%)
Mutual labels:  hacktoberfest, parser
Expr Eval
Mathematical expression evaluator in JavaScript
Stars: ✭ 752 (+1093.65%)
Mutual labels:  hacktoberfest, parser
Php Mime Mail Parser
A fully tested email parser for PHP 7.2+ (mailparse extension wrapper).
Stars: ✭ 687 (+990.48%)
Mutual labels:  hacktoberfest, parser
Yii2 Quill
Yii 2 implementation of Quill, modern WYSIWYG editor
Stars: ✭ 52 (-17.46%)
Mutual labels:  hacktoberfest, quill
Digitalocean Manager
iOS App to Manage and View your Virtual Server horsted by DigitalOcean
Stars: ✭ 61 (-3.17%)
Mutual labels:  hacktoberfest
Whisper
Whisper is a file-based time-series database format for Graphite.
Stars: ✭ 1,121 (+1679.37%)
Mutual labels:  hacktoberfest
Cssparser.js
cssparser.js is a parser that generate json from css with matched orders & structures.
Stars: ✭ 61 (-3.17%)
Mutual labels:  parser
Ascemu
Official AscEmu repo... a never ending place to work. With cutting edge technologies XD
Stars: ✭ 61 (-3.17%)
Mutual labels:  hacktoberfest
Coursify Hacktoberfest
A curated list of best free learning resources on the planet, made specifically for first time hackers!
Stars: ✭ 63 (+0%)
Mutual labels:  hacktoberfest
Auto
Generate releases based on semantic version labels on pull requests.
Stars: ✭ 1,120 (+1677.78%)
Mutual labels:  hacktoberfest

Quill Delta to HTML Parser

A PHP library to parse Quill WYSIWYG editor deltas into HTML - flexible and extendible for custom elements. Every element is parsed by the same mechanism, this makes it easy to extend and understand.

Tests Maintainability Test Coverage Latest Stable Version Total Downloads License

What is Quill? Quill is a free, open source WYSIWYG editor built for the modern web. With its modular architecture and expressive API, it is completely customizable to fit any need.

Installation

The package is only available through composer:

composer require nadar/quill-delta-parser

Usage

// ensure to load the autoload file from composer somehwere in your application
require __DIR__ . '/vendor/autoload.php';

// create the lexer object with your given quill json delta code (either an array or string)
$lexer = new \nadar\quill\Lexer($json);

// echoing the html for the given json ops.
echo $lexer->render();

Where $json is the ops json array from quill, for example:

{
  "ops": [
    {
      "insert": "Hello"
    },
    {
      "attributes": {
        "header": 1
      },
      "insert": "\n"
    },
    {
      "insert": "\nThis is the php quill "
    },
    {
      "attributes": {
        "bold": true
      },
      "insert": "parser"
    },
    {
      "insert": "!\n"
    }
  ]
}

This would render the following HTML:

<h1>Hello</h1>
<p><br></p>
<p>This is the php quill <strong>parser</strong>!</p>

Extend the Parser

In order to extend the Parser by adding your own listeneres (this can be the case if you are using quill plugins which generates custom delta code), you have to decide whether it's an:

  • inline element: Replaces content with new parsed content, this is mostly the case when working with quill extensions.
  • block element: Block elements which encloses the whole input with a tag, for example heading.

An example for a mention plugin which generates the following delta {"insert":{"mention":{"id":"1","value":"Basil","denotationChar":"@"}}} an inline plugin could look like this:

class Mention extends InlineListener
{
    /**
     * {@inheritDoc}
     */
    public function process(Line $line)
    {
      // check if input is json, decodes to an array and checks if the key "mention" 
      // exists, if yes return the value for this key.
      $mention = $line->insertJsonKey('mention');
      if ($mention) {
            // apply the inline behavior, updates the content and append to next "block" element.
            // the value in this example would be "<strong>Basil</strong>".
            $this->updateInput($line, '<strong>'.$mention['value'].'</strong>');
    }
}

Now register the listenere:

$lexer = new Lexer($json);
$lexer->registerListener(new Mention);
echo $lexer->render();

Override built-in Listeners

Certain listeners (image, video, color) produce a HTML output which maybe not suit your use case, so you have the option to override the properties of those plugins and re-register the Listener, here an example with the image tag:

$image = new Image();
$image->wrapper = '<img src="{src}" class="my-image" />';

// override the default plugin from the lexer:
$lexer = new Lexer($json);
$lexer->registerListener($image);
echo $lexer->render();

Debuging

Sometimes the handling of delta and how the data is parsed is very hard to debug and understand. Therefore you can use the debugger class which will print a table with informations about how the data is parsed.

$lexer = new Lexer($json);
$lexer->render(); // make sure to run the render before call debugPrint();
 
$debug = new Debug($lexer);
echo $debug->debugPrint();

There is also a built in docker compose file which provides access to the output.php file. The output.php helps to directly write content with the quill editor while displaying what is rendered including all debug informations. In order to run this docker webserver execute the following command in the root directory of your git repository clone:

docker-compose up

and visit http://localhost:5555/ in your browser.

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].