-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
@@ -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 ), |
There was a problem hiding this comment.
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
).
Works well 👍 |
blocks/library/shortcode/index.js
Outdated
// 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_-]+', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
b714abe
to
7db1c8d
Compare
174e6b9
to
086dd25
Compare
7db1c8d
to
b6fdc4f
Compare
b6fdc4f
to
efb06ae
Compare
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.
efb06ae
to
73ca3fa
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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):
Types of changes
Checklist: