-
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
Quote Block: Fix parsing a blockquote without a classname #485
Conversation
blocks/library/quote/index.js
Outdated
@@ -20,6 +20,9 @@ registerBlock( 'core/quote', { | |||
citation: html( 'footer' ), | |||
style: node => { | |||
const value = attr( 'blockquote', 'class' )( node ); | |||
if ( ! value ) { | |||
return 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.
With this, there's now three ways we're enforcing a default value for style
.
- Explicitly return
1
fromstyle
parsing - Return
null
from style parsing and fallback using|| 1
inedit
andsave
- Destructure with
style = 1
default incontrols.isActive
I think we ought to consolidate on one. My preference would be toward returning undefined
in the style
parsing and using destructuring with default value.
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.
e.g.
Explicit undefined:
style: ( node ) => {
const value = attr( 'blockquote', 'class' )( node );
if ( ! value ) {
return;
}
const match = value.match( /\bblocks-quote-style-(\d+)\b/ );
if ( ! match ) {
return;
}
return Number( match[ 1 ] );
}
Implicit undefined:
style: ( node ) => {
const value = attr( 'blockquote', 'class' )( node );
if ( value ) {
const match = value.match( /\bblocks-quote-style-(\d+)\b/ );
if ( match ) {
return Number( match[ 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.
Sounds good to me, I'd go for the explicit one :)
f2510d6
to
9690c35
Compare
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.
This looks good and seems to simplify a fair bit on how we're we're using style
👍
@@ -22,7 +22,7 @@ window._wpGutenbergPost = { | |||
'<!-- /wp:core/text -->', | |||
|
|||
'<!-- wp:core/quote -->', | |||
'<blockquote class="blocks-quote-style-2"><p>Real artists ship.</p><footer><p><a href="http://www.folklore.org/StoryView.py?story=Real_Artists_Ship.txt">Steve Jobs, 1983</a></p></footer></blockquote>', | |||
'<blockquote><p>Real artists ship.</p><footer><p><a href="http://www.folklore.org/StoryView.py?story=Real_Artists_Ship.txt">Steve Jobs, 1983</a></p></footer></blockquote>', |
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.
Depending on how we want the quote block to be styled, should we always enforce the existence of a class, even if it's the "default" (first) style?
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.
Probably, but I think it's worth dropping here to avoid having this bug another time?
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.
Probably, but I think it's worth dropping here to avoid having this bug another time?
I don't feel strongly either way. We can keep it as you have here and if it becomes a point of confusion, reintroduce later.
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.
This would be better handled with unit tests.
This PR fixes parsing a blockquote without a classname, and returns
1
as the default styling for quotes without classnames.