有没有办法从 FCKEditor 中删除所有不必要的 MS Word 格式
我已经安装了 fckeditor,当从 MS Word 粘贴时,它添加了很多不必要的格式。我想保留某些内容,例如粗体、斜体、项目符号等。我在网上搜索并提出了一些解决方案,可以去掉所有内容,甚至是我想保留的内容,例如粗体和斜体。有没有办法去掉不必要的文字格式?
I have installed fckeditor and when pasting from MS Word it adds alot of unnecessary formatting. I want to keep certain things like bold, italics, bulltes and so forth. I have searched the web and came up with solutions that strips everything away even the stuff that i wanted to keep like bold and italics. Is there a way to strip just the unnecessary word formatting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
以防万一有人想要已接受答案的 ac# 版本:
Just in case someone wants a c# version of the accepted answer:
这是我用来清理从富文本编辑器传入的 HTML 的解决方案...它是用 VB.NET 编写的,我没有时间转换为 C#,但它非常简单:
在您的情况下,您需要修改“AcceptableTags”中“已批准”HTML 标记的列表 - 代码仍会去除所有无用的属性(不幸的是,有用的属性,如 HREF 和 SRC,希望这些对您来说并不重要)。
当然,这需要访问服务器。如果您不希望这样,则需要在工具栏上添加某种“清理”按钮,该按钮调用 JavaScript 来弄乱编辑器的当前文本。不幸的是,“粘贴”不是一个可以捕获以自动清理标记的事件,并且每次 OnChange 后进行清理都会导致编辑器无法使用(因为更改标记会更改文本光标位置)。
Here's a solution I use to scrub incoming HTML from rich text editors... it's written in VB.NET and I don't have time to convert to C#, but it's pretty straightforward:
In your case, you'll want to modify the list of "approved" HTML tags in "AcceptableTags"--the code will still strip all the useless attributes (and, unfortunately, the useful ones like HREF and SRC, hopefully those aren't important to you).
Of course, this requires a trip to the server. If you don't want that, you'll need to add some sort of "clean up" button to the toolbar that calls JavaScript to mess with the editor's current text. Unfortunately, "pasting" is not an event that can be trapped to clean up the markup automatically, and cleaning after every OnChange would make for an unusable editor (since changing the markup changes the text cursor position).
尝试了接受的解决方案,但它没有清除单词生成的标签。
但是这段代码对我有用
Tried the accepted solution but it didn't clean the word generated tags.
But this code worked for me
我非常理解这个问题。当从 MS-Word(或任何文字处理或富文本编辑感知文本区域)复制出来然后粘贴到 FCKEditor(TinyMCE 也会出现同样的问题)时,原始标记将包含在剪贴板中并进行处理。此标记并不总是与它与粘贴操作的目标一起嵌入的标记互补。
除了成为FCKEditor的贡献者并研究代码并进行修改之外,我不知道解决方案。我通常做的是指导用户执行两阶段剪贴板操作。
I understand the problem very well. When copying out of MS-Word (or any word processing or rich text editing aware text area) then pasting into FCKEditor (same problem happens with TinyMCE), the original markup is included in what is in the clipboard and gets processed. This markup is not always complimentary with the markup that it gets embedded in with the target of the paste operation.
I don't know the solution other than become a contributor to FCKEditor and study the code and make the modification. What I normally do is instruct users to perform a two phase clipboard operation.
但正如其名称和网站所示,fckeditor 是一个文本编辑器。对我来说,这意味着它只是向您显示文件中的字符。
如果没有一些额外的字符,就无法使用粗体和斜体格式。
编辑:啊,我明白了。仔细观察 Fckeditor 网站,它是一个 HTML 编辑器,而不是我习惯的简单文本编辑器。
使用自动检测功能从 Word 清理粘贴
被列为一项功能。But fckeditor is, as the name and website suggests, a text editor. To me, that means it just shows you the characters in the file.
You can't have bold and italic formatting without some extra characters.
EDIT: Ah, I see. Looking more closely at the Fckeditor website, it's an HTML editor, not one of the simple text editors I'm used to.
There's
Paste from Word cleanup with autodetection
listed as a feature.对于我的解决方案,我最终使用了 C# 版本的 CleanHtml 函数和清除 MS Office 标签的部分的组合。本质上是 Glenn 流程的基于代码的版本。我将看看当我将其推送到一个巨大的 Excel 电子表格时会发生什么。
For my solution, I wound up using a combination of the C# version of the CleanHtml function, and the section to clear out the MS Office tags. Essentially a code-based version of Glenn's process. I'll see what happens when I go to push it al to a giant Excel Spreadsheet.