How to use the @wordpress/rich-text.getTextContent 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 WordPress / gutenberg / packages / block-editor / src / components / block-navigation / list.js View on Github external
function getBlockDisplayName( blockType, attributes ) {
	const displayNameAttribute = blockType.__experimentalDisplayName;

	if ( ! displayNameAttribute || ! attributes[ displayNameAttribute ] ) {
		return blockType.title;
	}

	// Strip any formatting.
	const richTextValue = create( { html: attributes[ displayNameAttribute ] } );
	const formatlessDisplayName = getTextContent( richTextValue );

	return formatlessDisplayName;
}
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / patterns.js View on Github external
( record ) => {
			const BACKTICK = '`';
			const { start } = record;
			const text = getTextContent( record );
			const characterBefore = text.slice( start - 1, start );

			// Quick check the text for the necessary character.
			if ( characterBefore !== BACKTICK ) {
				return record;
			}

			const textBefore = text.slice( 0, start - 1 );
			const indexBefore = textBefore.lastIndexOf( BACKTICK );

			if ( indexBefore === -1 ) {
				return record;
			}

			const startIndex = indexBefore;
			const endIndex = start - 2;
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / patterns.js View on Github external
return ( record, onReplace ) => {
		const text = getTextContent( record );
		const transformation = findTransform( transforms, ( item ) => {
			return item.regExp.test( text );
		} );

		if ( ! transformation ) {
			return record;
		}

		onReplace( [
			transformation.transform( { content: text } ),
		] );
	};
}
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / patterns.js View on Github external
( record, onReplace, valueToFormat ) => {
			if ( ! onReplace ) {
				return record;
			}

			const { start } = record;
			const text = getTextContent( record );
			const characterBefore = text.slice( start - 1, start );

			if ( ! /\s/.test( characterBefore ) ) {
				return record;
			}

			const trimmedTextBefore = text.slice( 0, start ).trim();
			const transformation = findTransform( prefixTransforms, ( { prefix } ) => {
				return trimmedTextBefore === prefix;
			} );

			if ( ! transformation ) {
				return record;
			}

			const content = valueToFormat( slice( record, start, text.length ) );
github WordPress / gutenberg / packages / components / src / autocomplete / index.js View on Github external
componentDidUpdate( prevProps, prevState ) {
		const { record, completers } = this.props;
		const { record: prevRecord } = prevProps;
		const { open: prevOpen } = prevState;

		if ( ( ! this.state.open ) !== ( ! prevOpen ) ) {
			this.toggleKeyEvents( ! ! this.state.open );
		}

		if ( isCollapsed( record ) ) {
			const text = deburr( getTextContent( slice( record, 0 ) ) );
			const prevText = deburr( getTextContent( slice( prevRecord, 0 ) ) );

			if ( text !== prevText ) {
				const textAfterSelection = getTextContent( slice( record, undefined, getTextContent( record ).length ) );
				const allCompleters = map( completers, ( completer, idx ) => ( { ...completer, idx } ) );
				const open = find( allCompleters, ( { triggerPrefix, allowContext } ) => {
					const index = text.lastIndexOf( triggerPrefix );

					if ( index === -1 ) {
						return false;
					}

					if ( allowContext && ! allowContext( text.slice( 0, index ), textAfterSelection ) ) {
						return false;
					}

					return /^\S*$/.test( text.slice( index + triggerPrefix.length ) );
				} );

				if ( ! open ) {