Conversation
Here's the test case I have that duplicates this issue: 1. Install Jetpack and enable markdown 2. Create post in Gutenberg with a couple paragraphs. 3. Open post in classic editor and click update 4. One big paragraph. This change adds the filter on `wp_insert_post_data` since edits in classic editor do not go through the rest API. Additionally, it changes the call to remove markdown which is more inclusive of all the actions and filters this markdown implementation touches.
lib/plugin-compat.php
Outdated
| return $post_data; | ||
| } | ||
| add_filter( 'rest_pre_insert_post', 'gutenberg_remove_wpcom_markdown_support' ); | ||
| add_filter( 'wp_insert_post_data', 'gutenberg_remove_wpcom_markdown_support', 1, 1 ); |
There was a problem hiding this comment.
Needs to be so early in priority? Can't it just be one step before where Jetpack it filtering it at?
There was a problem hiding this comment.
The fourth argument is 1 by default and can be omitted.
lib/plugin-compat.php
Outdated
| remove_post_type_support( 'post', 'wpcom-markdown' ); | ||
| function gutenberg_remove_wpcom_markdown_support( $post_data ) { | ||
| if ( gutenberg_content_has_blocks( implode( "\n", $post_data ) ) ) { | ||
| if ( class_exists ( 'WPCom_Markdown' ) ) { |
There was a problem hiding this comment.
No need for nesting if, just combine into the top-level condition.
lib/plugin-compat.php
Outdated
| remove_post_type_support( 'post', 'wpcom-markdown' ); | ||
| function gutenberg_remove_wpcom_markdown_support( $post_data ) { | ||
| if ( gutenberg_content_has_blocks( implode( "\n", $post_data ) ) ) { | ||
| if ( class_exists ( 'WPCom_Markdown' ) ) { |
There was a problem hiding this comment.
Whitespace issues here (needs tabs, not spaces).
lib/plugin-compat.php
Outdated
| if ( gutenberg_content_has_blocks( $post->post_content ) ) { | ||
| remove_post_type_support( 'post', 'wpcom-markdown' ); | ||
| function gutenberg_remove_wpcom_markdown_support( $post_data ) { | ||
| if ( gutenberg_content_has_blocks( implode( "\n", $post_data ) ) ) { |
There was a problem hiding this comment.
What is the shape of $post_data? From what I can tell, it's a compacted associative array of all properties:
Why do we test anything other than content?
There was a problem hiding this comment.
Fixed. I misread documentation that post_data was just the post_content in an array. I'm not sure what I did on my initial inspection of the data to convince me that was the case.
|
Thanks for the review @aduth - I rushed through the initial implementation and hadn't circled back yet to clean up. Updated with all the suggestions and fixed lint errors. |
aduth
left a comment
There was a problem hiding this comment.
I can confirm that this resolves the issue with paragraphs being stripped when saving in the classic editor.
I'm seeing that the classic editor inserts many paragraphs of its own in-between the blocks, which persist into the published copy. Seeing whether this is specific to Markdown module...
There is a conflict with wpcom-markdown which is used in Jetpack and other plugins which add markdown support.
Here's the test case that duplicates the issue:
Description
This change adds the filter on
wp_insert_post_datasinceedits in classic editor do not go through the rest API.
Additionally, it changes the call to remove markdown which
is more inclusive of all the actions and filters this markdown
implementation touches.
Checklist: