.m-console .g-AnsiBrightCyan { color: #16a085; font-weight: bold }
.m-console .g-AnsiBrightDefault { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightGreen { color: #1cdc9a; font-weight: bold }
+.m-console .g-AnsiBrightInvertedDefault { color: #1a1c1d; font-weight: bold }
.m-console .g-AnsiBrightMagenta { color: #8e44ad; font-weight: bold }
.m-console .g-AnsiBrightRed { color: #c0392b; font-weight: bold }
.m-console .g-AnsiBrightWhite { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightYellow { color: #fdbc4b; font-weight: bold }
.m-console .g-AnsiCyan { color: #1abc9c }
.m-console .g-AnsiGreen { color: #11d116 }
+.m-console .g-AnsiInvertedDefault { color: #1a1c1d }
.m-console .g-AnsiMagenta { color: #9b59b6 }
.m-console .g-AnsiRed { color: #ed1515 }
.m-console .g-AnsiWhite { color: #fcfcfc }
.m-console .g-AnsiBrightCyan { color: #16a085; font-weight: bold }
.m-console .g-AnsiBrightDefault { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightGreen { color: #1cdc9a; font-weight: bold }
+.m-console .g-AnsiBrightInvertedDefault { color: #1a1c1d; font-weight: bold }
.m-console .g-AnsiBrightMagenta { color: #8e44ad; font-weight: bold }
.m-console .g-AnsiBrightRed { color: #c0392b; font-weight: bold }
.m-console .g-AnsiBrightWhite { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightYellow { color: #fdbc4b; font-weight: bold }
.m-console .g-AnsiCyan { color: #1abc9c }
.m-console .g-AnsiGreen { color: #11d116 }
+.m-console .g-AnsiInvertedDefault { color: #1a1c1d }
.m-console .g-AnsiMagenta { color: #9b59b6 }
.m-console .g-AnsiRed { color: #ed1515 }
.m-console .g-AnsiWhite { color: #fcfcfc }
.m-console .g-AnsiBrightCyan { color: #16a085; font-weight: bold }
.m-console .g-AnsiBrightDefault { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightGreen { color: #1cdc9a; font-weight: bold }
+.m-console .g-AnsiBrightInvertedDefault { color: #1a1c1d; font-weight: bold }
.m-console .g-AnsiBrightMagenta { color: #8e44ad; font-weight: bold }
.m-console .g-AnsiBrightRed { color: #c0392b; font-weight: bold }
.m-console .g-AnsiBrightWhite { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightYellow { color: #fdbc4b; font-weight: bold }
.m-console .g-AnsiCyan { color: #1abc9c }
.m-console .g-AnsiGreen { color: #11d116 }
+.m-console .g-AnsiInvertedDefault { color: #1a1c1d }
.m-console .g-AnsiMagenta { color: #9b59b6 }
.m-console .g-AnsiRed { color: #ed1515 }
.m-console .g-AnsiWhite { color: #fcfcfc }
.m-console .g-AnsiBrightCyan { color: #16a085; font-weight: bold }
.m-console .g-AnsiBrightDefault { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightGreen { color: #1cdc9a; font-weight: bold }
+.m-console .g-AnsiBrightInvertedDefault { color: #1a1c1d; font-weight: bold }
.m-console .g-AnsiBrightMagenta { color: #8e44ad; font-weight: bold }
.m-console .g-AnsiBrightRed { color: #c0392b; font-weight: bold }
.m-console .g-AnsiBrightWhite { color: #ffffff; font-weight: bold }
.m-console .g-AnsiBrightYellow { color: #fdbc4b; font-weight: bold }
.m-console .g-AnsiCyan { color: #1abc9c }
.m-console .g-AnsiGreen { color: #11d116 }
+.m-console .g-AnsiInvertedDefault { color: #1a1c1d }
.m-console .g-AnsiMagenta { color: #9b59b6 }
.m-console .g-AnsiRed { color: #ed1515 }
.m-console .g-AnsiWhite { color: #fcfcfc }
.m-console .g-AnsiBrightCyan { color: #16a085; font-weight: bold } /* Generic.AnsiBrightCyan */
.m-console .g-AnsiBrightDefault { color: #ffffff; font-weight: bold } /* Generic.AnsiBrightDefault */
.m-console .g-AnsiBrightGreen { color: #1cdc9a; font-weight: bold } /* Generic.AnsiBrightGreen */
+.m-console .g-AnsiBrightInvertedDefault { color: #1a1c1d; font-weight: bold } /* Generic.AnsiBrightInvertedDefault */
.m-console .g-AnsiBrightMagenta { color: #8e44ad; font-weight: bold } /* Generic.AnsiBrightMagenta */
.m-console .g-AnsiBrightRed { color: #c0392b; font-weight: bold } /* Generic.AnsiBrightRed */
.m-console .g-AnsiBrightWhite { color: #ffffff; font-weight: bold } /* Generic.AnsiBrightWhite */
.m-console .g-AnsiBrightYellow { color: #fdbc4b; font-weight: bold } /* Generic.AnsiBrightYellow */
.m-console .g-AnsiCyan { color: #1abc9c } /* Generic.AnsiCyan */
.m-console .g-AnsiGreen { color: #11d116 } /* Generic.AnsiGreen */
+.m-console .g-AnsiInvertedDefault { color: #1a1c1d } /* Generic.AnsiInvertedDefault */
.m-console .g-AnsiMagenta { color: #9b59b6 } /* Generic.AnsiMagenta */
.m-console .g-AnsiRed { color: #ed1515 } /* Generic.AnsiRed */
.m-console .g-AnsiWhite { color: #fcfcfc } /* Generic.AnsiWhite */
# ANSI highlighting. Same order as in Konsole style dialog, following
# the Breeze theme.
+ Generic.AnsiInvertedDefault: '#1a1c1d',
Generic.AnsiBlack: '#232627',
Generic.AnsiRed: '#ed1515',
Generic.AnsiGreen: '#11d116',
Generic.AnsiMagenta: '#9b59b6',
Generic.AnsiCyan: '#1abc9c',
Generic.AnsiWhite: '#fcfcfc',
+ Generic.AnsiBrightInvertedDefault: 'bold #1a1c1d',
Generic.AnsiBrightBlack: 'bold #7f8c8d',
Generic.AnsiBrightRed: 'bold #c0392b',
Generic.AnsiBrightGreen: 'bold #1cdc9a',
from pygments.formatters import HtmlFormatter
from pygments.token import *
-# Support ANSI SGR codes in input, styling the output.
-# Code definitions are taken from
-# http://man7.org/linux/man-pages/man4/console_codes.4.html, which
+# Support ANSI SGR codes in input, styling the output. Code definitions are
+# taken from http://man7.org/linux/man-pages/man4/console_codes.4.html, which
# appears in part below, in case it disappears:
#
# ECMA-48 Set Graphics Rendition
# For historical reasons, all "brown"s above are replaced with "yellow"
# by m.css.
#
-# AnsiLexer supports commands 0, 1, 22, 30–39, 40–49, 90–97, and 100–107
-# (ranges inclusive).
-# All other commands will be ignored completely.
+# AnsiLexer supports commands 0, 1, 7, 22, 27, 30–39, 40–49, 90–97, and 100–107
+# (ranges inclusive). All other commands will be ignored completely.
#
# Foreground colors named Bright* are not affected by the "bright" SGR
# setting—they will always appear bright, even after command 22 resets the
RegexLexer.__init__(self, **options)
self._bright = False
+ self._invert = False
self._foreground = ''
self._background = ''
command = parameters.pop(0)
if command == 0:
self._bright = False
+ self._invert = False
self._foreground = ''
self._background = ''
elif command == 1:
self._bright = True
+ elif command == 7:
+ self._invert = True
elif command == 22:
self._bright = False
+ elif command == 27:
+ self._invert = False
elif command >= 30 and command <= 37:
self._foreground = self._named_colors[command - 30]
elif command == 38:
self._background = ('Bright' +
self._named_colors[command - 100])
- if self._bright and self._foreground in self._named_colors:
- token = 'Bright' + self._foreground
- elif self._bright and not self._foreground:
- token = 'BrightDefault'
+ # For "inverse video", foreground and background colors are swapped
+ if self._invert:
+ foreground, background = self._background, self._foreground
else:
- token = self._foreground
+ foreground, background = self._foreground, self._background
- if (self._background):
- token += '-On' + self._background
+ # If the bright bit is set for named colors (foreground or background
+ # in case of reverse video), use their bright variant
+ if self._bright and (not foreground or (foreground in self._named_colors)):
+ token = 'Bright'
+ else:
+ token = ''
+
+ # If the foreground color (or background in case of inverse video) is
+ # set, use it. Otherwise pick a default if it's needed for the bright
+ # variant, for inverse video or both.
+ if foreground:
+ token += foreground
+ else:
+ if self._invert:
+ token += 'Inverted'
+ if token:
+ token += 'Default'
+
+ # If the background color is set (or foreground in case of inverse
+ # video), use it as well. This gets subsequently separated to either a
+ # secondary CSS class or a separate background-color style item.
+ if background:
+ token += '-On' + background
if token:
token = 'Generic.Ansi' + token
\e[38;2;0;128;128;48;2;0;128;128mRGB 0,128,128 on RGB 0,128,128\e[0m
\e[38;2;192;192;0;48;2;0;128;128mRGB 192,192,0 on RGB 0,128,128\e[0m
+\e[1mInverted colors:\e[0m
+ \e[34mBlue \e[7;34mInverted\e[7;34m Inverted again\e[0m Reset
+ \e[34mBlue \e[7;34mInverted\e[27;34m Inverted back\e[0m Reset
+ \e[34mBlue \e[1;7;34mInverted and bright\e[7;34m Inverted again\e[0m Reset
+ \e[34mBlue \e[1;7;34mInverted and bright\e[27;34m Inverted back\e[0m Reset
+ \e[1;34mBright blue \e[7;34mInverted\e[7;34m Inverted again\e[0m Reset
+ \e[1;34mBright blue \e[7;34mInverted\e[27;34m Inverted back\e[0m Reset
+
\e[1mOther commands are ignored\e[0m
\e[2mhalf-bright\e[0m
\e[4mset underscore\e[0m
\e[5mset blink\e[0m
- \e[7mset reverse video\e[0m
\e[10mreset selected mapping, display control flag, and toggle\e[0m
\e[11mselect null mapping, set display control flag, reset\e[0m
\e[12mselect null mapping, set display control flag, set toggle\e[0m
\e[21mset underline\e[0m
\e[24munderline off\e[0m
\e[25mblink off\e[0m
- \e[27mreverse video off\e[0m
<span style="color: #008080; background-color: #008080">RGB 0,128,128 on RGB 0,128,128</span>
<span style="color: #c0c000; background-color: #008080">RGB 192,192,0 on RGB 0,128,128</span>
+<span class="g g-AnsiBrightDefault">Inverted colors:</span>
+ <span class="g g-AnsiBlue">Blue </span><span class="g g-AnsiInvertedDefault g-AnsiBackgroundBlue">Inverted Inverted again</span> Reset
+ <span class="g g-AnsiBlue">Blue </span><span class="g g-AnsiInvertedDefault g-AnsiBackgroundBlue">Inverted</span><span class="g g-AnsiBlue"> Inverted back</span> Reset
+ <span class="g g-AnsiBlue">Blue </span><span class="g g-AnsiBrightInvertedDefault g-AnsiBackgroundBlue">Inverted and bright Inverted again</span> Reset
+ <span class="g g-AnsiBlue">Blue </span><span class="g g-AnsiBrightInvertedDefault g-AnsiBackgroundBlue">Inverted and bright</span><span class="g g-AnsiBrightBlue"> Inverted back</span> Reset
+ <span class="g g-AnsiBrightBlue">Bright blue </span><span class="g g-AnsiBrightInvertedDefault g-AnsiBackgroundBlue">Inverted Inverted again</span> Reset
+ <span class="g g-AnsiBrightBlue">Bright blue </span><span class="g g-AnsiBrightInvertedDefault g-AnsiBackgroundBlue">Inverted</span><span class="g g-AnsiBrightBlue"> Inverted back</span> Reset
+
<span class="g g-AnsiBrightDefault">Other commands are ignored</span>
half-bright
set underscore
set blink
- set reverse video
reset selected mapping, display control flag, and toggle
select null mapping, set display control flag, reset
select null mapping, set display control flag, set toggle
set underline
underline off
- blink off
- reverse video off</pre>
+ blink off</pre>
<pre class="m-code">// this language is not highlighted</pre>
<p>Properly preserve backslashes: <code class="m-code"><span class="k">\frac</span><span class="nb">{</span>a<span class="nb">}{</span>b<span class="nb">}</span></code> ... and backticks:
<code class="m-code"><span class="na">:ref:</span><span class="nv">`a function <os.path.join()>`</span></code></p>