如何让 Jade 停止 HTML 编码元素属性,并生成文字字符串值? [英] How to make Jade stop HTML encoding element attributes, and produce a literal string value?
问题描述
UPDATE Jade v0.24.0 使用 !=
属性语法修复了这个问题.option(value!='<%= id %>')
UPDATE Jade v0.24.0 fixes this with a !=
syntax for attributes. option(value!='<%= id %>')
我正在尝试使用 jade 构建一个 ,其中选项的值是一个 UnderscoreJS 模板标记:
<%= id %>
但我无法让它工作,因为 jade 正在将我的标记文本转换为 <= id >
.
I'm trying to build an <option>
with jade, where the value of the option is an UnderscoreJS template marker: <%= id %>
but I can't get it to work because jade is converting my marker text to <= id >
.
这是我的 Jade 标记:
Here's my Jade markup:
script(id="my-template", type="text/template")
select(id="type")
<% _.each(deviceTypes, function(type){ %>
option(value='<%= type.id %>') <%= type.name %>
<% }) %>
我希望它产生这个 html:
I expect it to produce this html:
<script id="my-template" type="text/template">
<select id='type'>
<% _.each(deviceTypes, function(type){ %>
<option value="<%= type.id %>"> <%= type.name %> </option>
<% }) %>
</select>
</script>
但我得到的是:
<script id="my-template" type="text/template">
<select id='type'>
<% _.each(deviceTypes, function(type){ %>
<option value="<%= type.id %>"> <%= type.name %> </option>
<% }) %>
</select>
</script>
注意输出的 <option>
行中非常细微的差异...选项的 value
属性已被 HTML 编码.
Note the very subtle difference in the <option>
line of the output... the value
attribute of the option has been HTML encoded.
如何防止 Jade 对这个值进行 HTML 编码?我需要它来生成文字值,就像处理选项的文本一样.
How do I prevent Jade from HTML encoding this value? I need it to produce the literal value, the same way it does with the text of the option.
推荐答案
在撰写本文时,我不相信有解决方案.看到这个问题:https://github.com/visionmedia/jade/issues/198
As of this writing I don't believe there's a way to it. See this issue: https://github.com/visionmedia/jade/issues/198
我最终使用原始 HTML 来解决它,使用 |前缀.
I ended up dropping into raw HTML to solve it, using the | prefix.
这篇关于如何让 Jade 停止 HTML 编码元素属性,并生成文字字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!