WYSIWYG 限制可以放入的 HTML
我正在寻找一个所见即所得的工具,它允许我指定文本区域中允许的 HTML 标签白名单并呈现它们,同时丢弃其他任何内容。如果用户复制并粘贴内容或手动编辑 HTML,则需要运行此验证。
有点像 HTML Purifier,但采用 Javascript 所见即所得。
我已经尝试过 CKEditor 的 dataProcessor.dataFilter 设置,但这需要列出要排除的每个标签,因此它是黑名单而不是白名单。
有什么想法吗?
编辑...
请不要简单地建议使用{xyz}编辑器。我正在寻找带有代码示例的建议,展示如何以这种方式使用建议的编辑器。
I am looking for a WYSIWYG that will allow me to specify a whitelist of HTML tags that are allowed in the textarea and renders them, whilst discarding anything else. This validation would need to run if the user copies and pastes content in or editing the HTML manually.
Sort of like HTML Purifier but in a Javascript WYSIWYG.
I have played around with CKEditor's dataProcessor.dataFilter
setting but that would need to list every tag to EXCLUDE so its a blacklist rather than a whitelist.
Any ideas?
Edit...
Please don't simply suggest use {xyz} editor. I am looking for suggestions with code samples showing how to use the suggested editor in this manner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用tinyMCE,您可以获得有效元素、无效元素和扩展有效元素
您可以查看这些代码并使用配置通过查看 示例
提交表单或按下删除格式按钮(如本示例中)运行验证并退出所有无效的格式。
您必须小心,因为这并不能确保恶意用户不会直接向您发送无效的 html 并尝试导致 XSS 攻击。这意味着如果您打算再次向用户提供 html,您仍然需要在服务器端进行验证。
Using tinyMCE you can have a list of valid elements, invalid elements, and extended valid elements
You can see the code for these and play with the configuration options on tinyMCE's website by looking at examples
When the form is submitted or the remove formatting button is pressed (as in this example) the validation is ran and pulls out all the non-valid formatting.
You must be careful for this does not ensure that a malicious user will not directly send you non-valid html and try to cause a XSS attack. This means you still need validation on the server side if you intend to serve the html up to users again.