Skip to content

Re-evaluate shortcode blocks for more specific shortcode transforms #8569

@ccprog

Description

@ccprog

We're currently in a situation where some plugins using shortcodes do not yet convert them to blocks, but might do so at a later time.

This leads to the following scenario: A user has content containing shortcodes. He/she opens it in the Gutenberg editor and converts it to blocks. The shortcodes will be converted to a core/shortcode block. Later (and this might happen for a long time) the plugin developer decides to provide a conversion specific to his/her shortcodes. This transformation will never match the shortcode block, because it is only considered for raw handling.

For my plugin, I was able to solve this with a second from-transform:

{
    type: 'block',
    blocks: ['core/shortcode'],
    isMatch: ( {text} ) => {
        const re = wp.shortcode.regexp('crosswordsearch');
        return re.test(text);
    },
    transform: ( {text} ) => {
        return wp.blocks.rawHandler({
            HTML: '<p>' + text + '</p>',
            mode: 'BLOCKS'
        });
    },
    priority: 15
}

Instead of every developer implementing something like this, it would be much better to define this as a to-transform on the core/shortcode block with

  • a blocks list of all block type names that offer type: 'shortcode' from-transforms.
  • isMatch testing for all the tags named in those block types

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions