Skip to content

Commit

Permalink
Support list margins in PFW by default
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolDawidziuk committed Apr 24, 2023
1 parent ac4dbac commit 025dc5e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions plugins/pastefromword/filter/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,7 @@

// Insert first known list item before the list wrapper.
innermostContainer.insertBefore( list[ 0 ] );

var keepZeroMargins = CKEDITOR.plugins.pastetools.getConfigValue( editor, 'keepZeroMargins' );

// Preserve keeping list margins zero when pasteTools_keepZeroMargins is ON. #53163
if ( keepZeroMargins ) {
innermostContainer.attributes.style = getZeroMargins( firstLevel1Element.attributes.style );
}
innermostContainer.attributes.style = getMargins( firstLevel1Element.attributes.style, editor );

for ( j = 0; j < list.length; j++ ) {
element = list[ j ];
Expand Down Expand Up @@ -1019,24 +1013,32 @@
}, 0 );
}

function getZeroMargins( styles ) {
function getMargins( styles ) {
var parsedStyles = CKEDITOR.tools.parseCssText( styles );
var keys = [ 'margin-top', 'margin-right', 'margin-bottom', 'margin-left' ],
zeroMargins = '';
keepZeroMargins = CKEDITOR.plugins.pastetools.getConfigValue( editor, 'keepZeroMargins' ),
margins = '';

CKEDITOR.tools.array.forEach( keys, function( key ) {
if ( !( key in parsedStyles ) ) {
return;
}

var value = CKEDITOR.tools.convertToPx( parsedStyles[ key ] );
if ( value === 0 ) {
zeroMargins += key + ': ' + value + '; ';

// Preserve keeping zero list margins when pasteTools_keepZeroMargins is ON. #53163
if ( value === 0 && keepZeroMargins ) {
margins += key + ': ' + value + '; ';
}

// Preserve keeping margins by default.
if ( value > 0 ) {
margins += key + ': ' + value + 'px; ';
}
} );

if ( zeroMargins !== '' ) {
return zeroMargins;
if ( margins !== '' ) {
return margins;
}
}
},
Expand Down

0 comments on commit 025dc5e

Please sign in to comment.