texditor / blockify-php
Working with Texditor block data
1.0.0
2025-08-14 19:02 UTC
Requires
- php: >=8.1
- cleup/guard: ^1.0
This package is not auto-updated.
Last update: 2025-08-14 19:11:14 UTC
README
Blockify is a PHP library designed for processing and visualizing structured content, which is presented in the form of texditror/editror
blocks. It provides validation, sanitization, and output of data in HTML format.
Features
- Process JSON or array input into structured blocks
- Validate block data against configurable models
- Merge similar adjacent content items
- Render blocks to HTML with customizable output
- Development mode for error handling
Installation
Install via Composer:
composer require texditor/blockify-php
Basic Usage
use Texditor\Blockify\Blockify; use Texditor\Blockify\Config; use Texditor\Blockify\Models\ParagraphBlock; use Texditor\Blockify\Models\CodeBlock; use Texditor\Blockify\Models\FilesBlock; use Texditor\Blockify\Models\GalleryBlock; use Texditor\Blockify\Models\HeaderBlock; use Texditor\Blockify\Models\OrderedListBlock; use Texditor\Blockify\Models\UnorderedListBlock; // Initialize configuration $config = (new Config()) ->addModels( (new ParagraphBlock()) ->setAllowedTags(['a', 'b']), new CodeBlock(), (new FilesBlock()) ->setSourceProtocols(['https', 'http']) ->setSourceProtocols(['https', 'http']), (new GalleryBlock()) ->setImageTypes(['image/png', 'image/jpeg']) ->setVideoTypes(['video/mp4']) ->setVideoAttributes([ 'controls' => 'true' ]), new UnorderedListBlock(), new OrderedListBlock(), // Default h1 new HeaderBlock(), (new HeaderBlock()) ->setOutputName('h2') ->setInputName('h2'), //... and other block model methods (Texditor\Blockify\BlockModel) ); // Dev mode $config->setDev(true); // Process data $blockify = (new Blockify($config)) ->setData($jsonData); // Get secure and processed data $blocks = $blockify->getData();
Error Handling
//... $blockify = new Blockify($config); if (!$blockify->isValid()) { $errors = $blockify->getErrors(); // Handle errors }
Rendering
use Texditor\Blockify\HtmlBuilder; //... $htmlBuilder = new HtmlBuilder($config); // Use only prepared and safe blocks. $html = $htmlBuilder->render($blocks);
Available Block Models
The library includes these default block models:
ParagraphBlock
- For text paragraphsCodeBlock
- For code snippetsFilesBlock
- For file attachmentsGalleryBlock
- For image/video galleriesHeaderBlock
- For headings (h1-h6)OrderedListBlock
- For numbered listsUnorderedListBlock
- For bulleted lists
Configuration Options
addModels()
- Register block modelssetDev()
- Enable/disable development modesetBlockCssPrefix()
- Set CSS class prefixsetRenderTagNames()
- Customize HTML tag namessetRenderBlockNames()
- Customize block output tags