2012-12-06 105 views
4

每當我呈現一個JADE模板時,我都會在一行中獲取所有的HTML。這使得在視圖源模式下閱讀變得困難。我如何告訴JADE創建正確縮進的HTML?在Jade中保留換行符

這裏是我的模板:

#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 

回答

5

在玉的編譯選項設置pretty爲true。

這可以通過多種方式取決於你是如何編譯它們

  • 從命令行傳遞-P--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 

哪會產生

<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> 
+1

我使用Jade Express,所以我做了「app.set('view options',{pretty:true});」就在「.set('view engine','jade');」之後,我仍然把所有的HTML都放在一行中。我在問題中添加了我的Jade模板。 –

+4

您使用哪種版本的快遞?在快遞3中,我認爲你必須將它從* app.locals *'app.locals.pretty = true'中更改。檢查這個https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x – jaime

+0

啊,這些令人沮喪的版本...我剛剛開始使用NodeJS 2天前,我已經必須「遷移」...無論如何感謝! –