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

Parser: Apply raw transforms to fallback content #2617

Closed
wants to merge 2 commits into from

Conversation

aduth
Copy link
Member

@aduth aduth commented Aug 31, 2017

Closes #2454
Closes #1728

This pull request seeks to extend raw transforms used in paste handling to fallback post content (freeform). This could be used to upgrade legacy content to compatible blocks, including images, paragraphs, and even shortcodes (providing a transition path for plugin authors and their existing shortcodes).

Implementation notes:

This pull request is a work-in-progress, and has encountered a number of hurdles:

  • The raw transform tests expect to receive a DOM node, but in the case of legacy post content, we need to generate blocks from a string of removep-delimited content (removep replaces paragraphs with two subsequent line breaks). The implementation here applies autop to freeform content, assuming it to be from legacy posts (an open question as to whether this is a fair assumption).
  • There may be need for transform prioritization. For example, given the above note about reapplying autop, the paragraph block will now match a <p>[gallery]</p> node, despite this being better suited as a gallery block. In the meantime, I have had to temporarily disable the paragraph block transform.
  • We may want to consider just how much we automatically upgrade. While paragraph transforms were still active with these changes, it was pretty nice to see freeform paragraphs automatically upgraded to a paragraph block. But do we risk these transforms being destructive?
  • To the previous point, we must determine how to handle cases where freeform content is a "match" but also has additional attributes that would be lost in the block reserialization, per the conversation between @youknowriad and @iseulde at Handle pasted block content #1331 (comment)
  • The gallery block expects more attributes to be sourced than can be satisfied by the gallery shortcode. This may simply be a matter of refactoring the gallery block to be able to initialize from the data available in a shortcode (only image IDs)

As an alternative implementation, we could consider limiting these upgrades to either (a) specific string patterns and/or (b) shortcode detection.

Testing instructions:

Noting that this is still a work in progress, you can test the behavior by saving a post in the current post editor's HTML mode as such:

this is a post

[gallery ids="12,34,56"]

with a gallery

When reopening this post in Gutenberg, you should note that the gallery shortcode is replaced with a gallery block (currently best observed in Text mode, noting issues above about gallery block initializing only from IDs).

aduth added 2 commits August 30, 2017 20:48
Used previously to generate paragraph wrappers for removep'd content, now handled by wpautop in parser for unrecognized content
@aduth aduth added [Feature] Parsing Related to efforts to improving the parsing of a string of data and converting it into a different f [Status] In Progress Tracking issues with work in progress labels Aug 31, 2017
@aduth
Copy link
Member Author

aduth commented Oct 27, 2017

Superseded by #3179.

@aduth aduth closed this Oct 27, 2017
@aduth aduth deleted the update/transform-raw branch October 27, 2017 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Parsing Related to efforts to improving the parsing of a string of data and converting it into a different f [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant