Skip to content

Compat: Support unwrapped paragraph text via deprecation#4874

Merged
aduth merged 3 commits intomasterfrom
update/p-deprecated-repair
Feb 6, 2018
Merged

Compat: Support unwrapped paragraph text via deprecation#4874
aduth merged 3 commits intomasterfrom
update/p-deprecated-repair

Conversation

@aduth
Copy link
Copy Markdown
Member

@aduth aduth commented Feb 5, 2018

Closes #589
Related: #589, #3922

This pull request seeks to enhance the paragraph block to accommodate technically-broken-but-common markup of text without a paragraph tag wrapper.

Specifically, this can assist in cases where:

  • A third-party editor emulates legacy removep behavior and strips paragraph tags from the inner contents of <!-- wp:paragraph --> blocks
  • The user pastes unwrapped content into the block's "Edit as HTML" mode

Implementation notes:

The approach here abuses uses the block deprecation pattern to consider an unwrapped paragraph as deprecated, even though it was never truly a supported implementation. The idea is that we anticipate the block invalidation and repair it to its supported equivalent.

Testing instructions:

  1. Navigate to Posts > Add New
  2. Add a new paragraph block with some text
  3. Cmd/Ctrl+A to select all text of the paragraph block, then copy it
  4. Switch block to Edit as HTML mode via its "More Options" menu
  5. Paste the contents copied in step 3
  6. Switch back to Edit as Visual mode
  7. Note that the block is still valid and appears with the same text entered in step 2

@aduth aduth added the [Feature] Blocks Overall functionality of blocks label Feb 5, 2018
},
},
save( { attributes } ) {
return attributes.content;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting, the issue I see about this is that anything (any HTML) could be considered a valid paragraph block

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Interesting, the issue I see about this is that anything (any HTML) could be considered a valid paragraph block

Wouldn't it only be tried for the paragraph blocks, since it happens during the parse step for the individual block?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, that's true but if I tweak the paragraph block with any markup (say in a code editor, I add an image), this markup will be upgraded and shown in the editor. I don't know if we want to fix this or consider it a rare edge case

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that's true but if I tweak the paragraph block with any markup (say in a code editor, I add an image), this markup will be upgraded and shown in the editor. I don't know if we want to fix this or consider it a rare edge case

Hmm, that's a good point. If we cared to, we could filter the HTML allowed here. Is this something the raw handler would be well-suited for, @iseulde ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could an example be given here? Not sure I follow entirely. A few weeks ago I was thinking to add the valid_elements TinyMCE filter to only include the formatting we allow and if multiline the tag + formatting. This could then be enforced on setting initial content. This whitelist could also be shared with raw handling.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is ok, you currently can write plenty of HTML within the paragraph content if you want so, and that is not really different.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mmm that's true, I guess we need to fix this separately if we ever want to then. (Maybe apply a filter in the save function which would invalidate the block)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this seems like another layer of refinement that we might want to explore separately. But not even sure we should care too much about it.

@ellatrix
Copy link
Copy Markdown
Member

ellatrix commented Feb 6, 2018

I'm assuming here that the issue is the following: someone edits the block as HTML, remove the "main" tag (<p> in this case) along with other formatting so only inline text remains. This triggers the modified externally message. This branch fixes that for paragraphs, but shouldn't we be looking to fix it everywhere? I can do exactly the some for e.g. a heading block. The heading block delimiters remain, and the inline text remains, but it won't work.

@mtias
Copy link
Copy Markdown
Member

mtias commented Feb 6, 2018

@iseulde it's not so much about removing the <p> but the expectation that WP has that p-less text are valida paragraphs. Which means it's a lot more likely you'd copy a p-less chunk of text into the HTML view for a paragraph.

Also what @aduth mentioned about external editors running their replacep for compat purposes increasing the likelihood of messing with the paragraph content. That's not true on the same level for headings, etc, so I think we can draw a line there.

That said, for sources that have a single value, it might be interesting to explore a general solution where plain-text or the source attr are both matched.

@mtias
Copy link
Copy Markdown
Member

mtias commented Feb 6, 2018

This looks 👍 from me.

@mkaz
Copy link
Copy Markdown
Member

mkaz commented Feb 6, 2018

I've tested and it solves the issue, thank you! This was my hope for #4813

It is kinda cool that you can see the P tags get auto added when editor loses focus switching between Visual/Code editor modes.

The minor concern would be if a user for some reason wants a block of text without P tags - but that can easily be made with custom HTML block, and not a paragraph.

@aduth aduth force-pushed the update/p-deprecated-repair branch from bd72c3b to 54802d9 Compare February 6, 2018 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Blocks Overall functionality of blocks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants