setono/editorjs-bundle

Symfony bundle that integrates the editorjs-php library

Fund package maintenance!
Setono

Installs: 24 273

Dependents: 1

Suggesters: 0

Security: 0

Stars: 7

Watchers: 2

Forks: 0

Open Issues: 1

Type:symfony-bundle

v1.2.0 2024-03-01 11:47 UTC

This package is auto-updated.

Last update: 2024-03-30 12:04:44 UTC


README

Latest Version Software License Build Status Code Coverage Mutation testing

This bundle integrates the editorjs-php library into Symfony.

Instead of using the default block renderers in the library, this bundle creates a TwigBlockRenderer which renders all blocks as twig templates. This makes it very easy for you to override the rendered HTML for each block.

Install

composer require setono/editorjs-bundle

Usage

<?php

use Setono\EditorJS\Parser\ParserInterface;
use Setono\EditorJS\Renderer\RendererInterface;

final class YourService
{
    public function __construct(
        private readonly ParserInterface $parser,
        private readonly RendererInterface $renderer
    ) {
    }

    public function __invoke(string $json): string
    {
        return $this->renderer->render($this->parser->parse($json));
    }
}

Override rendered HTML

Each block has a corresponding Twig template inside the block directory. The template for the ListBlock looks like this for example:

{# @var block \Setono\EditorJS\Block\ListBlock #}
<{{ block.tag }}>
{% for item in block.items %}
    <li>{{ item|raw }}</li>
{% endfor %}
</{{ block.tag }}>

Just as other Twig templates you can easily override these templates.