Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

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

## 0.1.0 - 202X-XX-XX
## 1.0.0 - 2022-12-19

- Initial release
43 changes: 39 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,46 @@ composer require alleyinteractive/wp-block-converter

## Usage

Use this package like so:
Use this package like so to convert HTML into Gutenberg Blocks:

```php
$package = Alley\\Block_Converter\WP_Block_Converter\WP_Block_Converter();
$package->perform_magic();
use Alley\WP\Block_Converter\Block_Converter;

$converter = new Block_Converter();

$blocks = $converter->convert( '<p>Some HTML</p>' );
```

### Filtering the Blocks

The blocks can be filtered on a block-by-block basis or for an entire HTML body.

#### `wp_block_converter_block`

Filter the generated block for a specific node.

```php
use Alley\WP\Block_Converter\Block;

add_filter( 'wp_block_converter_block', function ( Block $block, \DOMElement $node ): ?Block {
// Modify the block before it is serialized.
$block->content = '...';
$block->blockName = '...';
$block->attributes = [ ... ];

return $block;
}, 10, 2 );
```

#### `wp_block_converter_html_content`

Filter the generated blocks for an entire HTML body.

```php
add_filter( 'wp_block_converter_document_html', function( string $blocks, \DOMNodeList $content ): string {
// ...
return $blocks;
}, 10, 2 );
```

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

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

- [Sean Fisher](https://github.com/srtfisher)
- [All Contributors](../../contributors)
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
},
"sort-packages": true
},
"autoload": {
"files": [
"src/helpers.php"
]
},
"extra": {
"wordpress-autoloader": {
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<properties>
<property name="prefixes" type="array">
<element value="alley" />
<element value="wp_block_converter" />
</property>
</properties>
</rule>
Expand Down
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
<testsuite name="Feature">
<directory prefix="test-" suffix=".php">tests/feature</directory>
</testsuite>
<testsuite name="Unit">
<directory prefix="test-" suffix=".php">tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>
Loading