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

Prioritize specific blocks (e.g. Gallery) over Shortcode block during conversion #4706

Merged
merged 1 commit into from
Jan 27, 2018
Merged
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
21 changes: 20 additions & 1 deletion blocks/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ import * as video from './video';

export const registerCoreBlocks = () => {
[
// FIXME: Temporary fix.
//
// The Shortcode block declares a catch-all shortcode transform,
// meaning it will attempt to intercept pastes and block conversions of
// any valid shortcode-like content. Other blocks (e.g. Gallery) may
// declare specific shortcode transforms (e.g. `[gallery]`), with which
// this block would conflict. Thus, the Shortcode block needs to be
// registered as early as possible, so that any other block types'
// shortcode transforms can be honoured.
//
// This isn't a proper solution, as it is at odds with the
// specification of shortcode conversion, in the sense that conversion
// is explicitly independent of block order. Thus, concurrent parse
// rules (i.e. a same text input can yield two different transforms,
// like `[gallery] -> { Gallery, Shortcode }`) are unsupported,
// yielding non-deterministic results. A proper solution could be to
// let the editor (or site owners) determine a default block handler of
// unknown shortcodes — see `setUnknownTypeHandlerName`.
shortcode,
Copy link
Member

Choose a reason for hiding this comment

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

How about moving it out of this array to make things extra clear? registerBlockType( shortcode.name, shortcode.settings );?

Copy link
Member

Choose a reason for hiding this comment

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

Both work for me :) Hopefully it will be fixed soon as described in the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure. It feels like all the core blocks should be gathered in a single place, and the current approach of creating an array and looping over it seems more apt. Placing a registerBlockType call for Shortcode beside that loop could perhaps make it less visible?


audio,
button,
categories,
Expand All @@ -57,7 +77,6 @@ export const registerCoreBlocks = () => {
quote,
reusableBlock,
separator,
shortcode,
subhead,
table,
textColumns,
Expand Down