Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#12256 closed Bug (fixed)

Paste from Word plugin removes classes

Reported by: Boris Lykah Owned by: Piotr Jasiun
Priority: Normal Milestone: CKEditor 4.4.8
Component: General Version:
Keywords: Support Cc:

Description

When pasting content from word the classes assigned to the elements by filter are removed.

Use config with Bold definition that involves classes.

            coreStyles_bold: {
                element: 'span',
                attributes: { 'class': 'myboldclass' },
                overrides: ['strong', 'b']
            },

When pasting bold text from Word, the result is <span> without class. The offending line that always removes class is

'class': falsyFilter,

in pastefromword/filter/default.js.

Change History (9)

comment:1 Changed 4 years ago by Wiktor Walc

Keywords: Support added

comment:2 Changed 4 years ago by Piotr Jasiun

Milestone: CKEditor 4.5.0
Owner: set to Piotr Jasiun
Status: newassigned

comment:3 Changed 4 years ago by Piotr Jasiun

Bug in the pasteFromWord plugin is fixed. Fix and tests pushed to t/12256.

Unfortunately working on this issue I found another problem with pasting on Chrome. Classes added by paste from Word are later removed by the filter.

comment:4 Changed 4 years ago by Piotr Jasiun

The custom class added in the paste from Word plugin is removed by the pasteFilter introduced recently (#11621). There are multiple possible solution for this issue:

  • disable pasteFilter (by adding pasteFilter: null into the config), but without pasteFiler content pasted from Chrome will contain all the mess,
  • add myboldclass class to the pasteFilter rules, but it is not that easy at the moment because pasteFilter use semantic-content which is generated dynamically and there is no easy way to add some custom rule in the config,
  • automatically add classes from custom styles to pasteFilter:semantic-content filter, what seems to be the best way, but all coreStyles_* configs need to be checked,
  • remove form the paste from word filter code which apply custom styles (remove these lines), custom styles will be applied anyway by ACF and, because ACF will handle the content after pasteFilter is applied, the custom styles will not be removed; but if ACF is disabled custom styles will not be applied.

comment:5 Changed 4 years ago by Piotrek Koszuliński

add myboldclass class to the pasteFilter rules, but it is not that easy at the moment because pasteFilter use semantic-content which is generated dynamically and there is no easy way to add some custom rule in the config,

On instanceReady use editor.pasteFilter.allow() - that's it. That's how you're supposed to extend paste filter's settings.

comment:6 Changed 4 years ago by Piotr Jasiun

Status: assignedreview

So the changes in code are done. Changes in t/12256. To enable pasting from word in Chrome additional rule in paste filter is needed:

	editor.on( 'instanceReady', function( evt ) {
		editor.pasteFilter.allow( 'span(myboldclass)' );
	} );

comment:7 Changed 4 years ago by Piotrek Koszuliński

Resolution: fixed
Status: reviewclosed

Fixed on master with git:e8a747d.

Since 4.5.0 this patch to work will need the code mentioned in comment:6. This lack of automation comes from the fact that PFW plugin is a bit outdated. Instead of using the ACF to transform one styles into another it does it by itself, but it does it too early. The paste filter is not aware of such things and strips classes that are not supposed to exist at this point. We plan to resolve this situation in the future by rebuilding the PFW filter.

comment:8 Changed 4 years ago by Piotrek Koszuliński

After bit of thinking I reported #13093, because the conflict between paste filter and PFW is far more general.

comment:9 Changed 4 years ago by Piotrek Koszuliński

Milestone: CKEditor 4.5.0CKEditor 4.4.8
Note: See TracTickets for help on using tickets.
© 2003 – 2017 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy