jade模板引擎(在node.js下):不带pipe道符号的多行块

我目前正在使用Jade进行一个新项目。 它似乎非常适合编写webapp布局,但不适合编写静态内容,如网页

包含文本的元素。

例如,为了创build这样一个段落,我相信我需要这样做:

p | This is my long, | multi-line | paragraph. 

对于一个真正的文本段落的静态网页,使用玉成为一个负担,由于在每一行开头的pipe道符号。

是否有某种语法糖用于将整个块标记为文本节点,因为pipe道符号是逐行的? 或者我不知道现有的filter?

我正在探索的一个解决scheme是创build一个:阻塞filter或者其他东西,这个filter预先给每行添加一个| 然后把它传递给玉,但玉创buildfilter的文档是稀疏的,至less可以说,所以这可能需要一段时间来弄清楚。 如果任何人都可以提供这样的解决scheme的指导,我会感激。

从玉github页面 :

 p. foo asdf asdf asdfasdfaf asdf asd. 

产生输出:

 <p>foo asdf asdf asdfasdfaf asdf asd . </p> 

p之后的后期是你正在寻找的东西。

经过一番修改之后,我制定了一个完成这个filter的细节。 在这里发表答案,因为我想这对于使用玉器的人来说是有用的。

创buildfilter的代码变得非常简单:

 var jade = require ("jade"); jade.filters.text = function(block, compiler){ return new TextBlockFilter(block).compile(); }; function TextBlockFilter(node) { this.node = node; } TextBlockFilter.prototype.__proto__ = jade.Compiler.prototype; TextBlockFilter.prototype.visit = function(node){ // first this is called with a node containing all the block's lines // as sub-nodes, with their first word interpreted as the node's name // // so here, collect all the nodes' text (including its name) // into a single Text node, and then visit that instead. // the child nodes won't be visited - we're cutting them out of the // parse tree var text = new jade.nodes.Text(); for (var i=0; i < node.length; i++) { text.push (node[i].name + (node[i].text ? node[i].text[0] : "")); } this.visitNode (text); }; 

然后标记看起来像这样。 请注意,它允许你在其中包含其他的玉石:文本块:

 p :text This is my first line of text, followed by another and another. Now let's include a jade link tag: a(href="http://blahblah.com") :text and follow it with even more text and more, etc