setono / editorjs-bundle
Symfony bundle that integrates the editorjs-php library
Fund package maintenance!
Setono
Installs: 31 707
Dependents: 1
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 0
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.1
- psr/log: ^1.1 || ^2.0 || ^3.0
- setono/editorjs-php: ^1.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-foundation: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/monolog-bundle: ^3.8
- symfony/string: ^5.4 || ^6.0 || ^7.0
- symfony/twig-bundle: ^5.4 || ^6.0 || ^7.0
- twig/twig: ^2.15 || ^3.5
Requires (Dev)
- infection/infection: ^0.27
- matthiasnoback/symfony-dependency-injection-test: ^4.3 || ^5.0
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18
- psalm/plugin-symfony: ^5.0
- setono/code-quality-pack: ^2.6
This package is auto-updated.
Last update: 2024-11-30 13:19:52 UTC
README
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.