最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Copying and pasting into CKEditor from MS Word - Stack Overflow

programmeradmin1浏览0评论

I have a word document consisting of just two words "Hello to". This is actually a simplified version of the original document. The font-family for this text is Calibri (body). I don't notice any difference in formatting between these two words in the word document.

When attempting to copy and paste this text into ckeditor, the font-family of "Hello" is correctly preserved as Calibri, but the font-family of the word "to" in incorrectly changed to Arial. I don't understand why it doesn't also preserve the font-family of the "to" text.

Here is my config.js:

CKEDITOR.editorConfig = function( config ) {    
    config.pasteFromWordRemoveStyles = false;
    config.pasteFromWordRemoveFontStyles = false;
};

Here is the source HTML in ckeditor upon pasting the text:

<p><span style="font-size:10pt"><span style="font-family:calibri">Hello </span>to</span></p>

The word document is available to download from the following link:

/?file_id=00848535251570855827

The above behaviour is evident using IE 11. Please can someone assist with this?

I have a word document consisting of just two words "Hello to". This is actually a simplified version of the original document. The font-family for this text is Calibri (body). I don't notice any difference in formatting between these two words in the word document.

When attempting to copy and paste this text into ckeditor, the font-family of "Hello" is correctly preserved as Calibri, but the font-family of the word "to" in incorrectly changed to Arial. I don't understand why it doesn't also preserve the font-family of the "to" text.

Here is my config.js:

CKEDITOR.editorConfig = function( config ) {    
    config.pasteFromWordRemoveStyles = false;
    config.pasteFromWordRemoveFontStyles = false;
};

Here is the source HTML in ckeditor upon pasting the text:

<p><span style="font-size:10pt"><span style="font-family:calibri">Hello </span>to</span></p>

The word document is available to download from the following link:

http://s000.tinyupload./?file_id=00848535251570855827

The above behaviour is evident using IE 11. Please can someone assist with this?

Share Improve this question edited Mar 9, 2015 at 14:49 Reinmar 22k4 gold badges69 silver badges79 bronze badges asked Mar 9, 2015 at 12:10 aw1975aw1975 1,7083 gold badges24 silver badges36 bronze badges 7
  • I assume you have explicitly set the font-family by highlighting the words in Word and setting the font-family to Calibri? – robabby Commented Mar 9, 2015 at 12:57
  • @robabby No it was from a pre-existing word document provided by our customer. If I create a new word document and set the font-family to Calibri by highlighting the words then the issue doesn't occur. The issue can also be resolved by using the clear all formatting function and then reapplying it But I can't expect our customer to re-apply formatting on all their documents. Ideally I need to determine what is the issue with those specific word documents that prevent their content from being copy/pasted correctly into ckeditor. – aw1975 Commented Mar 9, 2015 at 13:53
  • 1 We have similar customer issues e down the pipeline at my job where we use Word import for our CKEditor instances. These are one-off circumstances and should be documented for the customer to know proper steps before import. At least, that's how we will handle these. If CKEditor is working as designed, and when text is properly formatted it works as designed, then there is little else you should have to do. How many permutations should you be able to account for in code? – robabby Commented Mar 9, 2015 at 14:42
  • 1 Some insight from CKEditor perspective - the HTML that MSWord generates when pasting into browser is absolutely terrible and often it happens that it's simply incorrect. I'm sure that CKEditor has some bugs too, but sometimes there's also not much it can do with a content that it's given. If you've got any doubts, you can report a ticket on dev.ckeditor. and we'll check if there's a light in the tunnel. – Reinmar Commented Mar 9, 2015 at 14:56
  • Thank you both for your responses. I've submitted a ticket on the ckeditor site. – aw1975 Commented Mar 9, 2015 at 15:55
 |  Show 2 more ments

2 Answers 2

Reset to default 4

IMHO, the below with some modification will do.

config.forcePasteAsPlainText = false;
config.pasteFromWordRemoveFontStyles = false;
config.pasteFromWordRemoveStyles = false;
config.allowedContent = true;
config.extraAllowedContent = 'p(mso*,Normal)';
config.pasteFilter = null;

This would definitely work

CKEDITOR.config.forcePasteAsPlainText = false;
CKEDITOR.config.pasteFromWordRemoveFontStyles = false;
CKEDITOR.config.pasteFromWordRemoveStyles = false;
CKEDITOR.config.allowedContent = true;
CKEDITOR.config.extraAllowedContent = 'p(mso*,Normal)';
CKEDITOR.config.pasteFilter = null;

Thanks

发布评论

评论列表(0)

  1. 暂无评论