diff --git a/packages/block-library/src/code/edit.js b/packages/block-library/src/code/edit.js index a3dbedeaf23352..b61edfcd86e8d5 100644 --- a/packages/block-library/src/code/edit.js +++ b/packages/block-library/src/code/edit.js @@ -5,6 +5,13 @@ import { __ } from '@wordpress/i18n'; import { RichText, useBlockProps } from '@wordpress/block-editor'; import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; +const SUPPORTS_BREAK_SPACES = + typeof CSS !== 'undefined' && + // eslint-disable-next-line no-undef + CSS.supports && + // eslint-disable-next-line no-undef + CSS.supports( 'white-space', 'break-spaces' ); + export default function CodeEdit( { attributes, setAttributes, @@ -13,6 +20,9 @@ export default function CodeEdit( { mergeBlocks, } ) { const blockProps = useBlockProps(); + + const whiteSpaceStyle = SUPPORTS_BREAK_SPACES ? 'break-spaces' : 'pre-wrap'; + return (
); diff --git a/packages/block-library/src/code/style.scss b/packages/block-library/src/code/style.scss index ccc950d19b552c..23272cd7f047cd 100644 --- a/packages/block-library/src/code/style.scss +++ b/packages/block-library/src/code/style.scss @@ -14,5 +14,9 @@ direction: ltr; text-align: initial; /*!rtl:end:ignore*/ + + @supports (white-space: break-spaces) { + white-space: break-spaces; + } } }insertBlocksAfter( createBlock( getDefaultBlockName() ) ) } + style={ { whiteSpace: whiteSpaceStyle } } />