Python API¶
Miscellaneous¶
-
class
myst_nb.ansi_lexer.
AnsiColorLexer
(*args, **kwds)[source]¶ Bases:
pygments.lexer.RegexLexer
-
aliases
= ('myst-ansi',)¶ Shortcuts for the lexer
-
property
current_token
¶
-
flags
= 24¶ Flags for compiling the regular expressions. Defaults to MULTILINE.
-
name
= 'ANSI Color'¶ Name of the lexer
-
process
(match)[source]¶ Produce the next token and bit of text.
Interprets the ANSI code (which may be a color code or some other code), changing the lexer state and producing a new token. If it’s not a color code, we just strip it out and move on.
- Some useful reference for ANSI codes:
-
tokens
= {'root': [('\\x1b\\[([^\\x1b]*)', <function AnsiColorLexer.process>), ('[^\\x1b]+', Token.Text)]}¶ Dict of
{'state': [(regex, tokentype, new_state), ...], ...}
The initial state is ‘root’.
new_state
can be omitted to signify no state transition. If it is a string, the state is pushed on the stack and changed. If it is a tuple of strings, all states are pushed on the stack and the current state will be the topmost. It can also becombined('state1', 'state2', ...)
to signify a new, anonymous state combined from the rules of two or more existing ones. Furthermore, it can be ‘#pop’ to signify going back one step in the state stack, or ‘#push’ to push the current state on the stack again.The tuple can also be replaced with
include('state')
, in which case the rules from the state named by the string are included in the current one.
-