I'm working on a grunt build file which hits a URL and writes the output to a static HTML file. The url I'm hitting has compressed HTML and I'd like to pretty print it before writing to the static file. Are there any good modules for doing this? I've looked around and it seems like Max Ogden's html prettyprinter is my closest option (https://github.com/maxogden/commonjs-html-prettyprinter). Maybe if I combine it with the grunt-shell task or something? Really I'd prefer to just require a module in grunt and say pretty(my-file.html) and then write that using fs but so far that is proving elusive.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You found all the resources you need. That module does it for you.
var html = require("html");
var data = '<h2><strong><a href="http://awesome.com">AwesomeCom</a></strong><span>is awesome</span></h2>';
var prettyData = html.prettyPrint(data, {indent_size: 2});
process.stdout.write(prettyData)
Look at it's source.
Or you could use child_process to execute the command found in the README: html *.html
.