Supported Codes
The following are examples of the ANSI escape codes which are supported (i.e. interpreted as a valid input) by HTMLPrinter
. Note that the representation depends on the renderer, since some codes are not widely supported and there are some code conflicts.
Bold and Faint
buf = IOBuffer()
print(buf, "\e[0m", "Normal ")
print(buf, "\e[1m", "Bold ")
print(buf, "\e[2m", "Faint ") # this unsets the "bold"
print(buf, "\e[0m", "Normal ")
HTMLPrinter(buf, root_class="documenter-example-output")
Normal Bold Faint Normal
Italic
buf = IOBuffer()
print(buf, "\e[0m", "Normal ")
print(buf, "\e[3m", "Italic ")
print(buf, "\e[1m", "Bold-Italic ") # this keeps the "italic"
print(buf, "\e[23m", "Bold ") # this keeps the "bold"
print(buf, "\e[0m", "Normal ")
HTMLPrinter(buf, root_class="documenter-example-output")
Normal Italic Bold-Italic Bold Normal
Underline and Strikethrough
buf = IOBuffer()
print(buf, "\e[0m", "Normal ")
print(buf, "\e[4m", " Underline ", "\e[24m", " ")
print(buf, "\e[9m", " Striethrough ", "\e[29m", " ")
print(buf, "\e[4;9m", " Both ", "\e[m")
HTMLPrinter(buf, root_class="documenter-example-output")
Normal Underline Striethrough Both
Invert
The invert code swaps the foreground and background colors. However, the support is limited. You will need to force the foreground and background colors to be switched manually, or convert the style afterwards using JavaScript etc.
buf = IOBuffer()
print(buf, "\e[0m", "Normal ")
print(buf, "\e[7m", "Invert ")
print(buf, "\e[27m", "Normal ")
print(buf, "\e[7;100m", "GrayText? ") # not supported by default.css
print(buf, "\e[34m", "BlueBG? ") # not supported by default.css
print(buf, "\e[0m", "Normal ")
HTMLPrinter(buf, root_class="documenter-example-output")
Normal Invert Normal GrayText? BlueBG? Normal
Conceal
buf = IOBuffer()
print(buf, "\e[0m", "Normal ")
print(buf, "\e[8m", "Conceal ")
print(buf, "\e[31;47m", "Red1 ") # this is still concealed
print(buf, "\e[0m", "Normal ")
print(buf, "\e[31;47m", "Red2 ")
print(buf, "\e[8m", "Conceal ")
print(buf, "\e[28m", "Red3 ")
print(buf, "\e[0m", "Normal ")
HTMLPrinter(buf, root_class="documenter-example-output")
Normal Conceal Red1 Normal Red2 Conceal Red3 Normal
16 colors
The 16 colors correspond to the color symbols which can be specified in the argument of printstyled
(e.g. :black
, :red
, :green
, :light_blue
). Their sRGB values are environment-dependent. This document defines their actual colors in a CSS file.
Basic colors
buf = IOBuffer()
for fg in [30:37; 39] # foreground color
for bg in [40:47; 49] # background color
print(buf, "\e[$fg;$(bg)m $fg; $bg ")
end
println(buf)
end
HTMLPrinter(buf, root_class="documenter-example-output")
30; 40 30; 41 30; 42 30; 43 30; 44 30; 45 30; 46 30; 47 30; 49 31; 40 31; 41 31; 42 31; 43 31; 44 31; 45 31; 46 31; 47 31; 49 32; 40 32; 41 32; 42 32; 43 32; 44 32; 45 32; 46 32; 47 32; 49 33; 40 33; 41 33; 42 33; 43 33; 44 33; 45 33; 46 33; 47 33; 49 34; 40 34; 41 34; 42 34; 43 34; 44 34; 45 34; 46 34; 47 34; 49 35; 40 35; 41 35; 42 35; 43 35; 44 35; 45 35; 46 35; 47 35; 49 36; 40 36; 41 36; 42 36; 43 36; 44 36; 45 36; 46 36; 47 36; 49 37; 40 37; 41 37; 42 37; 43 37; 44 37; 45 37; 46 37; 47 37; 49 39; 40 39; 41 39; 42 39; 43 39; 44 39; 45 39; 46 39; 47 39; 49
Light colors
buf = IOBuffer()
for fg in [90:97; 39] # foreground color
for bg in [100:107; 49] # background color
print(buf, "\e[$fg;$(bg)m $fg;$bg ")
end
println(buf)
end
HTMLPrinter(buf, root_class="documenter-example-output")
90;100 90;101 90;102 90;103 90;104 90;105 90;106 90;107 90;49 91;100 91;101 91;102 91;103 91;104 91;105 91;106 91;107 91;49 92;100 92;101 92;102 92;103 92;104 92;105 92;106 92;107 92;49 93;100 93;101 93;102 93;103 93;104 93;105 93;106 93;107 93;49 94;100 94;101 94;102 94;103 94;104 94;105 94;106 94;107 94;49 95;100 95;101 95;102 95;103 95;104 95;105 95;106 95;107 95;49 96;100 96;101 96;102 96;103 96;104 96;105 96;106 96;107 96;49 97;100 97;101 97;102 97;103 97;104 97;105 97;106 97;107 97;49 39;100 39;101 39;102 39;103 39;104 39;105 39;106 39;107 39;49
256 colors
The 256 colors correspond to the integer codes which can be specified in the argument of printstyled.
buf = IOBuffer()
for color in 0:15 # same as the 16 colors above.
print(buf, "\e[38;5;$color;48;5;$(color)m ")
print(buf, "\e[49m", lpad(color, 3), " ")
color % 8 == 7 && println(buf)
end
for color in 16:231 # 6 × 6 × 6 = 216 colors
(color - 16) % 12 == 0 && println(buf)
print(buf, "\e[38;5;$color;48;5;$(color)m ")
print(buf, "\e[49m", lpad(color, 3), " ")
end
println(buf)
for color in 232:255 # grayscale in 24 steps
(color - 232) % 12 == 0 && println(buf)
print(buf, "\e[38;5;$color;48;5;$(color)m ")
print(buf, "\e[49m", lpad(color, 3), " ")
end
print(buf, "\e[m")
HTMLPrinter(buf, root_class="documenter-example-output")
0 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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
24-bit colors
buf = IOBuffer()
print(buf, " \e[48;2;56;152;38m \n")
print(buf, "\e[48;2;203;60;51m ")
print(buf, "\e[48;2;149;88;178m ")
print(buf, "\e[49;38;2;64;99;216m 24-bit RGB\e[m")
HTMLPrinter(buf, root_class="documenter-example-output")
24-bit RGB