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

Pasting: Convert unknown shortcodes to Shortcode block #3610

Merged
merged 1 commit into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change? It makes me nervous that we depend on load order of blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. See #3326 (comment). My thinking is that we can get away with it for now in library, and we could soon start to think of a mechanism based on explicit priority.

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