ckeditor粘入word內容如何默認設置為保留樣式


現在將word文檔中的內容粘貼到ckeditor(CKEditor3.6.2)中好像默認了要去除內容樣式,只保留了格式。。如何才能設置為保留樣式呢?方法如下:

打開
\editor\plugins\pastefromword\filter\default.js
找到文件尾大概有這么一句代碼
Js代碼 復制代碼 收藏代碼
  1. ;CKEDITOR.cleanWord=function(h,i){if
  2. (CKEDITOR.env.gecko)h=h.replace(/(<!--\[if
  3. [^<]*?\])-->([\S\s]*?)<!--(\[endif\]--
  4. >)/gi,'$1$2$3');var j=new g
  5. (),k=j.dataFilter;k.addRules
  6. (CKEDITOR.plugins.pastefromword.getRules
  7. (i));i.fire('beforeCleanWord',{filter:k});try
  8. {h=j.toHtml(h,false);}catch(l){alert
  9. (i.lang.pastefromword.error);}h=h.replace
  10. (/cke:.*?".*?"/g,'');h=h.replace
  11. (/style=""/g,'');h=h.replace
  12. (/<span>/g,'');return h;};})();
;CKEDITOR.cleanWord=function(h,i){if
(CKEDITOR.env.gecko)h=h.replace(/(<!--\[if
[^<]*?\])-->([\S\s]*?)<!--(\[endif\]--
>)/gi,'$1$2$3');var j=new g
(),k=j.dataFilter;k.addRules
(CKEDITOR.plugins.pastefromword.getRules
(i));i.fire('beforeCleanWord',{filter:k});try
{h=j.toHtml(h,false);}catch(l){alert
(i.lang.pastefromword.error);}h=h.replace
(/cke:.*?".*?"/g,'');h=h.replace
(/style=""/g,'');h=h.replace
(/<span>/g,'');return h;};})();
這段JS代碼正是清除word里的格式的作用,我們可以 修改為
Js代碼 復制代碼 收藏代碼
  1. ;CKEDITOR.cleanWord=function(h,i){return h;if
  2. (CKEDITOR.env.gecko)h=h.replace(/(<!--\[if
  3. [^<]*?\])-->([\S\s]*?)<!--(\[endif\]--
  4. >)/gi,'$1$2$3');var j=new g
  5. (),k=j.dataFilter;k.addRules
  6. (CKEDITOR.plugins.pastefromword.getRules
  7. (i));i.fire('beforeCleanWord',{filter:k});try
  8. {h=j.toHtml(h,false);}catch(l){alert
  9. (i.lang.pastefromword.error);}h=h.replace
  10. (/cke:.*?".*?"/g,'');h=h.replace
  11. (/style=""/g,'');h=h.replace
  12. (/<span>/g,'');return h;};})();
;CKEDITOR.cleanWord=function(h,i){return h;if
(CKEDITOR.env.gecko)h=h.replace(/(<!--\[if
[^<]*?\])-->([\S\s]*?)<!--(\[endif\]--
>)/gi,'$1$2$3');var j=new g
(),k=j.dataFilter;k.addRules
(CKEDITOR.plugins.pastefromword.getRules
(i));i.fire('beforeCleanWord',{filter:k});try
{h=j.toHtml(h,false);}catch(l){alert
(i.lang.pastefromword.error);}h=h.replace
(/cke:.*?".*?"/g,'');h=h.replace
(/style=""/g,'');h=h.replace
(/<span>/g,'');return h;};})();
已經測試過了,完全正確!

---------------------------------------------------------------------------------------------------------------------------------
就是加上reutrn h;就ok了。





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM