在 Jade 中保留换行符 [英] Preserving newlines in Jade
问题描述
每当我渲染 JADE 模板时,我都会在一行中获取所有 HTML.这使得在查看源模式下难以阅读.我如何告诉 JADE 创建正确缩进的 HTML?
这是我的模板:
#applicationp#docsa(href='/docs/index.html') 文档p#用户输入输入#msg(名称='msg',大小='50')input#submit(name='submit', type='submit', value='Send a Message')ul#messages
在 Jade 的编译选项中将 pretty
设置为 true.
可以通过多种方式完成,具体取决于您的编译方式
- 从命令行传递
-P
或--pretty
标志. - 来自 express 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.//<-- 注意点Lorem Ipsum 只是虚拟文本印刷和排版行业.Lorem Ipsum 一直是业界的标准假人自 1500 年代以来的文字,当一个不知名的打印机拿着一个类型的厨房并争先恐后
哪个会产生
Lorem Ipsum 只是虚拟文本印刷和排版行业.Lorem Ipsum 一直是业界的标准假人自 1500 年代以来的文字,当一个不知名的打印机拿着一个类型的厨房并争先恐后
Whenever I render a JADE template, I get all HTML in a single line. This makes it difficult to read in view-source mode. How can I tell JADE to create HTML which is properly indented?
Here is my template:
#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
In Jade's compiling options set pretty
to true.
Which can be done in multiple ways depending of how you are compiling them
- From the command line pass the
-P
or--pretty
flag. - From express 3.x:
app.locals.pretty = true;
(express 2.x used a different syntax: app.set('view options', { pretty: true });
, see migration guide: https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x)
Then you can do the following
#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
which will produce
<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>
这篇关于在 Jade 中保留换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!