保留Jade中的换行符

Ere*_*evi 4 node.js pug

每当我渲染一个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
Run Code Online (Sandbox Code Playgroud)

jai*_*ime 5

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

根据您编译它们的方式,可以通过多种方式完成

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

(表达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 
Run Code Online (Sandbox Code Playgroud)

这将产生

<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>
Run Code Online (Sandbox Code Playgroud)

  • 您使用的是哪个版本的快递?在快递3中,我认为你必须从*app.locals*`app.locals.pretty = true`改变它.请查看此https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x (4认同)