Skip to content

Commit

Permalink
Parse mso-list in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Aug 24, 2017
1 parent 5419891 commit b5ef57a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions blocks/api/paste/ms-list-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit b5ef57a

Please sign in to comment.