@@ -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
3166This project is actively maintained by [ Alley
3267Interactive] ( 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 )
0 commit comments