How to use the @wordpress/rich-text.registerFormatType function in @wordpress/rich-text

To help you get started, we’ve selected a few @wordpress/rich-text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
//
RT.join([VALUE, VALUE]);
RT.join([], VALUE);
RT.join([], 'foo');
RT.join([VALUE], 'foo');

//
// registerFormatType
//
RT.registerFormatType('foo', {
    tagName: 'span',
    className: 'foo',
    title: 'Foo',
    edit: () =&gt; <span>Hello World</span>,
});
RT.registerFormatType('foo', {
    tagName: 'span',
    className: null,
    title: 'Foo',
    keywords: ['foo', 'bar', 'baz'],
    object: false,
    attributes: {
        className: 'class',
        myFoo: 'data-my-foo',
    },
    edit(props) {
        return <span data-is-active="{props.isActive}">{props.value}</span>;
    },
});

//
// remove
github livinglab / openlab / wp-content / plugins / openlab-attributions / dist / js / formats / index.js View on Github external
/**
 * WordPress dependencies
 */
import { registerFormatType } from '@wordpress/rich-text';

/**
 * Internal dependencies
 */
import Edit from './edit';

// Register fake format.
registerFormatType( 'ol/attributions', {
	title: 'Attribution',
	tagName: 'a',
	className: 'attribution-anchor',
	edit: Edit,
} );
github gambitph / Stackable / src / format-types / highlight / index.js View on Github external
colorType === 'low' ? '' :
										highlightColor || textColor || ''

								onChange( createApplyFormat( value, colorType, defaultTextColor, defaultHighlightColor ), { withoutHistory: true } )
							} }
							isSmall
						/&gt;
					
				
				}
			
		
	)
}

registerFormatType(
	'ugb/highlight', {
		title: __( 'Highlight Text', i18n ),
		tagName: 'span',
		className: 'ugb-highlight',
		edit: HighlightButton,
		attributes: {
			style: 'style',
		},
	}
)

domReady( () =&gt; {
	// Turn off EditorsKit features to prevent duplicates.
	if ( ! select( 'core/edit-post' ).isFeatureActive( 'disableEditorsKitColorsFormats' ) ) {
		dispatch( 'core/edit-post' ).toggleFeature( 'disableEditorsKitColorsFormats' )
	}
github Automattic / wp-calypso / apps / wpcom-block-editor / src / default / features / rich-text.js View on Github external
const unsubscribe = subscribe( () =&gt; {
	const underlineFormat = select( 'core/rich-text' ).getFormatType( 'core/underline' );
	if ( ! underlineFormat ) {
		return;
	}
	unsubscribe();
	const settings = unregisterFormatType( 'core/underline' );
	registerFormatType( 'wpcom/underline', {
		...settings,
		name: 'wpcom/underline',
		edit( { isActive, value, onChange } ) {
			const onToggle = () =&gt;
				onChange(
					toggleFormat( value, {
						type: 'wpcom/underline',
						attributes: {
							style: 'text-decoration: underline;',
						},
					} )
				);

			return (
github WordPress / gutenberg / packages / format-library / src / index.js View on Github external
].forEach( ( { name, ...settings } ) => registerFormatType( name, settings ) );
github godaddy-wordpress / coblocks / src / formats / index.js View on Github external
].forEach( ( { name, settings } ) => {
		registerFormatType( name, settings );
	} );
}
github Automattic / wp-calypso / apps / wpcom-block-editor / src / default / features / rich-text.js View on Github external
if ( ! selectedBlock ) {
			return {};
		}
		return {
			blockId: selectedBlock.clientId,
			blockName: selectedBlock.name,
			isBlockJustified: 'justify' === get( selectedBlock, 'attributes.align' ),
		};
	} ),
	withDispatch( dispatch => ( {
		updateBlockAttributes: dispatch( 'core/editor' ).updateBlockAttributes,
	} ) ),
	ifCondition( props => 'core/paragraph' === props.blockName )
)( RichTextJustifyButton );

registerFormatType( 'wpcom/justify', {
	title: wpcomGutenberg.richTextToolbar.justify,
	tagName: 'p',
	className: null,
	edit: ConnectedRichTextJustifyButton,
} );
github ampproject / amp-wp / assets / src / stories-editor / index.js View on Github external
formats.keys().sort( ( a, b ) => ( a.priority > b.priority ) ? 1 : -1 ).forEach( ( modulePath ) => {
	const { name, settings } = formats( modulePath );
	registerFormatType( name, settings );
} );
github insideout10 / wordlift-plugin / src / src / js / src / block-editor / formats / register-format-type-wordlift-annotation.js View on Github external
* WordPress dependencies
 */
import { registerFormatType } from "@wordpress/rich-text";
import { Fragment } from "@wordpress/element";
import { doAction } from "@wordpress/hooks";

/**
 * Internal dependencies
 */
import EditComponent from "./edit-component";

/**
 * @see https://developer.wordpress.org/block-editor/tutorials/format-api/1-register-format/
 */

registerFormatType("wordlift/annotation", {
  /*
   * The `attributes` property is undocumented as basically the `WPFormat` class.
   *
   * Run this in the Developer Tools > Console to see what other formats return
   * as WPFormat:
   *  wp.data.select( 'core/rich-text' ).getFormatTypes();
   */
  attributes: { id: "id", class: "class", itemid: "itemid" },
  tagName: "span",
  className: "textannotation",
  title: "Annotation",
  edit: EditComponent
});