diff --git a/blocks/api/raw-handling/shortcode-converter.js b/blocks/api/raw-handling/shortcode-converter.js index 0b429b8063dce9..040b08a9c83cf9 100644 --- a/blocks/api/raw-handling/shortcode-converter.js +++ b/blocks/api/raw-handling/shortcode-converter.js @@ -33,7 +33,10 @@ export default function( HTML ) { const attributes = mapValues( pickBy( transform.attributes, ( schema ) => schema.shortcode ), - ( schema ) => schema.shortcode( match.shortcode.attrs ), + // Passing all of `match` as second argument is intentionally + // broad but shouldn't be too relied upon. See + // https://github.com/WordPress/gutenberg/pull/3610#discussion_r152546926 + ( schema ) => schema.shortcode( match.shortcode.attrs, match ), ); const block = createBlock( diff --git a/blocks/library/index.js b/blocks/library/index.js index 45bda0a9f84f39..d12af4f1efafe1 100644 --- a/blocks/library/index.js +++ b/blocks/library/index.js @@ -1,3 +1,4 @@ +import './shortcode'; import './image'; import './gallery'; import './heading'; @@ -16,7 +17,6 @@ import './freeform'; import './latest-posts'; import './categories'; import './cover-image'; -import './shortcode'; import './text-columns'; import './verse'; import './video'; diff --git a/blocks/library/shortcode/index.js b/blocks/library/shortcode/index.js index 9ae142a954e723..f94922e0d67ac7 100644 --- a/blocks/library/shortcode/index.js +++ b/blocks/library/shortcode/index.js @@ -31,6 +31,27 @@ registerBlockType( 'core/shortcode', { }, }, + transforms: { + from: [ + { + type: 'shortcode', + // Per "Shortcode names should be all lowercase and use all + // letters, but numbers and underscores should work fine too. + // Be wary of using hyphens (dashes), you'll be better off not + // using them." in https://codex.wordpress.org/Shortcode_API + tag: '[a-z0-9_-]+', + attributes: { + text: { + type: 'string', + shortcode: ( attrs, { content } ) => { + return content; + }, + }, + }, + }, + ], + }, + supportHTML: false, supports: {