diff --git a/packages/format-library/src/default-formats.js b/packages/format-library/src/default-formats.js index 3ccfc92cb40c18..1bd7a3e057e1b6 100644 --- a/packages/format-library/src/default-formats.js +++ b/packages/format-library/src/default-formats.js @@ -15,6 +15,7 @@ import { keyboard } from './keyboard'; import { unknown } from './unknown'; import { language } from './language'; import { nonBreakingSpace } from './non-breaking-space'; +import { lineBreakWbr, softHyphen } from './line-break'; export default [ bold, @@ -31,4 +32,6 @@ export default [ unknown, language, nonBreakingSpace, + lineBreakWbr, + softHyphen, ]; diff --git a/packages/format-library/src/line-break/index.js b/packages/format-library/src/line-break/index.js new file mode 100644 index 00000000000000..fca251382bd44c --- /dev/null +++ b/packages/format-library/src/line-break/index.js @@ -0,0 +1,58 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { insert, insertObject } from '@wordpress/rich-text'; +import { RichTextToolbarButton } from '@wordpress/block-editor'; +import { keyboardReturn, lineDashed } from '@wordpress/icons'; + +const nameWbr = 'core/line-break-wbr'; +const titleWbr = __( 'Word break' ); + +export const lineBreakWbr = { + name: nameWbr, + title: titleWbr, + tagName: 'wbr', + object: true, + className: 'wp-inline-wbr', + edit( { value, onChange, onFocus } ) { + const onClick = () => { + onChange( insertObject( value, { type: nameWbr } ) ); + onFocus(); + }; + + return ( + + ); + }, +}; + +const nameShy = 'core/soft-hyphen'; +const titleShy = __( 'Soft hyphen' ); + +export const softHyphen = { + name: nameShy, + title: titleShy, + tagName: 'span', + className: 'is-soft-hyphen-format', + edit( { value, onChange, onFocus } ) { + const onClick = () => { + onChange( insert( value, '\u00AD' ) ); + onFocus(); + }; + + return ( + + ); + }, +};