How could I escape a & in Haml so that it compiles to & instead of &? (Haml noob)

前端 未结 3 936
轻奢々
轻奢々 2020-12-20 04:09

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

3条回答
  •  一整个雨季
    2020-12-20 04:55

    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=\"&\" aria-hidden='true')"
    
    puts Haml::Engine.new(haml, :escape_attrs => false).to_html
    

    Output:

    
    

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

提交回复
热议问题