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

//
// toHTMLString
//
RT.toHTMLString({ value: VALUE });
RT.toHTMLString({ value: VALUE, multilineTag: 'p' });

//
// toggleFormat
//
RT.toggleFormat(VALUE, FORMAT);
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
//
// 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);
RT.split(VALUE, 5, 10);
RT.split(VALUE, undefined, 5);

//
// toHTMLString
//
RT.toHTMLString({ value: VALUE });
RT.toHTMLString({ value: VALUE, multilineTag: 'p' });

//
// toggleFormat
//
RT.toggleFormat(VALUE, FORMAT);

//
// unregisterFormatType
//
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
//
// 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);
RT.split(VALUE, 5, 10);
RT.split(VALUE, undefined, 5);

//
// toHTMLString
//
RT.toHTMLString({ value: VALUE });
RT.toHTMLString({ value: VALUE, multilineTag: 'p' });

//
// toggleFormat
//
RT.toggleFormat(VALUE, FORMAT);

//
// unregisterFormatType
//
RT.unregisterFormatType('foo');
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
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);
RT.split(VALUE, 5, 10);
RT.split(VALUE, undefined, 5);

//
// toHTMLString
//
RT.toHTMLString({ value: VALUE });
RT.toHTMLString({ value: VALUE, multilineTag: 'p' });

//
// toggleFormat
//
RT.toggleFormat(VALUE, FORMAT);

//
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
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);
RT.split(VALUE, 5, 10);
RT.split(VALUE, undefined, 5);

//
// toHTMLString
//
RT.toHTMLString({ value: VALUE });
RT.toHTMLString({ value: VALUE, multilineTag: 'p' });

//
// toggleFormat
//
RT.toggleFormat(VALUE, FORMAT);

//
// unregisterFormatType
github DefinitelyTyped / DefinitelyTyped / types / wordpress__rich-text / wordpress__rich-text-tests.tsx View on Github external
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);
RT.split(VALUE, 5, 10);
RT.split(VALUE, undefined, 5);

//
// toHTMLString
//
RT.toHTMLString({ value: VALUE });
RT.toHTMLString({ value: VALUE, multilineTag: 'p' });

//
// toggleFormat
//
RT.toggleFormat(VALUE, FORMAT);
github WordPress / gutenberg / packages / block-library / src / quote / transforms.js View on Github external
transform: ( { value, citation, ...attrs } ) => {
				// If there is no quote content, use the citation as the
				// content of the resulting heading. A nonexistent citation
				// will result in an empty heading.
				if ( value === '<p></p>' ) {
					return createBlock( 'core/heading', {
						content: citation,
					} );
				}

				const pieces = split( create( { html: value, multilineTag: 'p' } ), '\u2028' );

				const headingBlock = createBlock( 'core/heading', {
					content: toHTMLString( { value: pieces[ 0 ] } ),
				} );

				if ( ! citation &amp;&amp; pieces.length === 1 ) {
					return headingBlock;
				}

				const quotePieces = pieces.slice( 1 );

				const quoteBlock = createBlock( 'core/quote', {
					...attrs,
					citation,
					value: toHTMLString( {
						value: quotePieces.length ? join( pieces.slice( 1 ), '\u2028' ) : create(),
github WordPress / gutenberg / packages / block-editor / src / components / rich-text / index.js View on Github external
const splitValue = useCallback( ( record, pastedBlocks = [] ) => {
		if ( ! onReplace || ! onSplit ) {
			return;
		}

		const blocks = [];
		const [ before, after ] = split( record );
		const hasPastedBlocks = pastedBlocks.length > 0;

		// Create a block with the content before the caret if there's no pasted
		// blocks, or if there are pasted blocks and the value is not empty.
		// We do not want a leading empty block on paste, but we do if split
		// with e.g. the enter key.
		if ( ! hasPastedBlocks || ! isEmpty( before ) ) {
			blocks.push( onSplit( toHTMLString( {
				value: before,
				multilineTag,
			} ) ) );
		}

		if ( hasPastedBlocks ) {
			blocks.push( ...pastedBlocks );
		} else if ( onSplitMiddle ) {
github WordPress / gutenberg / packages / block-library / src / quote / transforms.js View on Github external
transform: ( { value, citation } ) =&gt; {
				const paragraphs = [];
				if ( value &amp;&amp; value !== '<p></p>' ) {
					paragraphs.push(
						...split( create( { html: value, multilineTag: 'p' } ), '\u2028' )
							.map( ( piece ) =&gt;
								createBlock( 'core/paragraph', {
									content: toHTMLString( { value: piece } ),
								} )
							)
					);
				}
				if ( citation &amp;&amp; citation !== '<p></p>' ) {
					paragraphs.push(
						createBlock( 'core/paragraph', {
							content: citation,
						} )
					);
				}

				if ( paragraphs.length === 0 ) {