storyblok / richtext-resolver
A package allowing you to get an HTML string from the richtext field of Storyblok.
Installs: 351 105
Dependents: 7
Suggesters: 0
Security: 0
Stars: 7
Watchers: 18
Forks: 6
Open Issues: 1
Requires
- php: >=7.3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4.0
- phpunit/phpunit: ^8|^9
This package is auto-updated.
Last update: 2024-12-08 04:32:50 UTC
README
This package allows you to get an HTML string from the richtext field of Storyblok.
Installing the Storyblok PHP Richtext Renderer
You can install the Storyblok PHP Richtext Renderer via composer. Storyblok PHP Richtext Renderer requires PHP version 7.3 to 8.2. The suggestion is to use an actively supported version of PHP (8.1 and 8.2).
If you want to install the stable release of Storyblok PHP Richtext Renderer you can launch:
composer require storyblok/richtext-resolver
If you want to install the current development release, you can add the version dev-master
:
composer require storyblok/richtext-resolver dev-master
For executing the command above, you need to have composer installed on your development environment. If you need to install Composer, you can follow the official Composer documentation:
- Install Composer on GNU Linux / Unix / macOS
- Install Composer on Windows
We suggest using the latest version of PHP.
composer require storyblok/richtext-resolver dev-master
Usage:
Instantiate the Resolver
class:
use Storyblok\RichtextRender\Resolver; $resolver = new Resolver();
Use the function render()
to get the html string from your richtext field.
// previous code... // Note that in php our objects use multidimensional array notation $data = [ "type" => "doc", "content" => [ [ "type" => "horizontal_rule" ] ] ]; $resolver->render($data) # renders a html string: '<hr />'
How to define a custom schema for resolver?
Make a copy of the default schema storyblok-php-richtext-renderer/src/Schema.php and add your own schema as parameter to the Richtext class.
$resolver = new Resolver($my_custom_schema);
Testing
We use PHPUnit for tests. You can execute the following composer task to run the tests:
composer run test
If you want to generate the coverage report you can launch:
composer run test-coverage
You will find the HTML reports in the coverage/
directory.
Code Style guide
For consistency, we are using PHP Coding Standards Fixer tool, for checking and fixing the code to follow standards.
For checking the code you can execute:
composer run codestyle-check
If you want to automatically fix the code to follow standards:
composer run codestyle-fix
If you want to execute fix and test coverage:
composer run all-check
Contribution
Fork me on Github