Skip to content

Commit c3775bc

Browse files
authored
Building out the block converter
Constructs the block converter with a Block DTO to allow for easy modification.
1 parent 4110a4d commit c3775bc

12 files changed

Lines changed: 718 additions & 51 deletions

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Changelog
22

3-
All notable changes to `Create PHP Package` will be documented in this file.
3+
All notable changes to `WP Block Converter` will be documented in this file.
44

5-
## 0.1.0 - 202X-XX-XX
5+
## 1.0.0 - 2022-12-19
66

77
- Initial release

README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,46 @@ composer require alleyinteractive/wp-block-converter
1515

1616
## Usage
1717

18-
Use this package like so:
18+
Use this package like so to convert HTML into Gutenberg Blocks:
1919

2020
```php
21-
$package = Alley\\Block_Converter\WP_Block_Converter\WP_Block_Converter();
22-
$package->perform_magic();
21+
use Alley\WP\Block_Converter\Block_Converter;
22+
23+
$converter = new Block_Converter();
24+
25+
$blocks = $converter->convert( '<p>Some HTML</p>' );
26+
```
27+
28+
### Filtering the Blocks
29+
30+
The blocks can be filtered on a block-by-block basis or for an entire HTML body.
31+
32+
#### `wp_block_converter_block`
33+
34+
Filter the generated block for a specific node.
35+
36+
```php
37+
use Alley\WP\Block_Converter\Block;
38+
39+
add_filter( 'wp_block_converter_block', function ( Block $block, \DOMElement $node ): ?Block {
40+
// Modify the block before it is serialized.
41+
$block->content = '...';
42+
$block->blockName = '...';
43+
$block->attributes = [ ... ];
44+
45+
return $block;
46+
}, 10, 2 );
47+
```
48+
49+
#### `wp_block_converter_html_content`
50+
51+
Filter the generated blocks for an entire HTML body.
52+
53+
```php
54+
add_filter( 'wp_block_converter_document_html', function( string $blocks, \DOMNodeList $content ): string {
55+
// ...
56+
return $blocks;
57+
}, 10, 2 );
2358
```
2459

2560
## Changelog
@@ -30,7 +65,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re
3065

3166
This project is actively maintained by [Alley
3267
Interactive](https://github.com/alleyinteractive). Like what you see? [Come work
33-
with us](https://alley.co/careers/).
68+
with us](https://alley.com/careers/).
3469

3570
- [Sean Fisher](https://github.com/srtfisher)
3671
- [All Contributors](../../contributors)

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
},
3232
"sort-packages": true
3333
},
34+
"autoload": {
35+
"files": [
36+
"src/helpers.php"
37+
]
38+
},
3439
"extra": {
3540
"wordpress-autoloader": {
3641
"autoload": {

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<properties>
3939
<property name="prefixes" type="array">
4040
<element value="alley" />
41+
<element value="wp_block_converter" />
4142
</property>
4243
</properties>
4344
</rule>

phpunit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,5 @@
1111
<testsuite name="Feature">
1212
<directory prefix="test-" suffix=".php">tests/feature</directory>
1313
</testsuite>
14-
<testsuite name="Unit">
15-
<directory prefix="test-" suffix=".php">tests/unit</directory>
16-
</testsuite>
1714
</testsuites>
1815
</phpunit>

0 commit comments

Comments
 (0)