javascript 从 TinyMCE 复制+粘贴中剥离样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7878492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Stripping styles from TinyMCE copy+paste?
提问by Walker
is there a way to strip specific tags from coming into tiny MCE through a copy+paste from an external source (e.g. Word)? I'd like to prevent font-family and image tags from being copy+pasted over, but have no problem with font-size etc.
有没有办法通过从外部来源(例如 Word)复制+粘贴将特定标签从进入微型 MCE 中剥离出来?我想防止字体系列和图像标签被复制+粘贴,但字体大小等没有问题。
Thank you!
谢谢!
采纳答案by Brian Glaz
You can't really stop someone from pasting something, so I believe your best bet would be to filter out the unwanted tags by calling a function on form submit, or onchange of the tiny MCE textarea. Then you could use some regular expression replacement to get rid of the unwanted tags.
你不能真正阻止某人粘贴某些东西,所以我相信你最好的办法是通过在表单提交或微小 MCE textarea 的 onchange 上调用函数来过滤掉不需要的标签。然后你可以使用一些正则表达式替换来摆脱不需要的标签。
EDIT:Actually there is a simple way. check the TinyMCE documentation.
编辑:实际上有一个简单的方法。检查TinyMCE 文档。
回答by Thariama
Here is the link to a similar SO question with a detailed description of howto strip out unwanted tags: TinyMCE Paste As Plain Text
这是一个类似 SO 问题的链接,其中详细描述了如何去除不需要的标签:TinyMCE Paste As Plain Text
回答by Hirvesh
I don't know how useful this will be, but you might want to take a look at this jQuery plugin which allows you to filter tags and attributed from the text your are pasting.
我不知道这会有多大用处,但您可能想看看这个 jQuery 插件,它允许您从您粘贴的文本中过滤标签和属性。
FilteredPaste.js - A jQuery Plugin To Filter & Clean Pasted Input