Skip to content
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

Code blocks should be editable after saving the post and reloading the editor #15780

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/block-library/src/code/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"attributes": {
"content": {
"type": "string",
"source": "text",
"source": "html",
"selector": "code"
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/code/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( '<button>Click</button>' );
} );

it( 'should unescape escaped opening square brackets', () => {
const text = unescape( '&#91;shortcode]&#91;/shortcode]' );
expect( text ).toBe( '[shortcode][/shortcode]' );
Expand Down
13 changes: 13 additions & 0 deletions packages/block-library/src/code/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function unescape( content ) {
return flow(
unescapeProtocolInIsolatedUrls,
unescapeOpeningSquareBrackets,
unescapeTagDelimiters,
unescapeAmpersands
)( content || '' );
}
Expand Down Expand Up @@ -54,6 +55,18 @@ function unescapeAmpersands( content ) {
return content.replace( /&amp;/g, '&' );
}

/**
* Returns the given content with all &lt; and &gt; HTML entities converted
* into < and >, respectively.
*
* @param {string} content The content of a code block.
* @return {string} The given content with all &lt; and &gt; HTML entities
* converted into < and >, respectively
*/
function unescapeTagDelimiters( content ) {
return content.replace( /&lt;/g, '<' ).replace( /&gt;/g, '>' );
}

/**
* Returns the given content with all opening shortcode characters converted
* into their HTML entity counterpart (i.e. [ => &#91;). For instance, a
Expand Down