PHPackages                             texditor/blockify-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. texditor/blockify-php

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

texditor/blockify-php
=====================

Working with the Texditor block data. Validation and sanitization of blocks.

1.1.0(5mo ago)057MITPHPPHP &gt;=8.1

Since Aug 14Pushed 5mo agoCompare

[ Source](https://github.com/texditor/blockify-php)[ Packagist](https://packagist.org/packages/texditor/blockify-php)[ Docs](https://github.com/texditor/blockify-php)[ RSS](/packages/texditor-blockify-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (19)Used By (0)

Blockify
========

[](#blockify)

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
--------

[](#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
------------

[](#installation)

Install via Composer:

```
composer require texditor/blockify-php
```

Basic Usage
-----------

[](#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'])
            ->setSourceHosts([
                'priveted.com',
                'github.com'
            ])
            // or only locally
            ->setSourceRegex(["/^\/uploads\/.*\.(png|jpg|jpeg|gif)$/"]),
        (new GalleryBlock())
            // ->setIsMeta(true)
            // ->setIsMetaCaption(true)
            // ->setIsMetaDesc(false)
            ->setSourceHosts([
                'youtube.com',
                'myimageserver.com'
            ])
            ->setSourceProtocols(['https'])
            ->setMetaPosition('top')
            ->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);

// Or if filters are needed
$blockify
    ->filter(function (array $block, int $index, BlockModelInterface $model) {
        if ($model->isPreformatted())
            return false;

        if ($block['type'] == 'p')
            return false;

        return true;
    })
    ->dataFilter(function (
        array|string $item,
        int $index,
        array $block,
        int $blockIndex,
        BlockModelInterface $model
    ) {
        if (
            is_array($item) &&
            $block['type'] == 'gallery' &&
            empty($item['id'])
        ) {
            return false;
        }

        return true;
    });

// Get secure and processed data
$blocks = $blockify->getData();
```

### Error Handling

[](#error-handling)

```
//...
$blockify = new Blockify($config);

if (!$blockify->isValid()) {
    $errors = $blockify->getErrors();
    // Handle errors
}
```

### Rendering

[](#rendering)

```
use Texditor\Blockify\HtmlBuilder;

//...
// Initializes the HTML builder with security and rendering settings.
$htmlBuilder = new HtmlBuilder($config);

// Renders all provided blocks into a safe HTML string.
$html = $htmlBuilder->render($blocks);

// Renders all blocks into plain text, stripping all HTML tags.
$text = $htmlBuilder->renderAsText($blocks);

// Renders only the specified block types ('p', 'h1') into HTML.
$html = $htmlBuilder->renderOnly($blocks, ["p", "h1"]);

// Renders only the specified block types into plain text.
$text = $htmlBuilder->renderOnly($blocks, ["p", "h1"], true);
```

Available Block Models
----------------------

[](#available-block-models)

The library includes these default block models:

- `ParagraphBlock` - For text paragraphs
- `CodeBlock` - For code snippets
- `FilesBlock` - For file attachments
- `GalleryBlock` - For image/video galleries
- `HeaderBlock` - For headings (h1-h6)
- `OrderedListBlock` - For numbered lists
- `UnorderedListBlock` - For bulleted lists

Configuration Options
---------------------

[](#configuration-options)

- `addModels()` - Register block models
- `setDev()` - Enable/disable development mode
- `setBlockCssPrefix()` - Set CSS class prefix
- `setRenderTagNames()` - Customize HTML tag names
- `setRenderBlockNames()` - Customize block output tags

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance70

Regular maintenance activity

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Recently: every ~16 days

Total

18

Last Release

174d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab3497d20980114ee76b06a776b1f957ee8a0f420662e2a21fcd90a03aba855e?d=identicon)[texditor](/maintainers/texditor)

---

Top Contributors

[![texditor](https://avatars.githubusercontent.com/u/202995908?v=4)](https://github.com/texditor "texditor (26 commits)")[![priveted](https://avatars.githubusercontent.com/u/18353516?v=4)](https://github.com/priveted "priveted (1 commits)")

---

Tags

phpmanagerblockstexditor

### Embed Badge

![Health badge](/badges/texditor-blockify-php/health.svg)

```
[![Health](https://phpackages.com/badges/texditor-blockify-php/health.svg)](https://phpackages.com/packages/texditor-blockify-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
