在 pug mixin 属性中写入格式化文本

Write formatted text in pug mixin attributes

我需要在 mixin 属性中写入多行文本。但是找不到正确的方法。

所有这些方法都不起作用:

+someMixin({
  key: "text in \n two lines"
})
+someMixin({
  key: "text in two lines"
})
+someMixin({
  key: `text in${ }two lines`
})
+someMixin({
  key: `text in#{ }two lines`
})
+someMixin({
  key: `text in${\n}two lines`
})
+someMixin({
  key: `text in#{\n}two lines`
})
+someMixin({
  key: `text in#{br}two lines`
})
+someMixin({
  key: `text in${br}two lines`
})
+someMixin({
  key: `text in<br/>two lines`
})
+someMixin({
  key: 'text in<br/>two lines'
})

请告诉我这样做的可能性和正确的方法。 谢谢!

Pug mixin 旨在为控制变量获取属性,为内容获取块。您正在尝试对内容使用属性,这就是为什么您发现很难完成此操作的原因。

此 mixin 会将键视为分隔字符串,将其拆分为一个数组,然后为数组中的每个成员输出 <p> 个元素。

mixin someMixin(options)
  - var delimiter = '\n';
  - var output = options.key.split(delimiter);
  each line in output
    p= line

所以这个

+someMixin({
  key: "text in \n two lines \n no wait make it three"
})

然后会输出这个:

<p>text in </p>
<p> two lines <p>
<p> no wait make it three</p>