-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Transforms: Shortcode: Support isMatch
predicate
#18459
Conversation
<p>[my-broccoli id="42"]</p> | ||
<p>[my-broccoli id="1000"]</p>`; | ||
|
||
const transformed = segmentHTMLToShortcodeBlock( original ); |
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.
Could we add some integration tests as well?
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.
@ellatrix, a few of questions:
- How would they differ from the current ones? It's not like any core blocks are using
isMatch
, nor that there are multiple core blocks interested in the same shortcode tag. - Looking at blocks-raw-handling.test.js, I notice that there are now three "areas" for testing:
- individual tests under Blocks raw handling
- the fixture-based tests under pasteHandler
- individual tests under rawHandler
Seems like we could revisit this? I personally don't really know where to start adding tests for this.
- That
readFile
helper silently bails if the provided file path doesn't exist, meaning thattypes
in pasteHandler can just silently pass even when there are missing fixtures. Case in point:caption-shortcode
no longer runs. Seems like something to fix too, I don't see a reason not to throw an error if a file is missing.
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.
It's not like any core blocks are using isMatch, nor that there are multiple core blocks interested in the same shortcode tag.
Interestingly, this could be changed. An example off the top of my head is that the [video]
shortcode in Core explicitly supports YouTube and Vimeo URLs in the src
attribute. These shortcodes could be transformed into their respective core-embed
block, rather than the core/video
block.
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.
- How would they differ from the current ones? It's not like any core blocks are using
isMatch
, nor that there are multiple core blocks interested in the same shortcode tag.
That's true, but we could add a test block?
Seems like we could revisit this? I personally don't really know where to start adding tests for this.
Yeah, we should clean that up :) Ideally, if applicable, tests should be run for both the raw and paste handler.
That
readFile
helper silently bails if the provided file path doesn't exist, meaning thattypes
in pasteHandler can just silently pass even when there are missing fixtures. Case in point:caption-shortcode
no longer runs. Seems like something to fix too, I don't see a reason not to throw an error if a file is missing.
Me neither. Sounds good to throw an error.
Looks great, but would really love some integration tests for an extra layer of confidence. :) |
Thank you for getting onto this one, @mcsf! For consistency, is it worth looking at having the shortcode transform use a |
@pento What kind of additional conversation? I believe we use |
Talking about the difference between the examples in the docs, all of the transform types provide a |
I don't think so. I'm fine with revising that. The difference is that the other |
I know I raised this way way back somewhere in a comment, deep in the GitHub mist. |
type: 'shortcode', | ||
tag: 'gallery', | ||
isMatch( { named: { ids } } ) { | ||
return ids.indexOf( 42 ) > -1; |
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.
Is this your answer to everything? :)
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.
😄
6c020eb
to
9a1848b
Compare
Description
Fixes #10674
How has this been tested?
Expanded unit tests for shortcode conversion.
Types of changes
Enhancement, API.
Checklist: