在 Markdown 中仅允许 Youtube/Vimeo iframe
我正在尝试允许用户在我们正在开发的 Rails3 应用程序的帖子中嵌入 youtube 或 vimeo 视频,并且现在都使用 iframe。清理助手似乎只允许您在全局范围内将标签列入白名单 - 此外,youtube 的 iframe 具有一致的类,但 vimeo 没有。
您将如何将这两个网址的嵌入列入白名单,但不允许它们以其他方式嵌入?
I'm trying to allow users to embed youtube or vimeo videos in posts for a Rails3 app we're working on, and both use iframes now. The sanitize helper seems like it only allows you to whitelist tags on a global basis - further, youtube has a consistent class for their iframes, but vimeo does not.
How would you go about whitelisting embeds from those two urls, but not allow them otherwise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定如何使用清理方法将标签列入白名单,但您始终可以通过另一种方法进行过滤,并使用正则表达式专门检查 src,并且仅写出它是否与 youtube 匹配。
I am not sure about how to whitelist tags using the sanitize method, but you could always filter through another method and specifically check for the src using regex and only write out if it matched youtube.
http://github.com/rgrove/sanitize/
这是一个很棒的项目,有一个示例youtube 嵌入也允许。 YouTube 最近已更改为 iframe,我正在向他们提交一个“过滤器”示例:
http://github.com/rgrove/sanitize/
This is a great project, with an example for youtube embeds allowing as well. Youtube has recently changed to iframe, and I'm submitting an example "filter for it" to them: