-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhighlight.js
109 lines (102 loc) · 1.39 KB
/
highlight.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const fs = require("fs")
let w = (ch, color = "white") => {
let col = "\033[38;5;";
let num;
switch (color) {
case "teal":
num = 48
break
case "white":
num = 15
break
case "green":
num = 40
break
case "red":
num = 1
break
case "crimson":
num = 124
break
case "purple":
num = 162
break
case "orange":
num = 9
break
case "lgreen":
num = 46
break
case "yellow":
num = 220
break
case "black":
num = 16
break
case "pink":
num = 213
break
default:
num = 196
break
}
col += num + "m"
process.stdout.write(col+ch)
}
fs.readFile(process.argv[2], function(err, data) {
data = data.toString()
console.log("")
for (d of data) {
switch (d) {
case ">":
case "<":
case "^":
case "v":
case "?":
case "@":
w(d, "lgreen")
break
case "+":
case "-":
case "/":
case "*":
case "%":
case "!":
case "`":
w(d, "purple")
break
case "_":
case "|":
w(d, "red")
break
case "\"":
w(d, "crimson")
break
case ":":
case "\\":
case "$":
case "#":
w(d, "yellow")
break
case ".":
case ",":
case "p":
case "g":
case "~":
case "&":
w(d, "orange")
break
case "=":
case "{":
case "}":
w(d, "white")
break
default:
if (!isNaN(d)) {
w(d, "pink")
} else {
w(d, "red")
}
}
}
})