在 Jade 模板中,如何将文字 URL 作为 link 锚点?
In a Jade template how do I put a literal URL as a link anchor?
在 Node.js Express 网络应用程序中,我想在我的一个视图中的某些文档中包含 link,并将 URL 显示为锚文本。在 Jade: Links inside a paragraph 之后,我尝试了:
p See #[a(href="http://example.com/help/123") http://example.com/help/123]
但是,这会导致错误,"The end of the string was reached with no closing bracket found."
如果我在锚文本周围加上引号,它大部分都有效,但我最终会在 HTML 输出中看到引号,这是我不想要的。
p See #[a(href="http://example.com/help/123") "http://example.com/help/123"]
未加引号的 URL 是不是搞乱了括号内内容的计算?如果是这样,我能以某种方式逃避它以防止出现问题吗?
使用一个变量:
-var helpurl="http://example.com/help/123"
p See #[a(href=helpurl) #{helpurl}]
URL 中的双斜杠本身可能被解释为评论的开始,并阻止评估者阅读表达式的其余部分,包括其右括号。
编辑:从@laggingreflex (https://github.com/jadejs/jade/issues/2144) 亲切打开的问题来看,实际上是 Jade 2.0.0 之前的冒号斜杠序列有问题.对于使用早期版本的用户,Jade 作者 ForbesLindesay 建议使用等号对文字字符串求值。
p See #[a(href="http://example.com/help/123")= "http://example.com/help/123"]
在 Node.js Express 网络应用程序中,我想在我的一个视图中的某些文档中包含 link,并将 URL 显示为锚文本。在 Jade: Links inside a paragraph 之后,我尝试了:
p See #[a(href="http://example.com/help/123") http://example.com/help/123]
但是,这会导致错误,"The end of the string was reached with no closing bracket found."
如果我在锚文本周围加上引号,它大部分都有效,但我最终会在 HTML 输出中看到引号,这是我不想要的。
p See #[a(href="http://example.com/help/123") "http://example.com/help/123"]
未加引号的 URL 是不是搞乱了括号内内容的计算?如果是这样,我能以某种方式逃避它以防止出现问题吗?
使用一个变量:
-var helpurl="http://example.com/help/123"
p See #[a(href=helpurl) #{helpurl}]
URL 中的双斜杠本身可能被解释为评论的开始,并阻止评估者阅读表达式的其余部分,包括其右括号。
编辑:从@laggingreflex (https://github.com/jadejs/jade/issues/2144) 亲切打开的问题来看,实际上是 Jade 2.0.0 之前的冒号斜杠序列有问题.对于使用早期版本的用户,Jade 作者 ForbesLindesay 建议使用等号对文字字符串求值。
p See #[a(href="http://example.com/help/123")= "http://example.com/help/123"]