diff --git a/blocks/api/raw-handling/blockquote-normaliser.js b/blocks/api/raw-handling/blockquote-normaliser.js index 58633866f5a84..b3c21149adce6 100644 --- a/blocks/api/raw-handling/blockquote-normaliser.js +++ b/blocks/api/raw-handling/blockquote-normaliser.js @@ -2,12 +2,23 @@ * Internal dependencies */ import normaliseBlocks from './normalise-blocks'; +import { isInlineWrapper } from './utils'; /** * Browser dependencies */ const { ELEMENT_NODE } = window.Node; +function replace( node, tagName ) { + const newNode = document.createElement( tagName ); + + while ( node.firstChild ) { + newNode.appendChild( node.firstChild ); + } + + node.parentNode.replaceChild( newNode, node ); +} + export default function( node ) { if ( node.nodeType !== ELEMENT_NODE ) { return; @@ -17,5 +28,14 @@ export default function( node ) { return; } + Array.from( node.childNodes ).forEach( ( childNode ) => { + // Quote component only handle p tag inside blockquote tag + // normaliseBlocks will not wrap any inline wrapper tag with p so we have to do it manually. + // If child node is inline wrapper node and not paragraph then convert it to paragraph. + if ( isInlineWrapper( childNode ) && node.nodeName.toLowerCase() !== 'p' ) { + replace( childNode, 'p' ); + } + } ); + node.innerHTML = normaliseBlocks( node.innerHTML ); } diff --git a/blocks/api/raw-handling/test/blockquote-normaliser.js b/blocks/api/raw-handling/test/blockquote-normaliser.js index 151b545f57862..1cb52c6b969e2 100644 --- a/blocks/api/raw-handling/test/blockquote-normaliser.js +++ b/blocks/api/raw-handling/test/blockquote-normaliser.js @@ -15,4 +15,22 @@ describe( 'blockquoteNormaliser', () => { const output = '

test

'; equal( deepFilterHTML( input, [ blockquoteNormaliser ] ), output ); } ); + + it( 'should normalise blockquote containing inline wrapper tag', () => { + const input = '

test

'; + const output = '

test

'; + equal( deepFilterHTML( input, [ blockquoteNormaliser ] ), output ); + } ); + + it( 'should normalise blockquote containing multiple inline tags', () => { + const input = '

test

test2

'; + const output = '

test

test2

'; + equal( deepFilterHTML( input, [ blockquoteNormaliser ] ), output ); + } ); + + it( 'should normalise blockquote containing multiple inline tags and caption', () => { + const input = '

test

cite
'; + const output = '

test

cite
'; + equal( deepFilterHTML( input, [ blockquoteNormaliser ] ), output ); + } ); } );