-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# WordPress Block Parser | ||
|
||
Parse WordPress edit-context content to PHP objects easily. | ||
|
||
## Installation | ||
```bash | ||
composer require recoded-dev/wordpress-block-parser | ||
``` | ||
|
||
## Examples | ||
|
||
### Parsing and replacing | ||
```php | ||
<?php | ||
|
||
use Recoded\WordPressBlockParser\BlockParser; | ||
use Recoded\WordPressBlockParser\Blocks\Block; | ||
use Recoded\WordPressBlockParser\BlockReplacer; | ||
|
||
$content = <<<HTML | ||
<!-- wp:paragraph --> | ||
Test | ||
<!-- /wp:paragraph --> | ||
HTML; | ||
|
||
$parser = BlockParser::create($content); | ||
$replacer = BlockReplacer::create($content); | ||
|
||
foreach ($parser as $block) { | ||
// $block->namespace | ||
// $block->name | ||
// $block->attributes | ||
|
||
if ($block instanceof Block) { | ||
// $block->content | ||
} | ||
|
||
$replacer->replace($block, 'Your replaced content'); | ||
} | ||
|
||
echo (string) $replacer; // Your replaced content | ||
``` | ||
|
||
## Contributing | ||
Everyone is welcome to contribute. Feel free to PR your work once you think it's ready. | ||
Or open a draft-PR if you want to get some opinions or further help. | ||
|
||
I would like to keep this package relatively small and want to avoid bloat. The package | ||
should remain extensible and unopinionated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters