diff --git a/packages/block-library/src/code/block.json b/packages/block-library/src/code/block.json index d39e5f213bbe6c..354d30b04fd6dc 100644 --- a/packages/block-library/src/code/block.json +++ b/packages/block-library/src/code/block.json @@ -4,7 +4,7 @@ "attributes": { "content": { "type": "string", - "source": "text", + "source": "html", "selector": "code" } } diff --git a/packages/block-library/src/code/test/utils.js b/packages/block-library/src/code/test/utils.js index 4926eef16d5282..4dbf5e1c40e42c 100644 --- a/packages/block-library/src/code/test/utils.js +++ b/packages/block-library/src/code/test/utils.js @@ -38,6 +38,11 @@ describe( 'core/code', () => { expect( text ).toBe( '&' ); } ); + it( 'should unescape escaped less than and greater than characters', () => { + const text = unescape( '<button>Click</button>' ); + expect( text ).toBe( '' ); + } ); + it( 'should unescape escaped opening square brackets', () => { const text = unescape( '[shortcode][/shortcode]' ); expect( text ).toBe( '[shortcode][/shortcode]' ); diff --git a/packages/block-library/src/code/utils.js b/packages/block-library/src/code/utils.js index fb8557a95b18ee..c5f2040db90481 100644 --- a/packages/block-library/src/code/utils.js +++ b/packages/block-library/src/code/utils.js @@ -27,6 +27,7 @@ export function unescape( content ) { return flow( unescapeProtocolInIsolatedUrls, unescapeOpeningSquareBrackets, + unescapeTagDelimiters, unescapeAmpersands )( content || '' ); } @@ -54,6 +55,18 @@ function unescapeAmpersands( content ) { return content.replace( /&/g, '&' ); } +/** + * Returns the given content with all < and > HTML entities converted + * into < and >, respectively. + * + * @param {string} content The content of a code block. + * @return {string} The given content with all < and > HTML entities + * converted into < and >, respectively + */ +function unescapeTagDelimiters( content ) { + return content.replace( /</g, '<' ).replace( />/g, '>' ); +} + /** * Returns the given content with all opening shortcode characters converted * into their HTML entity counterpart (i.e. [ => [). For instance, a