漂亮打印HTML模块? [英] Module for Pretty Printing HTML?

查看:129
本文介绍了漂亮打印HTML模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个grunt构建文件,它命中一个URL并将输出写入一个静态HTML文件。我打的URL有压缩的HTML,我想在写入静态文件之前打印它。有没有好的模块可以做到这一点?我环顾四周,似乎Max Ogden的漂亮打印机是我最接近的选项(https://github.com/maxogden/commonjs-html-prettyprinter)。也许如果我将它与grunt-shell任务结合起来呢?真的,我宁愿只是需要一个模块在咕噜咕噜,说漂亮(my-file.html),然后使用fs编写,但到目前为止,这是难以捉摸的。

解决方案

你找到了你需要的所有资源。

  var html = require(html); 
var data ='< h2>< strong>< a href =http://awesome.com> AwesomeCom< / a>< / strong>< span>跨度>< / H2>';
var prettyData = html.prettyPrint(data,{indent_size:2});
process.stdout.write(prettyData)

看看来源






或者您可以使用 child_process 执行在README中找到的命令: html * .html

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.

解决方案

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.

这篇关于漂亮打印HTML模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆