Skip to content

Block Library: Parse Markdown when converting Classic blocks - #79958

Closed
Mustafabharmal wants to merge 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/classic-block-markdown-conversion
Closed

Mustafabharmal wants to merge 1 commit into
WordPress:trunkfrom
Mustafabharmal:fix/classic-block-markdown-conversion

Conversation

@Mustafabharmal

Copy link
Copy Markdown
Contributor

What?

Closes #79871.

Updates the Classic block's Convert to blocks action so Markdown content is correctly converted into Gutenberg blocks instead of being preserved as literal Markdown inside a Paragraph block.

Why?

Markdown content inserted outside the editor (for example using WP-CLI) is loaded into a Classic block when the post is opened in Gutenberg.

When the user clicks Convert to blocks, the current conversion flow treats the content as HTML and bypasses Gutenberg's Markdown conversion, resulting in content such as:

## Heading

being converted into a Paragraph block containing the literal Markdown rather than a Heading block.

The issue is limited to the Classic block conversion flow.

How?

This PR updates the Classic block migration action to reuse Gutenberg's existing Markdown conversion flow.

Before passing the content to pasteHandler, the automatic paragraph wrappers generated by the Classic editor are removed using the existing removep utility from @wordpress/autop. The resulting plain text is then passed to pasteHandler in BLOCKS mode, allowing Gutenberg's existing Markdown parser to generate the appropriate blocks.

This keeps the implementation minimal by reusing existing utilities instead of introducing any custom Markdown parsing logic.

Testing Instructions

  1. Start the development environment.
    npm run wp-env start
    npm run dev
  2. Create a post containing Markdown using WP-CLI.
    npm run wp-env run cli -- wp post create \
      --post_title="Markdown Test" \
      --post_content="## Radiohead rocks" \
      --post_status="publish"
  3. Open the newly created post in the block editor.
  4. Verify the content is loaded inside a Classic block.
  5. Select the Classic block.
  6. Click Convert to blocks.
  7. Verify the content is converted into a Heading block instead of a Paragraph block containing the literal Markdown.

Additional testing

Verify list conversion. Create another post:

npm run wp-env run cli -- wp post create --post_title="Markdown List Test" --post_content="* Item 1
* Item 2
* Item 3"

Repeat the conversion steps above.

Verify the content is converted into a List block.

Screenshots or screencast

Before: ## Radiohead rocks becomes a Paragraph block

Before.Markdown.Fix.mov

After: ## Radiohead rocks becomes a Heading block

After.Markdown.Fix.mov

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Block library.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mustafabharmal <mustafabharmal@git.wordpress.org>
Co-authored-by: flexseth <flexseth@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mustafabharmal

Copy link
Copy Markdown
Contributor Author

I am closing this PR as I notice that the file where I have worked for this issue is removed, So will be creating the new changes to different file.

PR that removed packages/block-library/src/freeform/migration-notice.js #79894

@Mustafabharmal
Mustafabharmal deleted the fix/classic-block-markdown-conversion branch July 7, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown disappears from WP-CLI post editor to Gutenberg

1 participant