4

每当我渲染一个 JADE 模板时,我都会在一行中获得所有 HTML。这使得在查看源代码模式下难以阅读。如何告诉 JADE 创建正确缩进的 HTML?

这是我的模板:

#application
  p#docs
    a(href='/docs/index.html') Documentation

  p#user-input
    input#msg(name='msg', size='50')
    input#submit(name='submit', type='submit', value='Send a Message')

  ul#messages
4

1 回答 1

5

在 Jade 的编译选项中设置pretty为 true。

这可以通过多种方式完成,具体取决于您如何编译它们

  • 从命令行传递-Por--pretty标志。
  • 从快递 3.x 开始:app.locals.pretty = true;

(express 2.x 使用了不同的语法:app.set('view options', { pretty: true });,请参阅迁移指南:https ://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x )

然后您可以执行以下操作

#test.     // <-- notice the dot
    Lorem Ipsum is simply dummy text of 
    the printing and typesetting industry. 
    Lorem Ipsum has been the industry's standard dummy 
    text ever since the 1500s ,
    when an unknown printer took a galley of type and scrambled 

这将产生

<div id="test">
    Lorem Ipsum is simply dummy text of 
    the printing and typesetting industry. 
    Lorem Ipsum has been the industry's standard dummy 
    text ever since the 1500s ,
    when an unknown printer took a galley of type and scrambled 
</div>
于 2012-12-06T13:30:59.773 回答