7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
11 from pip
._vendor
.pygments
.token
import Token
, STANDARD_TYPES
13 # Default mapping of ansixxx to RGB colors.
16 'ansiblack': '000000',
18 'ansigreen': '007f00',
19 'ansiyellow': '7f7fe0',
21 'ansimagenta': '7f007f',
25 'ansibrightblack': '555555',
26 'ansibrightred': 'ff0000',
27 'ansibrightgreen': '00ff00',
28 'ansibrightyellow': 'ffff00',
29 'ansibrightblue': '0000ff',
30 'ansibrightmagenta': 'ff00ff',
31 'ansibrightcyan': '00ffff',
32 'ansiwhite': 'ffffff',
34 # mapping of deprecated #ansixxx colors to new color names
35 _deprecated_ansicolors
= {
37 '#ansiblack': 'ansiblack',
38 '#ansidarkred': 'ansired',
39 '#ansidarkgreen': 'ansigreen',
40 '#ansibrown': 'ansiyellow',
41 '#ansidarkblue': 'ansiblue',
42 '#ansipurple': 'ansimagenta',
43 '#ansiteal': 'ansicyan',
44 '#ansilightgray': 'ansigray',
46 '#ansidarkgray': 'ansibrightblack',
47 '#ansired': 'ansibrightred',
48 '#ansigreen': 'ansibrightgreen',
49 '#ansiyellow': 'ansibrightyellow',
50 '#ansiblue': 'ansibrightblue',
51 '#ansifuchsia': 'ansibrightmagenta',
52 '#ansiturquoise': 'ansibrightcyan',
53 '#ansiwhite': 'ansiwhite',
55 ansicolors
= set(_ansimap
)
58 class StyleMeta(type):
60 def __new__(mcs
, name
, bases
, dct
):
61 obj
= type.__new
__(mcs
, name
, bases
, dct
)
62 for token
in STANDARD_TYPES
:
63 if token
not in obj
.styles
:
64 obj
.styles
[token
] = ''
66 def colorformat(text
):
67 if text
in ansicolors
:
74 return col
[0] * 2 + col
[1] * 2 + col
[2] * 2
77 elif text
.startswith('var') or text
.startswith('calc'):
79 assert False, "wrong color format %r" % text
81 _styles
= obj
._styles
= {}
83 for ttype
in obj
.styles
:
84 for token
in ttype
.split():
87 ndef
= _styles
.get(token
.parent
, None)
88 styledefs
= obj
.styles
.get(token
, '').split()
89 if not ndef
or token
is None:
90 ndef
= ['', 0, 0, 0, '', '', 0, 0, 0]
91 elif 'noinherit' in styledefs
and token
is not Token
:
92 ndef
= _styles
[Token
][:]
96 for styledef
in obj
.styles
.get(token
, '').split():
97 if styledef
== 'noinherit':
99 elif styledef
== 'bold':
101 elif styledef
== 'nobold':
103 elif styledef
== 'italic':
105 elif styledef
== 'noitalic':
107 elif styledef
== 'underline':
109 elif styledef
== 'nounderline':
111 elif styledef
[:3] == 'bg:':
112 ndef
[4] = colorformat(styledef
[3:])
113 elif styledef
[:7] == 'border:':
114 ndef
[5] = colorformat(styledef
[7:])
115 elif styledef
== 'roman':
117 elif styledef
== 'sans':
119 elif styledef
== 'mono':
122 ndef
[0] = colorformat(styledef
)
126 def style_for_token(cls
, token
):
127 t
= cls
._styles
[token
]
128 ansicolor
= bgansicolor
= None
130 if color
in _deprecated_ansicolors
:
131 color
= _deprecated_ansicolors
[color
]
132 if color
in ansicolors
:
134 color
= _ansimap
[color
]
136 if bgcolor
in _deprecated_ansicolors
:
137 bgcolor
= _deprecated_ansicolors
[bgcolor
]
138 if bgcolor
in ansicolors
:
139 bgansicolor
= bgcolor
140 bgcolor
= _ansimap
[bgcolor
]
143 'color': color
or None,
145 'italic': bool(t
[2]),
146 'underline': bool(t
[3]),
147 'bgcolor': bgcolor
or None,
148 'border': t
[5] or None,
149 'roman': bool(t
[6]) or None,
150 'sans': bool(t
[7]) or None,
151 'mono': bool(t
[8]) or None,
152 'ansicolor': ansicolor
,
153 'bgansicolor': bgansicolor
,
156 def list_styles(cls
):
159 def styles_token(cls
, ttype
):
160 return ttype
in cls
._styles
163 for token
in cls
._styles
:
164 yield token
, cls
.style_for_token(token
)
167 return len(cls
._styles
)
170 class Style(metaclass
=StyleMeta
):
172 #: overall background color (``None`` means transparent)
173 background_color
= '#ffffff'
175 #: highlight background color
176 highlight_color
= '#ffffcc'
178 #: line number font color
179 line_number_color
= 'inherit'
181 #: line number background color
182 line_number_background_color
= 'transparent'
184 #: special line number font color
185 line_number_special_color
= '#000000'
187 #: special line number background color
188 line_number_special_background_color
= '#ffffc0'
190 #: Style definitions for individual token types.
193 # Attribute for lexers defined within Pygments. If set
194 # to True, the style is not shown in the style gallery
195 # on the website. This is intended for language-specific
197 web_style_gallery_exclude
= False