在Pug中有没有办法插值混排?

问题描述 投票:0回答:1

是否可以在一大块文字里面使用 mixins,或许可以通过插值的方式?我试过下面的语法,但没有成功。

p.
    The molecular #{+intext(1, "Cooper et al.")} structure of 
    AACs causes them to bind to chlorophyll and retain

基本上,我想在页面底部创建链接到参考文献 然后从引文返回到这段文字。所以混杂可以是这样的东西。

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

但是网页上会有很多文字和很多引用,管道会让它变得太复杂。

有没有什么方法可以实现,使用插值或过滤器?或者更简单的方法?

pug
1个回答
0
投票

明白了。这可以用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

完美的工作

© www.soinside.com 2019 - 2024. All rights reserved.