Fix error with Jetpack Markdown being enabled#2817
Conversation
gutenberg.php
Outdated
There was a problem hiding this comment.
The version bumps here shouldn't be part of the changes.
lib/compat.php
Outdated
There was a problem hiding this comment.
I don't think that $settings would ever not be an array. What we might want to do here is test first whether the post contains blocks and, if it does, assign $settings['wpautop'] as explicitly false but otherwise do nothing with the key.
There was a problem hiding this comment.
I like that, a bit cleaner.
lib/compat.php
Outdated
There was a problem hiding this comment.
Would it hurt if we removed wpcom-markdown support without explicitly testing whether we're in the context of Jetpack, since I assume the post support (by its prefix) is relevant for Jetpack only anyways?
There was a problem hiding this comment.
I changed the method of determining and removed it regardless of JETPACK being defined.
lib/compat.php
Outdated
There was a problem hiding this comment.
post is not the only post type we'd expect to be using Gutenberg. Or is it the case that Jetpack is only adding support for this type? Otherwise we might have to hook into where Jetpack is testing the post type and check whether it's handled by Gutenberg. Currently we have a filter for this, but it's not very well generalized:
Line 154 in 5a949b7
I could imagine a function to call which runs the filter.
We also want to make sure that we're not removing this support if the post is being edited from the classic editor, since this action will be triggered regardless of whether the user is using the Gutenberg editor.
791667c to
30e6fd5
Compare
a53e000 to
2836321
Compare
…d not flip settings if already set to true
This ends up being a bit heavy handed solution, since it will also disable markdown in the classic editor, however each block doesn't fail to classic blocks on each save. Is there a check we can add to init to see which editor is being used? The markdown processing is called during save a post, so not sure it is possible to determine or not
Use the pre insert filter on the rest endpoint to determine if the content being saved is from Gutenberg and disable the markdown support if a block is included. Temporary includes the content_has_block() function from PR#2806
Use the pre insert filter on the rest endpoint to determine if the content being saved is from Gutenberg and disable the markdown support if a block is included. Temporary includes the content_has_block() function from PR#2806
2836321 to
9377638
Compare
| * | ||
| * @param string $content Content to test. | ||
| * @return bool Whether the content contains blocks. | ||
| */ |
There was a problem hiding this comment.
If we're introducing this function, I think we should refactor gutenberg_post_has_blocks to use it as well, rather than repeat the strpos implementation.
There was a problem hiding this comment.
Good catch, updated gutenberg_post_has_blocks to use the new function
lib/compat.php
Outdated
| * @param array $post Post object which contains content to check for block. | ||
| * @return array $post Post object. | ||
| */ | ||
| function gutenberg_remove_wpcom_markdown_support( $post ) { |
There was a problem hiding this comment.
Shouldn't this live in the plugin that adds wpcom-markdown to posts?
There was a problem hiding this comment.
@aaronjorbin it does makes sense to include in Jetpack. However, there are also other plugins, for example JP Markdown which include it.
There was a problem hiding this comment.
@mkaz What about the other plugins that add markdown in a different way? Should the code for turning off markdown in each of them live in Gutenberg or should Gutenberg provide the tools (such as the content_has_blocks function and ideally some documentation) to assist them?
There was a problem hiding this comment.
@aaronjorbin Gutenberg definitely should provide tools to assist, which this change does include one.
It's a bit of a catch-22, Gutenberg is still a plugin under development, trying to grow and get more people interested and gather feedback. If user wants to try it out and then their first experience is a broken, it's not a great way to gather feedback. So this fix disables a feature in one of the most popular plugins that makes for a poor Gutenberg experience.
As Gutenberg grows and gets closer to becoming the core editor, plugins will adopt the changes and include fixes themselves. However, as stated it is harder to grow if initial experience is rough.
Ideally, a plugin could provide a markdown block which would be awesome and any parsing conflict could also be avoided.
There was a problem hiding this comment.
I completely agree on the catch-22, but I think it also goes other ways. If Gutenberg is going to be in core, it can't be responsible for changes to plugins. Either things need to be done in a fully backward compatible way, or education is needed for plugin maintainers to help them adjust. Playing favorites for popular plugins is going going to lead to unnecessary drama (what qualifies as a popular plugin? Why was that plugin given preference over mine?), an increased and unnecessary maintenance burdon for core, and slower fixes for users.
Perhaps what's needed is some documentation and a documentation standard for things that can't be included in a core merge if that was to happen?
Codecov Report
@@ Coverage Diff @@
## master #2817 +/- ##
==========================================
- Coverage 33.94% 33.23% -0.71%
==========================================
Files 193 196 +3
Lines 5700 6059 +359
Branches 1000 1075 +75
==========================================
+ Hits 1935 2014 +79
- Misses 3185 3406 +221
- Partials 580 639 +59
Continue to review full report at Codecov.
|
|
@aaronjorbin - I added a file called Let me know what you think, see commit c202c68 |
Creating a new file as a means to better document compatibility support added for specific plugins. This change also isolates code that likely will not be included for a core merge.
520671b to
c202c68
Compare
|
@mkaz Looks good to me. Seems to achieve the goal of improving compatibility to help with testing while also making a core merge easier. Thanks for working on this and for making that change. |
Description
When saving text blocks while Jetpack Markdown is enabled, the
<p>tags are stripped on save. When loaded again in Gutenberg the blocks are not recognized since the tags are needed to properly parse paragraph blocks.How to Test
Change
rest_pre_insert_posthook.