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

Conversation

mcsf
Copy link
Contributor

@mcsf mcsf commented Nov 22, 2017

Fixes #3062. Builds on top of #3609 (fix/shortcode-pasting-plain-text).

Description

Blocks can specify shortcodes from which blocks should be automatically created when pasting. For any other shortcode, the core Shortcode block will now act as a fallback.

The main benefit of this is that, within the Shortcode block, the code will be properly handled and never mishandled. Notably, this fixes the case where a shortcode sitting in a Paragraph block will be picked up with its double quotes rendered as ", thus breaking parsing of a shortcode's attributes.

How Has This Been Tested?

Screenshots (jpeg or gifs if applicable):

gutenberg-shortcode-paste-fallback

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@@ -33,7 +33,7 @@ export default function( HTML ) {

const attributes = mapValues(
pickBy( transform.attributes, ( schema ) => schema.shortcode ),
( schema ) => schema.shortcode( match.shortcode.attrs ),
( schema ) => schema.shortcode( match.shortcode.attrs, match ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing all of match is intentionally broad for the sake of the discussion here. For this PR, only match.content is needed. Using content seems better than attempting to reconstruct the code from the shortcode parser's output (for which we'd still need more than just match.shortcode.attrs).

@ephox-mogran
Copy link
Contributor

ephox-mogran commented Nov 23, 2017

Works well 👍

// 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_-]+',
Copy link
Member

Choose a reason for hiding this comment

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

Per above comment, should we not be matching capital letters as the regular expression here currently allows? Wondering if there's a more canonical regular expression from core code we should be leveraging, or if we should bother being strict at all.

Copy link
Contributor Author

@mcsf mcsf Nov 28, 2017

Choose a reason for hiding this comment

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

I'm fine with keeping it lowercase and simple.

@@ -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.

@mcsf mcsf force-pushed the fix/shortcode-catchall-transform branch from b714abe to 7db1c8d Compare November 28, 2017 14:06
@mcsf mcsf force-pushed the fix/shortcode-pasting-plain-text branch from 174e6b9 to 086dd25 Compare November 28, 2017 15:45
@mcsf mcsf force-pushed the fix/shortcode-catchall-transform branch from 7db1c8d to b6fdc4f Compare November 28, 2017 15:45
@mcsf mcsf mentioned this pull request Nov 28, 2017
3 tasks
@mcsf mcsf changed the base branch from fix/shortcode-pasting-plain-text to master November 28, 2017 16:02
@mcsf mcsf force-pushed the fix/shortcode-catchall-transform branch from b6fdc4f to efb06ae Compare November 28, 2017 16:04
Blocks can specify shortcodes from which blocks should be automatically
created. For any other shortcode, the core Shortcode block will now act
as a fallback.

The main benefit of this is that, within the Shortcode block, the code
will be properly handled and never mishandled. Notably, this fixes the
case where a shortcode sitting in a Paragraph block will be picked up
with its double quotes rendered as `&doubl;`, thus breaking parsing of a
shortcode's attributes.
@mcsf mcsf force-pushed the fix/shortcode-catchall-transform branch from efb06ae to 73ca3fa Compare November 28, 2017 16:05
@codecov
Copy link

codecov bot commented Nov 28, 2017

Codecov Report

Merging #3610 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3610      +/-   ##
==========================================
- Coverage   37.45%   37.45%   -0.01%     
==========================================
  Files         277      277              
  Lines        6706     6707       +1     
  Branches     1222     1222              
==========================================
  Hits         2512     2512              
- Misses       3535     3536       +1     
  Partials      659      659
Impacted Files Coverage Δ
blocks/api/raw-handling/shortcode-converter.js 52.38% <0%> (ø) ⬆️
blocks/library/shortcode/index.js 33.33% <0%> (-6.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d5d7064...73ca3fa. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blockwise shortcodes don't work in a new Gutenberg post
3 participants