我怎么能逃脱&在Haml中编译为&而不是& amp? (Haml菜鸟) [英] How could I escape a & in Haml so that it compiles to & instead of &? (Haml noob)

查看:60
本文介绍了我怎么能逃脱&在Haml中编译为&而不是& amp? (Haml菜鸟)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Icomoon图标字体与Haml一起使用,并且似乎找不到找到逃避&的方法,从而使它仅保留为&而不是&.

I am trying to use the Icomoon icon font with Haml and can't seem to find a way to escape the & so that it stays just an & instead of &.

Icomoon字体允许您使用带有data-icon ="属性的HTML实体.如果我只是直接进行HTML链接,则在HTML甚至在Haml文件中都可以像黄油一样平滑地工作.

The Icomoon font allows you to use HTML entities with a data-icon="" attribute. Works smooth as butter in HTML and even in a Haml file if I just do a straight HTML link.

但是,由于我正在学习Haml,所以我想我想看看这里的人是否愿意推荐解决这个问题的最佳方法.

However, since I'm learning Haml I thought I'd see if anyone on here would like to recommend the best way to approach this.

这是发生的情况的一个示例.

Here's a sample of what happens.

这是原始的Haml:

%a(href='/posts' data-icon="&#x0026" aria-hidden='true')

它是这样编译的:

<a aria-hidden='true' data-icon='&amp;#x0026' href='/posts'>

这是编译图标字体所需的工作方式:

This is how it needs to compile for the icon font to work:

<a aria-hidden='true' data-icon='&#x0026' href='/posts'>

这是一个Codepen,您可以在其中查看由于放大器而产生的图标的呈现方式;另外: http://codepen.io/dandenney/pen/3/6

and here is a codepen where you can see how the icon renders due to the amp; addition: http://codepen.io/dandenney/pen/3/6

推荐答案

您可以使用

You can use the :escape_attrs option to control whether HTML sensitive characters in attributes are escaped:

require 'haml'

haml = "%a(href='/posts' data-icon=\"&#x0026\" aria-hidden='true')"

puts Haml::Engine.new(haml, :escape_attrs => false).to_html

输出:

<a aria-hidden='true' data-icon='&#x0026' href='/posts'></a>

请注意,这将应用于Haml模板中的所有属性.

Note that this will apply to all attributes in your Haml template.

这篇关于我怎么能逃脱&amp;在Haml中编译为&amp;而不是&amp; amp? (Haml菜鸟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆