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

Conversation

Projects
None yet
5 participants
@iseulde
Member

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

@iseulde iseulde requested review from WordPress/gutenberg-core, danielbachhuber and aduth Nov 6, 2018

@iseulde iseulde added this to the WordPress 5.0 milestone Nov 6, 2018

@danielbachhuber

This comment has been minimized.

Member

danielbachhuber commented Nov 6, 2018

@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

@iseulde

This comment has been minimized.

Member

iseulde 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

@danielbachhuber

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

convertinline

I'll defer to others on the underlying implementation.

@aduth

aduth approved these changes Nov 6, 2018

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 👍

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

This comment has been minimized.

@aduth

aduth Nov 6, 2018

Member

Could do for a JSDoc.

@susanpaigen

This comment has been minimized.

susanpaigen commented Nov 7, 2018

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

    This comment has been minimized.

    Member

    danielbachhuber commented Nov 7, 2018

    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 :)

    @iseulde iseulde merged commit 489eb79 into master Nov 7, 2018

    1 check passed

    continuous-integration/travis-ci/pr The Travis CI build passed
    Details

    @iseulde iseulde deleted the try/separate-paste-handler branch Nov 7, 2018

    grey-rsi pushed a commit to OnTheGoSystems/gutenberg that referenced this pull request Nov 22, 2018

    Separate Paste Handler (WordPress#11539)
    * Separate paste handler
    
    * Add test for WP raw HTML conversion
    
    * Add docs
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment