5

I am using Jade in Express.js and I noticed that the html output is all in one line. On the Jade website ( http://scalate.fusesource.org/documentation/jade-syntax.html ) it says that formatted output is standard and that the options are ScamlOptions.nl and ScamlOptions.indent, but I can't find those options anywhere to see if they are set incorrectly. Does anyone know where I can find those options or is there another way to force clean formatting?

Thanks!

This thread didn't help: How to output pretty html in Express?

Community
  • 1
  • 1
Ben
  • 63
  • 1
  • 3
  • Scalate is Scala implementation of jade. JavaScript jade implementation, which are utilized by express, placed in the project repo on the github https://github.com/visionmedia/jade#readme – Phillip Kovalev Sep 01 '11 at 13:49
  • 3
    See this similar question: http://stackoverflow.com/questions/5276892/expressjs-how-to-output-pretty-html – Jonathan Julian Sep 29 '11 at 01:07
  • 1
    Why didn't the two stackoverflow links specified help? How are you formatting your Express view options? – Jon Nov 22 '11 at 18:34

2 Answers2

9

In Express 3, the api has changed for (at least) this view option.

I set app.locals.pretty and it seems to be working just fine. I call it within my app.js (or server.js) right after I set the view engine in app.configure()

app.use(function(req, res, next) {
  app.locals.pretty = true;
  next();
});
electblake
  • 2,027
  • 18
  • 25
  • 1
    For express 3.x this is correct. You can place it in your app.js - if you've used the bare bones express scaffold place `app.locals.pretty = true;` under the `// all environments` section. – Gilman May 09 '13 at 18:42
7
  1. Scalate != Jade

Also, Jade is not designed to create human-readable output. All the indention and new lines are just wasting space and are not important for any browser to process you HTML. But you could try:

  1. Try: app.set('view options', { pretty: true });
  2. Use Firebug or Chrome Inspector to view your HTML ;-)
  3. Use any HTML cleanup tool.
TheHippo
  • 61,720
  • 15
  • 75
  • 100
  • This was with express 2 (or even express 1), they changed the API of express with the release of version 3. @AmericanYak – TheHippo Dec 30 '12 at 00:51