Jade - Controlling line-breaks in the HTML output

大城市里の小女人 提交于 2019-12-05 03:19:11

I was looking for the same thing and came across this: http://scalate.fusesource.org/documentation/jade-syntax.html

Under Plain text: Whitespace Removal: > and <

I was having an issue with whitespace inside an <a> tag:

a.external(href={"http://foo.bar/" + reference.dxLink.get})
  |CrossRef

resulted in

<a href="http://foo.bar/10.1002/rmv.439">
                  CrossRef
</a>

Adding < to the end of the line:

a.external(href={"http://foo.bar/" + reference.dxLink.get})<
  |CrossRef

resulted in

<a href="http://foo.bar/10.1002/rmv.439">CrossRef</a>

If this is Jade for Node JS you can force jade to remove or add whitespace with the 'pretty' paramater

var jade = require('./../')
  , path = __dirname + '/whitespace.jade'
  , str = require('fs').readFileSync(path, 'utf8')
  , fn = jade.compile(str, { filename: path, pretty: true });

You could put your form template in a separate file (ex:myform.jade) and set pretty to false for that template when you load, or create a helper for this same purpose.

I also had this problem. locals.pretty is set to true under development as I want to read the rendered html. The space between two inputs would cause style problem.

My current solution is to use raw html for that two inputs:

form
  <input type="text" size="16" placeholder="Enter your keywords"><input type="button" value="Search">

This mixes a little none-jade text but renders the inputs without the extra space between them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!