Skip to content

Commit

Permalink
Add: Raw handling to the new list block. (#39954)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored May 17, 2022
1 parent f83dd10 commit 303a423
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/block-library/src/list/v2/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { omit } from 'lodash';
*/
import { createBlock } from '@wordpress/blocks';

function createListBlockFromDOMElement( listElement ) {
export function createListBlockFromDOMElement( listElement ) {
const listAttributes = {
ordered: 'OL' === listElement.tagName,
start: listElement.getAttribute( 'start' )
Expand Down
35 changes: 35 additions & 0 deletions packages/block-library/src/list/v2/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ import {
toHTMLString,
} from '@wordpress/rich-text';

/**
* Internal dependencies
*/
import { createListBlockFromDOMElement } from './migrate';

function getListContentSchema( { phrasingContentSchema } ) {
const listContentSchema = {
...phrasingContentSchema,
ul: {},
ol: { attributes: [ 'type', 'start', 'reversed' ] },
};

// Recursion is needed.
// Possible: ul > li > ul.
// Impossible: ul > ul.
[ 'ul', 'ol' ].forEach( ( tag ) => {
listContentSchema[ tag ].children = {
li: {
children: listContentSchema,
},
};
} );

return listContentSchema;
}

const transforms = {
from: [
{
Expand Down Expand Up @@ -82,6 +108,15 @@ const transforms = {
);
},
} ) ),
{
type: 'raw',
selector: 'ol,ul',
schema: ( args ) => ( {
ol: getListContentSchema( args ).ol,
ul: getListContentSchema( args ).ul,
} ),
transform: createListBlockFromDOMElement,
},
],
to: [
...[ 'core/paragraph', 'core/heading' ].map( ( block ) => ( {
Expand Down

0 comments on commit 303a423

Please sign in to comment.