Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the proper shortcode on paste #21864

Merged
merged 4 commits into from
Apr 29, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ function getAllowedFormats( {

getAllowedFormats.EMPTY_ARRAY = [];

// The given text is considered a shortcode if
// starts by the [ character and ends by the ] character.
const isShortcode = ( text ) => new RegExp( '^\\[.*\\]$' ).test( text );
oandregal marked this conversation as resolved.
Show resolved Hide resolved

function RichTextWrapper(
{
children,
Expand Down Expand Up @@ -393,6 +397,18 @@ function RichTextWrapper(

let mode = onReplace && onSplit ? 'AUTO' : 'INLINE';

// Force the blocks mode when the user is pasting
// on a new line & the content resembles a shortcode.
// Otherwise it's going to be detected as inline
// and the shortcode won't be replaced.
if (
mode === 'AUTO' &&
isEmpty( value ) &&
isShortcode( plainText )
) {
mode = 'BLOCKS';
}

if (
__unstableEmbedURLOnPaste &&
isEmpty( value ) &&
Expand Down