Repository navigation
Add wp block convert and wp block conversion-support for server-side block conversion - #20
Draft
swissspidy wants to merge 1 commit into
Draft
swissspidy wants to merge 1 commit into
swissspidy wants to merge 1 commit into
Conversation
Add two commands that expose the server-side block conversion from WordPress/gutenberg PR #82013: - `wp block convert [<html>] [--file=<file>]` converts HTML to block markup with `gutenberg_html_to_block_markup()`, reading the HTML from the argument, a file, or STDIN. - `wp block conversion-support [--format=<format>]` lists the blocks a conversion can produce with `gutenberg_get_block_conversion_support()`, one row per block with `converts`, `conditional` or `declines`. Both commands fail with a clear error when the conversion functions are not available. PHPStan gets stubs for those functions so static analysis can type-check the calls. The feature file has two scenarios that run in CI against a plain install and four scenarios tagged @broken that need a Gutenberg build from the pull request, with instructions on how to run them locally. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZNpaiVywfzpc8Hpm6dMa8
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two commands that expose the server-side block conversion prototyped in WordPress/gutenberg#82013 (branch
try/13163-php-block-conversion).Commands
wp block convert [<html>] [--file=<file>]Converts HTML to serialized block markup with
gutenberg_html_to_block_markup()and prints it to STDOUT. The HTML comes from the positional argument, else--file, else STDIN (socat page.html | wp block convertworks). Passing both the argument and--file, or passing no input at all, is an error. The docs note that the output is not sanitized and that it should go through the usual filters (for examplewp post update) before being stored.wp block conversion-support [--support=<support>] [--field=<field>] [--fields=<fields>] [--format=<format>]Lists what a conversion can produce from
gutenberg_get_block_conversion_support(), one row per block, with columnsnameandsupport(converts,conditionalordeclines), sorted by name. UsesWP_CLI\Formatterwith the usualtable,csv,json,countandyamlformats plus--field/--fields, the way the other list commands in this package do. I added a small--support=<level>filter on top of what was asked for, because--support=declines --field=nameis the obvious scripting use; happy to drop it if unwanted.Naming and structure
Neither name clashed with an existing command, so both live directly under the existing
wp blocknamespace as requested. They are implemented as two methods on one class (Block_Conversion_Command) and registered individually inblock-command.phpwith the class/method pair form ofWP_CLI::add_command(), behind the same WordPress 5.0 gate aswp block synced-pattern.Other changes
phpstan/gutenberg-block-conversion-stubs.phpdeclares the two Gutenberg functions for PHPStan (added toscanFiles), since level 9 otherwise reports them as not found. The directory is excluded from PHPCS and from the distributed package via.distignore.composer.jsonlists the new commands underextra.commands.README.mdregenerated withwp scaffold package-readme.Tests
features/block-convert.feature:Given a WP install): each command fails with the "not available" error on STDERR, empty STDOUT, exit code 1.@broken, socomposer behatskips them, following howwp-cli/wp-cli-testsalways excludes that tag): converting<h2>Title</h2><p>Text</p>yields<!-- wp:heading -->and<!-- wp:paragraph -->; reading from STDIN and from--fileplus the input-related errors; existing block markup is kept and unknown markup becomes a Custom HTML block;conversion-supportlistscore/paragraphasconvertsandcore/tableasdeclines, plus the--support,--format=jsonand--format=countvariants. A comment in the feature file explains how to run them locally: build the plugin zip from the branch, drop it in the package root asgutenberg.zip(git-ignored), runcomposer prepare-testsonce, thenvendor/bin/behat --tags=@broken features/block-convert.feature. Each scenario installs it withwp plugin install gutenberg.zip --activate.Validation
composer lint,composer lint-gherkin,composer phpcs,composer phpstan: all clean.WP_CLI_TEST_DBTYPE=sqliteagainst a WordPress 7.1 archive from the GitHub mirror viaWP_CLI_TEST_CORE_ZIP: 65 scenarios passed, including the two new ones.@brokenscenarios were not run against a real build of the Gutenberg PR (no way to build it in that environment). To check the command plumbing anyway I ran a throwaway scenario with an mu-plugin that fakes the two functions, covering argument/--file/STDIN input, the error paths, and every output format; that scenario is not part of this PR.wp help block convertandwp help block conversion-supportrender as expected.Notes
🤖 Generated with Claude Code
https://claude.ai/code/session_01YZNpaiVywfzpc8Hpm6dMa8
Generated by Claude Code