-o, --outdir <dir> - path to output generated jade file(s) to
-n, --nspaces <n> - the number of spaces to indent generated files with. Default is 2 spaces
-t, --tabs - use tabs instead of spaces
--donotencode - do not html encode characters. This is useful for template files which may contain expressions like {{username}}
--bodyless - do not output enveloping html and body tags
--numeric - use numeric character entities
-s, --scalate - generate Scalate variant of jade syntax
--noattrcomma - omit attribute separating commas
--noemptypipe - omit lines with only pipe ('|') printable character
Programmatic Usage (>= 0.0.7)
To convert raw HTML into Jade:
var html2jade = require('html2jade');
var html = "<html><body>Hello World</body></html>";
html2jade.convertHtml(html, {}, function (err, jade) {
// do your thing
});
To convert DOM document into Jade (client-side):
// assumes html2jade.js file has been loaded
Html2Jade.convertDocument(document, {}, function (err, jade) {
// do your thing
});
Converting Mustache/Handlebars Templates
Jade is commonly used to generate HTML with embedded Mustache or Handlebars templates.
Be sure to use version 0.8+ if you use template expressions in element IDs or CSS class names
to avoid generating invalid Jade files.
Miniclip is a Linux tray app that quickly converts
HTML to Jade, CSS to Stylus and JS to Coffee from clipboard.
Testing
As of version 0.4, there is a simple unit test that converts HTML files in test/data directory
and compare them against Jade files in the same directory. Unit test harness requires coffee-script
and mocha to be installed globally. Run the tests with command npm test.
Useful forks
If you're having issues with br line-breaks which apparently Jade has some problems with,
try @smaudet's
fix-breaklines branch.
请发表评论