Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conflicts with markdown plugins #5288

Merged
merged 4 commits into from
Feb 28, 2018
Merged

Fix conflicts with markdown plugins #5288

merged 4 commits into from
Feb 28, 2018

Conversation

mkaz
Copy link
Member

@mkaz mkaz commented Feb 27, 2018

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:

  1. Install Jetpack (or other wpcom markdown implementation) 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.

Description

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.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

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.
@aduth aduth added the [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes. label Feb 27, 2018
@aduth aduth added this to the 2.3 milestone Feb 27, 2018
}
add_filter( 'rest_pre_insert_post', 'gutenberg_remove_wpcom_markdown_support' );
add_filter( 'wp_insert_post_data', 'gutenberg_remove_wpcom_markdown_support', 1, 1 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be so early in priority? Can't it just be one step before where Jetpack it filtering it at?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fourth argument is 1 by default and can be omitted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

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' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for nesting if, just combine into the top-level condition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

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' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace issues here (needs tabs, not spaces).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, wrong editor.

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 ) ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the shape of $post_data? From what I can tell, it's a compacted associative array of all properties:

https://github.com/WordPress/wordpress-develop/blob/fde455a89f9eaaae9513ca722f2de20420ca4bdd/src/wp-includes/post.php#L3487

Why do we test anything other than content?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mkaz
Copy link
Member Author

mkaz commented Feb 27, 2018

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.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra paragraph tags are unrelated to Markdown module, tracked separately at #3901

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants