Ms word 所见即所得HTML5:将文本从word文档复制到编辑器

Ms word 所见即所得HTML5:将文本从word文档复制到编辑器,ms-word,richtextbox,rich-text-editor,wysihtml5,Ms Word,Richtextbox,Rich Text Editor,Wysihtml5,将文本从word复制到时,文本会变得混乱(无论是在格式方面还是在附加字符方面)。有没有简单的解决办法?我正在寻找的正确行为是Stack Overflow的富文本编辑器的工作方式——从word复制和粘贴的文本看起来与word文档完全相同 谢谢大家! 更新: 为了解决粘贴的word文本的格式问题,我在使用的wysihtml5-0.30_rc2.js文件中添加了行“p”:{},。该行已添加到defaultOptions[parserRules][tags]()的声明中 不过,现在我可以在粘贴文本的开头

将文本从word复制到时,文本会变得混乱(无论是在格式方面还是在附加字符方面)。有没有简单的解决办法?我正在寻找的正确行为是Stack Overflow的富文本编辑器的工作方式——从word复制和粘贴的文本看起来与word文档完全相同

谢谢大家!

更新: 为了解决粘贴的word文本的格式问题,我在使用的wysihtml5-0.30_rc2.js文件中添加了行
“p”:{},
。该行已添加到defaultOptions[parserRules][tags]()的声明中

不过,现在我可以在粘贴文本的开头看到一段“字体定义”:

<!-- /* Font Definitions */ @font-face {font-family:Arial; panose-1:2 11 6 4 2 2 2 2 2 4; mso-font-charset:0; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 0 0 0 1 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin-top:0cm; margin-right:0cm; margin-bottom:10.0pt; margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; mso-hyphenate:none; font-size:11.0pt; font-family:Arial; mso-fareast-font-family:Arial; mso-bidi-font-family:Arial; color:black; mso-fareast-language:HI; mso-bidi-language:HI;} a:link, span.MsoHyperlink {mso-style-unhide:no; mso-style-parent:""; color:navy; mso-ansi-language:#00FF; mso-fareast-language:#00FF; mso-bidi-language:#00FF; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page WordSection1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt
90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.WordSection1 {page:WordSection1;} -->

这只会在我使用Firefox时发生,在Chrome中不会发生。关于如何解决这个问题有什么想法吗?

包括一个解析器,它分析粘贴在其文本区域中的所有文本,并应用在
parserroles
config对象中定义的筛选规则。将
“style”:{“remove”:1}
添加到
parserules
中应该可以做到这一点

要理解Firefox的问题,您必须查看粘贴到文本区域的原始剪贴板HTML内容(源于Word)。仅仅复制一些Word文本并将其粘贴到文本编辑器中是没有帮助的,因为文本编辑器请求剪贴板内容的纯文本变体

若你们在Mac电脑上,你们可以在XCode的帮助下看到这个原始的剪贴板内容。所需的HTML内容应位于
public.HTML
Apple HTML粘贴板类型
字段中。可能存在其他不需要编译和/或在其他操作系统上工作的工具

现在您应该看到Word中的剪贴板内容实际上看起来像

    <span>
    <!--
      /* Font Definitions */
      ...
      div.WordSection1 {page:WordSection1;}
      ...
    -->
    </span>

因此,通过删除
style
标记(及其所有内容),字体定义垃圾就会消失


查看一些更高级的配置选项。

我通过覆盖
wysihtml5.dom.getPastedHtml
解决了这个问题。加载wysihtml5后,只需添加以下内容:

wysihtml5.dom.getPastedHtml = function(event) {
  var html;
  if (event.clipboardData) {
    html = event.clipboardData.getData('text/plain');
  }
  return html;
};

我也有同样的问题!一、 我也有同样的问题,这让我发疯。我真的很喜欢wysihtml5;然而,我的用户,那些喜欢用Word书写的人,在复制和粘贴时总是遇到问题。正在进行的修复搜索有什么进展吗?它正在删除内容的整体样式