Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce paste from libre office plugin #3624

Merged
merged 95 commits into from
Jan 20, 2020
Merged

Introduce paste from libre office plugin #3624

merged 95 commits into from
Jan 20, 2020

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Nov 4, 2019

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What is the proposed changelog entry for this pull request?

Added support for pasting rich content from Libre Office with the [Paste from Libre Office](https://ckeditor.com/cke4/addon/pastefromlibreoffice) plugin.

What changes did you make?

Requires: #3593

Implement part of the content fixing mechanism inside the common filter. Thi result with fixing some of the wrong expected output for IE11 & Safari on PFW.
The plugin doesn't change pftools mechanism, however, it bypasses it in some places.

@msamsel msamsel marked this pull request as ready for review November 6, 2019 07:53
@Comandeer Comandeer self-requested a review November 12, 2019 12:44
@Comandeer Comandeer self-assigned this Nov 12, 2019
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some failing tests:
Screenshot 2019-11-15 at 17 26 11
Additionally fixture for manual test has info that it's a GDocs one.

plugins/pastefromlibreoffice/filter/default.js Outdated Show resolved Hide resolved
Comment on lines 83 to 89
if ( styles.color === '#000080' ) {
delete styles.color;
}

if ( styles[ 'text-decoration' ] === 'underline' ) {
delete styles[ 'text-decoration' ];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract it to separate function, e.g. removeDefaultLinkStyling? At the moment it looks like some magic styles being removed.

plugins/pastefromlibreoffice/filter/default.js Outdated Show resolved Hide resolved
Comment on lines 210 to 214
if ( /%$/.test( value ) ) {
Style.setStyle( element, 'width', value );
} else {
Style.setStyle( element, 'width', value + 'px' );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's used in two places, it can be extracted to separate function.

Additionally IMO regexps should be extracted to variables with descriptive names (eg. endsWithPercentRegex).

plugins/pastetools/filter/common.js Outdated Show resolved Hide resolved
'background:transparent',
'background-color:none',
'background:none',
'text-align:start',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this style removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably some remaining leftover from the early stage of development.

plugins/pastetools/filter/image.js Show resolved Hide resolved
);
},

'test common filter should remove superflous styles': function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'test common filter should remove superflous styles': function() {
'test common filter should remove superfluous styles': function() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that during batch commit :( So I add it separately to not spend too much time on git history fixing.

@msamsel
Copy link
Contributor Author

msamsel commented Nov 21, 2019

There are some failing tests:

It seems to pass on my env. Please check if those still fails after rebase to current major and if so, then provide more details on what browser and which version you are using.

@msamsel msamsel removed their assignment Nov 21, 2019
@jacekbogdanski
Copy link
Member

@msamsel I see that this PR introduces some changes to image handling. Could you confirm if we should wait with #2800 until this PR gets merged?

@msamsel
Copy link
Contributor Author

msamsel commented Dec 11, 2019

@jacekbogdanski this PR is not related to #2800.
PFLO doesn't implement any changes to image processing in PFW. From my perspective linked issue can be handled separately, as long, as it only affects processing images. In case that proposed solution would require changes in the PFW filter, then would be better to wait for merge.

@msamsel
Copy link
Contributor Author

msamsel commented Jan 9, 2020

I've rebased the pr to current major and resolve existing conflicts.

@Comandeer Comandeer self-assigned this Jan 14, 2020
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it works really well, good job 👍.

I'm missing mainly… support for Page Break. We have it in PfW, so it would be nice to introduce it also for PfLO. It does not seem difficult, LO adds page-break-before: always style to appropriate element.

There is also an issue with aligning images.

LO:
Inserted image with some text below it

PfLO:
Inserted image with some text on the right of it

On Safari image is not inserted at all. On IE8 and 11 image is inserted, but it's broken:

<img style="width: 117px; height: 117px;" src="file:///C:/Users/dev/AppData/Local/Temp/lu7500w8bapy.tmp/lu7500w8baq5_tmp_da3e8e737c4f214e.png" data-cke-saved-src="file:///C:/Users/dev/AppData/Local/Temp/lu7500w8bapy.tmp/lu7500w8baq5_tmp_da3e8e737c4f214e.png">

Most other pain points are already extracted as separate issues and my quick manual tests showed that pasting works well. So I can't even complain much 😞

plugins/pastefromlibreoffice/filter/default.js Outdated Show resolved Hide resolved
}

function getListEvaluator() {
var guard = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe isInBlock? Current name is not much informative.

plugins/pastefromlibreoffice/plugin.js Outdated Show resolved Hide resolved
plugins/pastefromword/plugin.js Show resolved Hide resolved
plugins/pastetools/filter/image.js Outdated Show resolved Hide resolved
@msamsel
Copy link
Contributor Author

msamsel commented Jan 15, 2020

Issue related to float style added to images is extracted to: #3780

@msamsel
Copy link
Contributor Author

msamsel commented Jan 15, 2020

On Safari image is not inserted at all.

Safari doesn't provide the image, that's why it is not possible to obtain the image.
There is no text/rtf clipboard in the paste event and there is no src reference in text/html clipboard.
Screenshot 2020-01-15 at 12 42 18

@msamsel
Copy link
Contributor Author

msamsel commented Jan 15, 2020

The case related to missing images on IE11 is extracted to #3781. The image cannot be embedded in content as there is no available data which allows on that. This is why most suitable fix for this case is removing such elements, however, this change will affect the PFW behaviour.

@msamsel
Copy link
Contributor Author

msamsel commented Jan 15, 2020

About IE8 I remain it as it is. PFLO is a new feature and those has limited compatibility with obsolete browsers. It doesn't look that breaks something on this browser.

Mateusz Samsel added 3 commits January 15, 2020 14:59
…lows to avoid checking wordRegexp what reduces false positive results. Change data input to base on full text/html datatransfer which contains meta tags.
@Comandeer
Copy link
Member

Safari doesn't provide the image, that's why it is not possible to obtain the image.

I've reported it: https://bugs.webkit.org/show_bug.cgi?id=206348

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering how much work it would involve to introduce support for SVG graphics (e.g. document-with-image.odt.zip; unfortunately GH does not support ODT documents). I stumbled upon this use case today. It seems that SVG file is inside RTF as pict element. Maybe we would be able to add the support easily 🤔

There are also some small things to add:

  • new plugin should be added to the build config in dev/builder;
  • there should be also info about supported environments inside the plugin.

Everything else seems to be working well 👍

@msamsel msamsel self-assigned this Jan 16, 2020
@msamsel
Copy link
Contributor Author

msamsel commented Jan 16, 2020

It seems that SVG file is inside RTF as pict element. Maybe we would be able to add the support easily 🤔

Unfortunately, the format of this is image is wmetafile8. It would require to write some dedicated parser/converter which would allow embedding such image in the document. It is not a clear SVG image.
When there are used png or gif images then also for each image has it's wmf representation in rtf clipboard. AFAIR I tried to analyze this format to have possibility to embed shapes drawn in MS Word unfortunately without luck.

@msamsel msamsel removed their assignment Jan 16, 2020
@Comandeer Comandeer self-assigned this Jan 17, 2020
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some unit tests failing in IE8:
Tests failing in IE8

Some tests fail also in Edge, but it seems to be connected with their instability 🤔

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@LiamDawe
Copy link

LiamDawe commented Mar 5, 2020

Does this need a new toolbar button or is it added into other paste features?

@f1ames
Copy link
Contributor

f1ames commented Mar 5, 2020

@LiamDawe - it's added by default in Standard and Full presets and doesn't use additional paste button. So all content pasted from Libre Office with Ctrl/Cmd+C, patse button or context menu will go through Libre Office filter preserving formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants