setono/editorjs-php

PHP library for handling data from the EditorJS

v0.2.1 2022-04-28 19:27 UTC

This package is auto-updated.

Last update: 2022-04-28 19:29:16 UTC


README

Latest Version Software License Build Status Code Coverage Mutation testing

Installation

composer require setono/editorjs-php

Usage

Here is a full example going from json to html output.

<?php
$json = '...'; // this is the actual json you receive from the EditorJS instance

$hydrator = new CompositeHydrator();
$hydrator->add(new BlockHydrator());
$hydrator->add(new EmbedBlockHydrator());
$hydrator->add(new HeaderBlockHydrator());
$hydrator->add(new ImageBlockHydrator());
$hydrator->add(new ListBlockHydrator());
$hydrator->add(new ParagraphBlockHydrator());
$hydrator->add(new RawBlockHydrator());

$parser = new Parser($hydrator);
$parserResult = $parser->parse($json);

$blockRenderer = new CompositeBlockRenderer();
$blockRenderer->add(new DelimiterBlockRenderer());
$blockRenderer->add(new HeaderBlockRenderer());
$blockRenderer->add(new ImageBlockRenderer());
$blockRenderer->add(new ListBlockRenderer());
$blockRenderer->add(new ParagraphBlockRenderer());
$blockRenderer->add(new RawBlockRenderer());

$renderer = new Renderer($blockRenderer);
$html = $renderer->render($parserResult);

EditorJS plugins supported

A PR adding support for any of the above plugins would be awesome! Thank you 🎉