Rails 3.1 HAML 在 `:escaped` 块上转义太多,如何控制它以使其仅转义 & 符号?
我有 Wistia 提供的一段代码,用于将视频嵌入到页面中。该源是可嵌入的原始 html,它们直接在其中包含一些&符号。当然,我的 w3c 验证器整天对我大喊大叫,其中包含这些内容,我收到了数百个错误,例如: <代码>&没有开始角色参考。 (& 可能应该被转义为 &。)
我的视图是 HAML,所以我假设我需要转义序列,我很高兴地这样做了:
:escape
<object width="...
这样做后,视频不再加载时,它已经使用 <object width=" 转义了整个字符串。 ...等等
如何以编程方式正确转义此类序列,而不是每次使用 HAML 在 Rails 3.1 中进行新更新时手动更改插入的字符串?
I have a chunk of code provided by Wistia to embed videos into a page. This source is embedable raw html and they include some ampersands in it directly. Of course my w3c validator yells at me all day long and with these in it I'm getting hundreds of errors like:& did not start a character reference. (& probably should have been escaped as &.)
My view is in HAML so I'm assuming that I needed to escape the sequence, which I happily did with:
:escape
<object width="...
Upon doing this the video no longer loads as it has escaped the entire string with <object width=" ... etc.
How would one properly escape such sequences programmatically vs manually altering the inserted string each time a new update is made in Rails 3.1 with HAML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望将 HTML 放入其自己的部分中,然后将其呈现为字符串并对其执行
String#gsub
。将您的 Wistia HTML 放入名为 app/views/shared/_wistia.html 的部分,
然后创建一个如下所示的帮助器:
在您的 HAML 中,只需输入
= embed_video 'wistia'< /code> 无论您想要将视频插入到哪里。
You'll probably want to put your HTML into its own partial, then render it into a string and do a
String#gsub
on it.Put your Wistia HTML into a partial called something like app/views/shared/_wistia.html
Then create a helper that looks like:
And in your HAML, just put
= embed_video 'wistia'
wherever you want the video to be inserted.