Created
August 30, 2016 07:23
-
-
Save ynaoto/fa0040adfef5172b42192a137e0a6267 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cat <<EOF | |
<!DOCTYPE html> | |
<meta charset="UTF-8"> | |
<title>ansi to html</title> | |
<style> | |
body { font-family: menlo; } | |
.e1m { font-weight: bold; } | |
.e4m { text-decoration: underline; } | |
.e30m { color: black; } | |
.e31m { color: red; } | |
.e32m { color: green; } | |
.e33m { color: yellow; } | |
.e34m { color: blue; } | |
.e35m { color: magenta; } | |
.e36m { color: cyan; } | |
.e37m { color: white; } | |
.e39m { color: black; } | |
</style> | |
EOF | |
awk -F ' | |
BEGIN { | |
inEsc = 0; | |
} | |
{ | |
for (i = 1; i <= NF; i++) { | |
cmd = ""; | |
s = $i; | |
if (s == "") continue; | |
if (match(s, /^\[[0-9]*m/)) { | |
cmd = substr(s, RSTART, RLENGTH); | |
s = substr(s, RLENGTH + 1); | |
} | |
gsub("&", "\\&", s); | |
gsub("\"", "\\"", s); | |
gsub("<", "\\<", s); | |
gsub(">", "\\>", s); | |
gsub(" ", "\\ ", s); | |
if (cmd == "[m" || cmd == "[0m") { | |
if (inEsc) printf "</span>"; | |
inEsc = 0; | |
} else if (cmd != "") { | |
printf "<span class=\"e" substr(cmd, 2) "\">"; | |
inEsc = 1; | |
} | |
printf s; | |
} | |
print "<br/>"; | |
} | |
' $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment