2013-02-23 84 views
7

当从Word文本复制到wysihtml5 editor,文本被搞砸了(无论是在格式化的术语,并且额外添加的字符计算)。有这个简单的解决办法吗?我正在寻找的正确行为将是Stack Overflow的富文本编辑器的工作方式 - 从单词复制和粘贴的文本看起来与单词文档相同。wysihtml5:复制从Word文档中的文本编辑器

谢谢!

更新: 解决与粘贴字的文本格式观察到的问题,我增加了行"p": {},在使用wysihtml5-0.30_rc2.js文件。该行添加到defaultOptions [parserRules] [tags](see used resource)的声明中。

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

<!-- /* 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不会发生。任何想法如何摆脱这个问题?

+0

我有同样的问题! – RayOnAir 2013-08-15 16:01:29

+0

我也有同样的问题,这让我疯狂。我真的很喜欢wysihtml5;然而,我的用户,喜欢用Word编写的人,在复制和粘贴时永远会遇到问题。在不断寻找解决方案方面有什么好运? – realistschuckle 2014-02-08 03:00:44

回答

1

wysihtml5包含一个解析器,用于分析所有粘贴在其文本区域中的文本,并应用配置对象parserRules中定义的过滤规则。将"style": { "remove": 1 }添加到您的parserRules应该有所斩获。

要了解Firefox的问题,你必须看到原始剪贴板HTML内容(源自字),其被粘贴到文本区域。只需复制一些Word文本并将其粘贴到文本编辑器中将无济于事,因为文本编辑器会请求剪贴板内容的纯文本变体。

如果你是一个Mac上你可以看到这个原始剪贴板中的内容与你自己编译与Xcode中ClipboardViewer tool的帮助。所需的HTML内容应位于public.htmlApple HTML pasteboard type字段中。也许还有其他工具不需要编译和/或在其他操作系统上工作。

现在你应该看到,从Word中的剪贴板中的内容因此通过移除style标签(连同所有内容的)实际上看起来像

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

字体定义垃圾消失。

看一看wysihtml5’s parserRule demo看到一些更高级的配置选项。

1

我通过重写wysihtml5.dom.getPastedHtml解决了这个。只需在加载wysihtml5后添加以下内容:

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