I am creating a block which is created when transformed from a shortcode. In other words, this:
[example att1="foo" att2="bar"]
<p>Inner.</p>
<p>Content.</p>
[/example]
should transform into this a myplugin/example block with inner blocks of the two p tags.
So far I've got this, which works fine to get the shortcode attributes.
(function(wp){
wp.blocks.registerBlockType( 'myplugin/example', {
...
attributes: {
att1 {
type: 'string',
default: '',
},
att2: {
type: 'string',
default: '',
},
},
transforms: {
from: [
{
type: 'shortcode',
tag: 'example',
attributes: {
att1: {
type: 'string',
shortcode: attributes => {
return attributes.named.att1 || '';
}
},
att2: {
type: 'string',
shortcode: attributes => {
return attributes.named.att2 || '';
},
},
},
},
],
},
...
I can get the content by looking at the second parameter in one of those attributes shortcode functions:
attributes: {
att1: {
shortcode: (attributes, data) => {
// data.shortcode.content is the shortcode's inner content
}
}
}
But I don't know how to insert that content as innerBlocks in the output block. The block registration "transforms" attribute documentation is not helpful in this area.
I've tried using the transform
attribute in the block definition, but that doesn't seem to work.