-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix conversion for text <-> list, and quote <-> list #1297
Conversation
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.
Looks Great! Works really well, left some minor feedback, which I would love to hear your thoughts on!
blocks/library/list/index.js
Outdated
const fromBrDelimitedContent = function( content ) { | ||
const listItems = []; | ||
listItems.push( createElement( 'li', [], [] ) ); | ||
content.forEach( function( element, elementIndex, elements ) { |
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.
Minor Nitpick: I think we might want to use arrow function for these callbacks to keep consistent.
blocks/library/list/index.js
Outdated
const toBrDelimitedContent = function( values ) { | ||
const content = []; | ||
values.forEach( function( li, liIndex, listItems ) { | ||
if ( Array.isArray( li.props.children ) ) { |
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.
Another minor idea: I think we could potentially condense this code by using the Children
API in React; either by making use of Children.map
or Children.toArray
, Then the conditional checking whether children is an array won't really be necessary.
Hmm, actually while circling back to this, I did come across a weird situation. If things get indented, then when you transform the indented children never get changed to a text or quote properly. Not sure if that necessarily has to be addressed in this PR. |
Ah, when a user likes lists so much that they put a list in their list so they can list their lists... Yeah, I'm not sure that we can preserve the indentation when we convert to a text or quote block, but we should certainly get the values of the list items. |
I've added support for nested lists now. Also, there were bugs when converting from empty blocks, so they're fixed too. |
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.
Converts text and quotes to list by using BR as the delimiter for list items. Transformations have been moved into the list block, it seemed to make sense for them to live there as the transformation code is there too.
Fixes #1214