dust.js包括没有修剪的partitial

我正在使用dust.js模板引擎。 主要的模板包括一个部分,问题是dust.js修剪包含的模板文件的每一行。

例如,主要模板是:

<h1>{header}</h1> {>dust_cnt /} 

dust_cnt.dust是:

 <div> This is the content </div> 

我通过以下方式呈现响应:res.render('dust_template.dust',{header:'TEST OK'});

This is和输出中the content之间没有空间的问题。 所以输出如下所示:

 TEST OK This isthe content 

我不能通过放置{〜n}或其他分隔符来改变所有的内容 ,我不认为有这样的理由。

在http://linkedin.github.com/dustjs/上我发现了下面的注释GH- 166 - Added trimming of white spaces in dust templates configuration in the dust.compile ( default option is still true) 。 但是找不到设置选项的方法来避免修剪?

我如何使dust.js按照我期望的方式(与空格)呈现?

先谢谢你!

好的,我find了解决scheme:)。 在挖掘源代码+检查尘埃的GitHub上的问题后,我决定使用以下内容来防止模板节点的格式化:

 dust.optimizers.format = function(ctx, node) { return node }; 

(也在https://github.com/linkedin/dustjs/wiki/Dust-Tutorial#controlling-whitespace-suppression

默认的行为是非常危险的 – 正如它在GitHub上提到的,它可能会导致严重的问题,例如:

 <script> //this will alert "test" alert("this is test"); </script> 

将呈现为:

 <script>//this will alert "test" alert("this is test");</script> 

这很奇怪,我知道你不想编辑你的模板文件。 但是,您可以通过在该行末尾添加空格来以较不难看的方式解决此问题:

 <div> This is < add space here the content </div> 

只是为了这种情况,你不能find一个真正的解决scheme。