-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtml.js
More file actions
47 lines (37 loc) · 950 Bytes
/
html.js
File metadata and controls
47 lines (37 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
var sys = require("sys")
var html = require("../lib/html")
var fs = require('fs')
var args = process.argv.slice(0);
// shift off node and script name
args.shift()
args.shift()
if (args.length > 0) processFiles(args)
else readStdin()
function readStdin() {
var stdin = process.openStdin()
var data = ""
stdin.setEncoding("utf8")
stdin.on("data", function(chunk) {
data += chunk
})
stdin.on("end", function() {
process.stdout.write(html.prettyPrint(data, {indent_size: 2}))
})
}
function processFiles(files) {
if (files.length > 1) {
files.map(function(filename) {
prettifyFile(filename)
})
return
}
var str = fs.readFileSync(files[0]).toString()
process.stdout.write(prettify(str))
}
function prettify(str) {
return html.prettyPrint(str, {indent_size: 2})
}
function prettifyFile(filename) {
fs.writeFileSync(filename, prettify(fs.readFileSync(filename).toString()))
}