Download the PHP package automattic/block-delimiter without Composer
On this page you can find all versions of the php package automattic/block-delimiter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download automattic/block-delimiter
More information about automattic/block-delimiter
Files in automattic/block-delimiter
Package block-delimiter
Short Description Efficiently work with block structure
License GPL-2.0-or-later
Informations about the package block-delimiter
Block Delimiter
Efficiently work with block structure
How to install block-delimiter
To use this package in your WordPress plugin, you can require both this package and the Jetpack Autoloader in your project's composer.json
file.
Usage
The Block Delimiter package provides an efficient, streaming parser for working with WordPress block structure without the memory overhead of parse_blocks()
. It's designed for scenarios where you need to inspect, find, or modify specific blocks without parsing the entire block tree.
Basic Block Scanning
Find and iterate through all block delimiters in a document:
Output:
Finding Specific Block Types
Efficiently find blocks of a specific type without parsing everything:
Output:
Extracting Block Attributes
Parse JSON attributes only when needed:
Output:
Counting Block Types
Get a summary of all block types in a document:
Output:
Extracting Complete Block Content
Extract an entire block including its delimiters and content:
Output:
Modifying Block Content
Transform block content efficiently without parsing the entire tree:
Output:
Error Handling
Check for parsing errors:
Output:
Performance Benefits
The Block Delimiter approach offers significant performance advantages:
- Zero memory overhead: No block tree construction
- Streaming processing: Process only what you need
- Lazy parsing: JSON attributes parsed only when accessed
- String-based operations: Work directly with the source text
- Early termination: Stop processing when you find what you need
This makes it ideal for operations like finding specific blocks, counting block types, or making targeted modifications without the cost of full block tree parsing.
Contribute
You can contribute to this package by submitting a pull request to the Jetpack repository.
Coding standards
This package follows standards set by the Jetpack Codesniffer package, with a few exceptions documented in the package's .phpcs.dir.xml
file.
Testing
When introducing new features or making changes to existing code, please add tests.
To run the tests, you can use the following command:
Using this package in your WordPress plugin
If you plan on using this package in your WordPress plugin, we would recommend that you use Jetpack Autoloader as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.
Security
Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.
License
Block Delimiter is licensed under GNU General Public License v2 (or later)