Skip to content

Commit

Permalink
Change to RichText
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Sep 24, 2020
1 parent 6c398a9 commit 0530500
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
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
9 changes: 2 additions & 7 deletions packages/block-library/src/code/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import {
PlainText,
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function CodeEdit( { attributes, setAttributes } ) {
const blockWrapperProps = useBlockWrapperProps();
return (
<pre { ...blockWrapperProps }>
<PlainText
__experimentalVersion={ 2 }
<RichText
tagName="code"
value={ attributes.content }
onChange={ ( content ) => setAttributes( { content } ) }
Expand Down
10 changes: 9 additions & 1 deletion packages/block-library/src/code/save.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
Expand All @@ -6,7 +11,10 @@ import { escape } from './utils';
export default function save( { attributes } ) {
return (
<pre>
<code>{ escape( attributes.content ) }</code>
<RichText.Content
tagName="code"
value={ escape( attributes.content ) }
/>
</pre>
);
}
6 changes: 0 additions & 6 deletions packages/block-library/src/code/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
*/
import { flow } from 'lodash';

/**
* WordPress dependencies
*/
import { escapeEditableHTML } from '@wordpress/escape-html';

/**
* Escapes ampersands, shortcodes, and links.
*
Expand All @@ -16,7 +11,6 @@ import { escapeEditableHTML } from '@wordpress/escape-html';
*/
export function escape( content ) {
return flow(
escapeEditableHTML,
escapeOpeningSquareBrackets,
escapeProtocolInIsolatedUrls
)( content || '' );
Expand Down

0 comments on commit 0530500

Please sign in to comment.