Skip to content

Commit

Permalink
Merge pull request #3610 from WordPress/fix/shortcode-catchall-transform
Browse files Browse the repository at this point in the history
Pasting: Convert unknown shortcodes to Shortcode block
  • Loading branch information
mcsf authored Nov 28, 2017
2 parents d5d7064 + 73ca3fa commit 7bad210
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion blocks/api/raw-handling/shortcode-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './shortcode';
import './image';
import './gallery';
import './heading';
Expand All @@ -16,7 +17,6 @@ import './freeform';
import './latest-posts';
import './categories';
import './cover-image';
import './shortcode';
import './text-columns';
import './verse';
import './video';
Expand Down
21 changes: 21 additions & 0 deletions blocks/library/shortcode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 7bad210

Please sign in to comment.