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

Separate Paste Handler #11539

Merged
merged 3 commits into from
Nov 7, 2018
Merged

Separate Paste Handler #11539

merged 3 commits into from
Nov 7, 2018

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Nov 6, 2018

Description

Fixes #6102.

This PR separates paste handling from raw handling in general. I opted of a separate function instead of an extra argument because raw handling is significantly less complex and doesn't need as many arguments to works with. Raw handling aims to convert HTML without comment delimiters to blocks, trying to retain as much content as possible.

Needs an integration test.

How has this been tested?

Convert HTML/Classic block to blocks with e.g. a span with attributes in a paragraph.

Screenshots

Types of changes

Checklist:

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

@ellatrix ellatrix requested review from a team, danielbachhuber and aduth November 6, 2018 12:39
@ellatrix ellatrix added this to the WordPress 5.0 milestone Nov 6, 2018
@danielbachhuber
Copy link
Member

@iseulde I tried testing with <p>This classic block has <code>a code snippet</code>.</p> but got the same behavior on this branch and master:

convertinline

Can you update your testing instructions to include more detail about how to reproduce the behavior of the change? Thanks

@ellatrix
Copy link
Member Author

ellatrix commented Nov 6, 2018

@danielbachhuber Thanks, updated. The code tag will also be preserved on paste. Try something that wouldn't e.g. a span with attributes or a small tag.

@mtias mtias modified the milestones: WordPress 5.0, 4.3 Nov 6, 2018
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Confirmed that the <small> tag persists when converting from Classic to Paragraph Block:

convertinline

I'll defer to others on the underlying implementation.

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'm not totally convinced that paste and raw are fundamentally separate things, vs. the former applying a more strict set of filters in the general operation of raw transformation. It makes me wonder if filters should be handled as an argument of the HTML -> blocks transform function. Then again, this still means we'd have to either decide between exposing filters on the public interface, or otherwise provide just as we have done here with an abstracted form ("paste", "raw"). Maybe then this consideration just becomes a future refactoring detail.

Overall, I think this is a positive change 👍

packages/blocks/src/api/raw-handling/index.js Show resolved Hide resolved
@@ -65,6 +65,40 @@ function getRawTransformations() {
} );
}

function htmlToBlocks( { html, rawTransformations } ) {
Copy link
Member

Choose a reason for hiding this comment

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

Could do for a JSDoc.

@susanpaigen
Copy link

If this is the wrong place to post this I apologize. I've been posting to the #6012 string and I'm not sure whether to comment here or there.
Does this solution preserve attributes as well as tags? e.g. class="".
Does it also preserve attributes in other types of content, e.g. headings or lists?

Testing what happens now with the Gutenberg plugin:
I make a paragraph or list block, add content, 'edit in html', add markup (a span with a class, a style on a span or

  • ).
    If I copy the marked-up content in 'edit in html', make a new block, switch to 'edit in html' in the new block, paste my marked-up content, and update, the markup is preserved.
    If I copy the marked-up content in 'edit visually', make a new block, switch to 'edit in html' in the new block, paste my copied (marked-up) content, and update, the markup is stripped.
    So there's some kind of existing copy/paste functionality which doesn't strip the markup.

  • @danielbachhuber
    Copy link
    Member

    Hi @susanpaigen!

    Does this solution preserve attributes as well as tags? e.g. class="".
    Does it also preserve attributes in other types of content, e.g. headings or lists?

    This pull request doesn't, no. There's an ongoing conversation in #11440 on to what degree Gutenberg will support those behaviors. If you'd like, please do weigh in on #11440 with more details of your use-case, the markup you'd like to preserve, etc. Thanks :)

    @ellatrix ellatrix merged commit 489eb79 into master Nov 7, 2018
    @ellatrix ellatrix deleted the try/separate-paste-handler branch November 7, 2018 09:49
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Classic + Custom HTML blocks: Convert to Blocks removes valid inline formatting
    5 participants