diff --git a/packages/block-library/src/quote/transforms.js b/packages/block-library/src/quote/transforms.js index 18716d3b11308b..6f922d1794e19e 100644 --- a/packages/block-library/src/quote/transforms.js +++ b/packages/block-library/src/quote/transforms.js @@ -1,11 +1,7 @@ /** * WordPress dependencies */ -import { - createBlock, - parseWithAttributeSchema, - rawHandler, -} from '@wordpress/blocks'; +import { createBlock, parseWithAttributeSchema } from '@wordpress/blocks'; const transforms = { from: [ @@ -59,7 +55,7 @@ const transforms = { }, } ), selector: 'blockquote', - transform: ( node ) => { + transform: ( node, handler ) => { return createBlock( 'core/quote', // Don't try to parse any `cite` out of this content. @@ -68,7 +64,7 @@ const transforms = { // * If the cite is nested in the quoted text, it's wrong to // remove it. {}, - rawHandler( { + handler( { HTML: node.innerHTML, mode: 'BLOCKS', } ) diff --git a/packages/blocks/src/api/raw-handling/html-to-blocks.js b/packages/blocks/src/api/raw-handling/html-to-blocks.js index e31905ba82c9b7..18630a9abdce45 100644 --- a/packages/blocks/src/api/raw-handling/html-to-blocks.js +++ b/packages/blocks/src/api/raw-handling/html-to-blocks.js @@ -10,11 +10,13 @@ import { getRawTransforms } from './get-raw-transforms'; * top-level tag. The HTML should be filtered to not have any text between * top-level tags and formatted in a way that blocks can handle the HTML. * - * @param {string} html HTML to convert. + * @param {string} html HTML to convert. + * @param {Function} handler The handler calling htmlToBlocks: either rawHandler + * or pasteHandler. * * @return {Array} An array of blocks. */ -export function htmlToBlocks( html ) { +export function htmlToBlocks( html, handler ) { const doc = document.implementation.createHTMLDocument( '' ); doc.body.innerHTML = html; @@ -36,7 +38,7 @@ export function htmlToBlocks( html ) { const { transform, blockName } = rawTransform; if ( transform ) { - return transform( node ); + return transform( node, handler ); } return createBlock( diff --git a/packages/blocks/src/api/raw-handling/index.js b/packages/blocks/src/api/raw-handling/index.js index d534cfaf14bb04..afd68a4a9e1e7b 100644 --- a/packages/blocks/src/api/raw-handling/index.js +++ b/packages/blocks/src/api/raw-handling/index.js @@ -71,7 +71,7 @@ export function rawHandler( { HTML = '' } ) { piece = deepFilterHTML( piece, filters, blockContentSchema ); piece = normaliseBlocks( piece ); - return htmlToBlocks( piece ); + return htmlToBlocks( piece, rawHandler ); } ) .flat() .filter( Boolean ); diff --git a/packages/blocks/src/api/raw-handling/paste-handler.js b/packages/blocks/src/api/raw-handling/paste-handler.js index eecf70e3e99ea0..aa9f99037a39e9 100644 --- a/packages/blocks/src/api/raw-handling/paste-handler.js +++ b/packages/blocks/src/api/raw-handling/paste-handler.js @@ -209,7 +209,7 @@ export function pasteHandler( { // Allows us to ask for this information when we get a report. console.log( 'Processed HTML piece:\n\n', piece ); - return htmlToBlocks( piece ); + return htmlToBlocks( piece, pasteHandler ); } ) .flat() .filter( Boolean ); diff --git a/test/integration/blocks-raw-handling.test.js b/test/integration/blocks-raw-handling.test.js index 6e3f0e63aba946..14f38348bc68ae 100644 --- a/test/integration/blocks-raw-handling.test.js +++ b/test/integration/blocks-raw-handling.test.js @@ -345,6 +345,7 @@ describe( 'Blocks raw handling', () => { 'wordpress', 'gutenberg', 'shortcode-matching', + 'slack-quote', ].forEach( ( type ) => { // eslint-disable-next-line jest/valid-title it( type, () => { diff --git a/test/integration/fixtures/documents/slack-quote-in.html b/test/integration/fixtures/documents/slack-quote-in.html new file mode 100644 index 00000000000000..6e18f3e462f136 --- /dev/null +++ b/test/integration/fixtures/documents/slack-quote-in.html @@ -0,0 +1 @@ +
Test with link.\ No newline at end of file diff --git a/test/integration/fixtures/documents/slack-quote-out.html b/test/integration/fixtures/documents/slack-quote-out.html new file mode 100644 index 00000000000000..b5f9f82483d788 --- /dev/null +++ b/test/integration/fixtures/documents/slack-quote-out.html @@ -0,0 +1,5 @@ + +
++ \ No newline at end of fileTest with link.
+