有没有办法在 Pug 中插入 mixin?
Is there a way to interpolate a mixin in Pug?
是否可以在大块文本中使用 mixin,也许是通过插值?
我尝试了以下语法,但没有用:
p.
The molecular #{+intext(1, "Cooper et al.")} structure of
AACs causes them to bind to chlorophyll and retain
基本上,我想在页面底部创建指向参考文献的链接,并从引文返回到本文。所以 mixin 可能是这样的:
mixin intext(num, text)
span(id= 'intext' + num)
| (
a(href="#citation" + num)= text
| )
现在我知道我可以通过使用管道文本来解决这个问题:
p
| The molecular
+intext(1, "Cooper et al.")
| structure of AACs causes them to bind to chlorophyll and retain
但是网页会包含大量文本和大量引用,管道会使它变得过于复杂。
有什么方法可以实现这一点,使用插值或过滤器?或者更简单的东西?
知道了。这可以使用 JavaScript 函数本身来完成。
var intext = function(num, text) {
var link = "<a href=\"#citation" + num + "\">" + text + "</a>";
var wrapper = "<span id=\"intext" + num + "\">(" + link + ")</span>"
return wrapper;
}
然后使用它,
p.
The molecular !{intext(1, "Cooper et al.")} structure of
AACs causes them to bind to chlorophyll and retain
完美运行!
是否可以在大块文本中使用 mixin,也许是通过插值? 我尝试了以下语法,但没有用:
p.
The molecular #{+intext(1, "Cooper et al.")} structure of
AACs causes them to bind to chlorophyll and retain
基本上,我想在页面底部创建指向参考文献的链接,并从引文返回到本文。所以 mixin 可能是这样的:
mixin intext(num, text)
span(id= 'intext' + num)
| (
a(href="#citation" + num)= text
| )
现在我知道我可以通过使用管道文本来解决这个问题:
p
| The molecular
+intext(1, "Cooper et al.")
| structure of AACs causes them to bind to chlorophyll and retain
但是网页会包含大量文本和大量引用,管道会使它变得过于复杂。
有什么方法可以实现这一点,使用插值或过滤器?或者更简单的东西?
知道了。这可以使用 JavaScript 函数本身来完成。
var intext = function(num, text) {
var link = "<a href=\"#citation" + num + "\">" + text + "</a>";
var wrapper = "<span id=\"intext" + num + "\">(" + link + ")</span>"
return wrapper;
}
然后使用它,
p.
The molecular !{intext(1, "Cooper et al.")} structure of
AACs causes them to bind to chlorophyll and retain
完美运行!