How to use the @wordpress/rich-text.replace 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.remove(VALUE, 10);
RT.remove(VALUE, 10, 20);

//
// removeFormat
//
RT.removeFormat(VALUE, 'foo');
RT.removeFormat(VALUE, 'foo', 10);

//
// replace
//
RT.replace(VALUE, 'foo', 'bar');
RT.replace(VALUE, /foo/, 'bar');
RT.replace(VALUE, 'foo', match => `${match}bar`);
RT.replace(VALUE, /foo/, match => `${match}bar`);
RT.replace(VALUE, 'foo', (match, a, b) => `${match} ${a} ${b}`);

//
// slice
//
RT.slice(VALUE);
RT.slice(VALUE, 10);
RT.slice(VALUE, 10, 20);

//
// split
//
RT.split(VALUE);
RT.split(VALUE, 'foo');
RT.split(VALUE, 5);
RT.split(VALUE, 'foo', 10);
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
RT.remove(VALUE);
RT.remove(VALUE, 10);
RT.remove(VALUE, 10, 20);

//
// removeFormat
//
RT.removeFormat(VALUE, 'foo');
RT.removeFormat(VALUE, 'foo', 10);

//
// replace
//
RT.replace(VALUE, 'foo', 'bar');
RT.replace(VALUE, /foo/, 'bar');
RT.replace(VALUE, 'foo', match => `${match}bar`);
RT.replace(VALUE, /foo/, match => `${match}bar`);
RT.replace(VALUE, 'foo', (match, a, b) => `${match} ${a} ${b}`);

//
// slice
//
RT.slice(VALUE);
RT.slice(VALUE, 10);
RT.slice(VALUE, 10, 20);

//
// split
//
RT.split(VALUE);
RT.split(VALUE, 'foo');
RT.split(VALUE, 5);
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
//
RT.remove(VALUE);
RT.remove(VALUE, 10);
RT.remove(VALUE, 10, 20);

//
// removeFormat
//
RT.removeFormat(VALUE, 'foo');
RT.removeFormat(VALUE, 'foo', 10);

//
// replace
//
RT.replace(VALUE, 'foo', 'bar');
RT.replace(VALUE, /foo/, 'bar');
RT.replace(VALUE, 'foo', match => `${match}bar`);
RT.replace(VALUE, /foo/, match => `${match}bar`);
RT.replace(VALUE, 'foo', (match, a, b) => `${match} ${a} ${b}`);

//
// slice
//
RT.slice(VALUE);
RT.slice(VALUE, 10);
RT.slice(VALUE, 10, 20);

//
// split
//
RT.split(VALUE);
RT.split(VALUE, 'foo');
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
// remove
//
RT.remove(VALUE);
RT.remove(VALUE, 10);
RT.remove(VALUE, 10, 20);

//
// removeFormat
//
RT.removeFormat(VALUE, 'foo');
RT.removeFormat(VALUE, 'foo', 10);

//
// replace
//
RT.replace(VALUE, 'foo', 'bar');
RT.replace(VALUE, /foo/, 'bar');
RT.replace(VALUE, 'foo', match => `${match}bar`);
RT.replace(VALUE, /foo/, match => `${match}bar`);
RT.replace(VALUE, 'foo', (match, a, b) => `${match} ${a} ${b}`);

//
// slice
//
RT.slice(VALUE);
RT.slice(VALUE, 10);
RT.slice(VALUE, 10, 20);

//
// split
//
RT.split(VALUE);
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / index.js View on Github external
// If there are active formats, merge them with the pasted formats.
			if ( activeFormats.length ) {
				let index = valueToInsert.formats.length;

				while ( index-- ) {
					valueToInsert.formats[ index ] = [
						...activeFormats,
						...( valueToInsert.formats[ index ] || [] ),
					];
				}
			}

			// If the content should be multiline, we should process text
			// separated by a line break as separate lines.
			if ( multiline ) {
				valueToInsert = replace( valueToInsert, /\n+/g, LINE_SEPARATOR );
			}

			onChange( insert( value, valueToInsert ) );
		} else if ( content.length > 0 ) {
			if ( onReplace && isEmpty( value ) ) {
				onReplace( content );
			} else {
				splitValue( value, content );
			}
		}
	}, [
		tagName,