ms-word - wysihtml5:将文本从 Word 文档复制到编辑器

标签 ms-word richtextbox rich-text-editor wysihtml5

将文字从 word 复制到 wysihtml5 editor 时,文本变得困惑(无论是在格式方面还是在额外添加的字符方面)。有没有简单的解决方法?我正在寻找的正确行为是 Stack Overflow 的富文本编辑器的工作方式 - 从 word 复制和粘贴的文本看起来与 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 中不会发生。关于如何摆脱这个问题的任何想法?

最佳答案

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

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

如果您使用的是 Mac,您可以在 ClipboardViewer tool 的帮助下看到这个原始剪贴板内容。你必须用 XCode 自己编译。所需的 HTML 内容应该在 public.html 中或 Apple HTML pasteboard type领域。也许存在不需要编译和/或在其他操作系统上工作的其他工具。

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

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

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

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

关于ms-word - wysihtml5:将文本从 Word 文档复制到编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15046225/

相关文章:

c# - 如何使用 Microsoft.Office.Interop.Word 将光标移动到特定段落?

c# - 如何更改 RichTextBox 中文本的大小写?

java - 如何使用 antlrv3 生成的词法分析器和解析器提供语法高亮显示?

jquery - 如何从 SummerNote onPaste 上的标签中删除样式属性?

javascript - 在选定区域中取消选择后获取插入符位置

ColdFusion 'Run As Service' 与 'Run in Console'

javascript - 我需要通过office.js删除word消息

c# - 使用 DocumentFormat.OpenXml dll 读取 .Doc 文件

c# - 禁用 RichTextBox 自动滚动

c# - WPF 富文本框 FontFace/FontSize