Ckeditor4: Math formulas pasted from MS Word should be converted into base64 encoded images.

Created on 27 Feb 2018  路  9Comments  路  Source: ckeditor/ckeditor4

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

  • Browser: Any
  • OS: Any
  • CKEditor version: 4.8.0+
  • Installed CKEditor plugins:

Sample file with formulas:
Math Paper-1.docx

Are you reporting a feature request or a bug?

pastefromword L confirmed feature

Most helpful comment

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

All 9 comments

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.

Please resolve this problem.

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

I'm having the same bug as jswiderski reported.

image

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, "]--x3e");

a = a.replace(/./g, '');
a = a.replace(/.
/g, '');
a = a.replace(/./g, '');
a = a.replace(/.
/g, '');
a = a.replace(/.*/g, '');

This apparently fixed the bug.

image
image

@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

thanks its work for me.

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

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, "]--x3e");
}

Was this page helpful?
0 / 5 - 0 ratings