zoukankan      html  css  js  c++  java
  • 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了。




  • 相关阅读:
    [LeetCode] Reverse Linked List II
    [LeetCode] Reverse Linked List
    [LeetCode] Palindrome Linked List
    人工智能之一《tensorflow》
    计算机视觉之《OpenCV开发环境搭建》
    Android Automotive开发之一《编译自己的SDK 》 // TOBEDONE
    Android Automotive开发之一《环境: JDK7&JDK8切换 》
    Android Auto开发之一《开始学习Auto 》
    网络安全之证书、密钥、密钥库等名词解释
    Android开发笔记之《特斯拉-Tesla 代码分析》
  • 原文地址:https://www.cnblogs.com/guanghuiqq/p/2636392.html
Copyright © 2011-2022 走看看