diff --git a/blocks/api/paste/ms-list-converter.js b/blocks/api/paste/ms-list-converter.js index 5beefbe89f71d..b5408e4ad6e87 100644 --- a/blocks/api/paste/ms-list-converter.js +++ b/blocks/api/paste/ms-list-converter.js @@ -18,18 +18,24 @@ export default function( node ) { } const style = node.getAttribute( 'style' ); - const matches = /mso-list\s*:([^;]+)/.exec( style ); - if ( ! matches ) { + if ( ! style ) { + return; + } + + // Quick check. + if ( style.indexOf( 'mso-list' ) === -1 ) { return; } - const msoList = matches[ 1 ]; + const matches = /mso-list\s*:[^;]+level([0-9]+)/i.exec( style ); - if ( ! msoList ) { + if ( ! matches ) { return; } + let level = parseInt( matches[ 1 ], 10 ) - 1 || 0; + const prevNode = node.previousElementSibling; // Add new list if no previous. @@ -49,8 +55,7 @@ export default function( node ) { const listNode = node.previousElementSibling; const listType = listNode.nodeName; const listItem = document.createElement( 'li' ); - const levelMatches = /level([0-9]+)/i.exec( msoList ); - let level = parseInt( levelMatches[ 1 ], 10 ) - 1 || 0; + let receivingNode = listNode; // Remove the first span with list info.