简体   繁体   English

漂亮打印HTML模块?

[英]Module for Pretty Printing HTML?

I'm working on a grunt build file which hits a URL and writes the output to a static HTML file. 我正在研究一个grunt构建文件,该文件命中URL并将输出写入静态HTML文件。 The url I'm hitting has compressed HTML and I'd like to pretty print it before writing to the static file. 我正在点击的网址已压缩HTML,我想在写入静态文件之前将其打印出来。 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). 我环顾四周,似乎Max Ogden的html prettyprinter是我最接近的选项(https://github.com/maxogden/commonjs-html-prettyprinter)。 Maybe if I combine it with the grunt-shell task or something? 也许如果我将它与grunt-shell任务结合起来? 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. 真的,我宁愿只需要一个grunt中的模块并说漂亮(my-file.html),然后使用fs编写,但到目前为止,这证明是难以捉摸的。

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 . 或者您可以使用child_process来执行README: html *.html的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM