setono / editorjs-bundle
集成 editorjs-php 库的 Symfony 扩展包
v1.2.0
2024-03-01 11:47 UTC
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-08-30 12:54:57 UTC
README
此扩展包将 editorjs-php 库集成到 Symfony。
此扩展包不是使用库中的默认块渲染器,而是创建了一个 TwigBlockRenderer,该渲染器将所有块作为 twig 模板渲染。这使得您可以轻松覆盖每个块的渲染 HTML。
安装
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)); } }
覆盖渲染的 HTML
每个块在 block 目录中都有一个对应的 Twig 模板。例如,ListBlock
的模板看起来像这样
{# @var block \Setono\EditorJS\Block\ListBlock #} <{{ block.tag }}> {% for item in block.items %} <li>{{ item|raw }}</li> {% endfor %} </{{ block.tag }}>
与其他 Twig 模板一样,您可以轻松 覆盖 这些模板。