wp-cli / ideas

šŸ’” Ideas and feature requests are collected here
40 stars 1 forks source link

WP-CLI Command: convert #187

Open flexseth opened 5 months ago

flexseth commented 5 months ago

Description

The convert command for WP-CLI changes data from one type to another.

Sample use case: Markdown to Block Markup

The idea is to be able to consume a Markdown file and turn it into a HTML file, which could then be copy/pasted or otherwise imported via the CLI into the Block Editor.

Given the following best-chicken-wings-in-scotland.md file

## Scotland's Best Chicken Wings
Found in Edinburgh, you have to visit the Wingstop at Edinburgh Fountain Stop.

These are the best wings you will find around!

![An image of a crispy chicken wing being dunked into ranch dressing](https://github.com/wp-cli/ideas/assets/3792502/a0c5ee69-d2a3-4158-bedf-a31f18529089)

Converts to

<!-- wp:heading -->
<h2 class="wp-block-heading">Scotland's Best Chicken Wings</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Found in Edinburgh, you have to visit the Wingstop at Edinburgh Fountain Stop.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>These are the best wings you will find around!</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":7,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="http://development.local/wp-content/uploads/2024/06/chicken-wing.jpg" alt="An image of a crispy chicken wing being dunked into ranch dressing" class="wp-image-7"/></figure>
<!-- /wp:image -->

Syntax

wp post convert best-chicken-wings-in-scotland.md

Success: Converted to HTML.


Flags

--create ā€” Create the post as a draft in this WordPress instance. --copy ā€” Copy HTML to the clipboard. --no-follow ā€” Add no-follow to any image tags (good for adverts)

Behind the scenes

Uploads any images found into the Media Gallery

swissspidy commented 5 months ago

I'd say this ask falls under #119, where we're collecting ideas for all kinds of block editor related commands.

The problem is, a convert command like this is almost impossible to build. All the information about blocks and their markup only exists in JavaScript.

We might be able to hardcode something for the core blocks such as paragraph/heading/image, but that's a maintenance nightmare as we can't possibly keep up with any changes from Gutenberg.