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.
composer require setono/editorjs-bundle
<?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));
}
}
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.