Written by Anonymous

const { __ } = wp.i18n;
const { registerFormatType,  insert } = wp.richText;
const { Toolbar, ToolbarButton } = wp.components;
const { BlockFormatControls } = wp.editor;

registerFormatType( 'cocoon/shortcode', {
    title: 'Inline Shortcode',
    tagName: 'star',
	className: null,
	edit( { value, onChange } ) {
		const onToggle = () => onChange( insert( value, '[star]', value.start, value.end ) );

		return (
			<BlockFormatControls>
				<div className="editor-format-toolbar block-editor-format-toolbar">
					<Toolbar>
						<ToolbarButton
							icon = { 'star-filled' }
							title = { 'Star Shortcode' }
							onClick = { onToggle }
						/>
					</Toolbar>
				</div>
			</BlockFormatControls>
		);
	},
} );
Notepad
Select All