From ba9fd5c4590752ec6d700eee56fe06633a2fdada Mon Sep 17 00:00:00 2001 From: John Godley Date: Fri, 12 Oct 2018 12:33:45 +0100 Subject: [PATCH] Exclude blocks of type 'html' from processed by hpq This allows the HTML to be retained in the original format without processing and reformatting --- packages/blocks/src/api/parser.js | 4 ++++ packages/blocks/src/api/test/parser.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/blocks/src/api/parser.js b/packages/blocks/src/api/parser.js index 597ceffff726c2..dfad8e10a767f7 100644 --- a/packages/blocks/src/api/parser.js +++ b/packages/blocks/src/api/parser.js @@ -226,6 +226,10 @@ export function matcherFromSource( sourceConfig ) { * @return {*} Attribute value. */ export function parseWithAttributeSchema( innerHTML, attributeSchema ) { + if ( attributeSchema.source === 'html' && ! attributeSchema.selector ) { + return innerHTML; + } + return hpqParse( innerHTML, matcherFromSource( attributeSchema ) ); } diff --git a/packages/blocks/src/api/test/parser.js b/packages/blocks/src/api/test/parser.js index bc059542b01422..9c9c80b548d8d2 100644 --- a/packages/blocks/src/api/test/parser.js +++ b/packages/blocks/src/api/test/parser.js @@ -287,6 +287,20 @@ describe( 'block parser', () => { ); expect( value ).toBeUndefined(); } ); + + it( 'should return original content for html source with no selector', () => { + const value = getBlockAttribute( + 'content', + { + type: 'string', + source: 'html', + }, + '', + {} + ); + + expect( value ).toBe( '' ); + } ); } ); describe( 'getBlockAttributes()', () => {