ckeditor / ckeditor4

The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.
https://ckeditor.com/ckeditor-4
Other
5.79k stars 2.48k forks source link

Math formulas pasted from MS Word should be converted into base64 encoded images. #1720

Open jswiderski opened 6 years ago

jswiderski commented 6 years ago

Feature request

Expected result

Math formulas created in MS Word are available as images. They should be pasted into CKEditor as base64 encoded images.

Actual result

At the moment these formulas are pasted as images with local paths what results in empty image.

Other details

Sample file with formulas: Math Paper-1.docx

Are you reporting a feature request or a bug?

Comandeer commented 6 years ago

The issue is probably with extractFromRtf method in our PFW filter. Such objects in Word files are annotated with objdata. Note also that some of such equations are exported as GIF images, which aren't currently supported.

ummedgeek commented 6 years ago

Please resolve this problem.

jswiderski commented 6 years ago

From what I have checked in latest CKEditor 4.10.0, pasting formulas works quite nicely on Windows (it doesn't work on MAC) however there is a flaw. Formula is pasted as a plain text and as an image (base64 string).

Even below code returns text together with an image:

editor1.on( 'instanceReady', function( event ){ 
    editor1.on( 'paste', function( evt ) {
        console.log( evt.data.dataTransfer.$.getData( 'text/html'  ) );     
    } );
} );

result

Migueeeeel commented 6 years ago

I'm having the same bug as jswiderski reported.

image

Migueeeeel commented 6 years ago

After analyzing the html code injected by CKEditor I added the following lines to the Paste from Word plugin default.js, In the cleanWord function after a = a.replace(/<![/g, "\x3c!--[").replace(/]>/g, "]--\x3e");

a = a.replace(/.<\/m:omath>/g, ''); a = a.replace(/.<\/m:r>/g, ''); a = a.replace(/.<\/m:omathpara>/g, ''); a = a.replace(/.<\/m:omathparapr>/g, ''); a = a.replace(/.*<\/m:ssup>/g, '');

This apparently fixed the bug.

image image

NingerJohn commented 5 years ago

@Migueeeeel Thank you very much. But I have to say that the code you pasted above is not same as photo shows, you forgot the backslash

Nitinchopkar commented 5 years ago

thanks its work for me.

woody-li commented 5 years ago

It changed to white backgroundColor after converted to base64 image. Is it possible to keep it original bgColor such as transparent.

vishal342 commented 4 years ago

this code not working

KEDITOR.cleanWord = CKEDITOR.pasteFilters.word = B.createFilter({ rules: [t.rules, q.rules], additionalTransforms: function (b) { CKEDITOR.plugins.clipboard.isCustomDataTypesSupported && (b = t.styles.inliner.inline(b).getBody().getHtml()); return b.replace(/<![/g, "\x3c!--[").replace(/]>/g, "]--\x3e"); }

Comandeer commented 3 years ago

It seems that our recent changes to Paste from Word changed the behaviour of pasting documents with equations. It works well in Safari (due to its unique way of handling images) and fails in other browsers (no images are pasted at all for document provided as an original example and equation is pasted as plain text for a newly created Word document).

Additionally there is some new format of equations in Word, which uses unsupported EMF image format (see #4290), which means that fully supporting equations is blocked until #4290 is resolved.

Sample Word document with new equation format