ADAPT-Chase commited on
Commit
88a96d6
·
verified ·
1 Parent(s): c9c1112

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. tool_server/.venv/lib/python3.12/site-packages/_yaml/__pycache__/__init__.cpython-312.pyc +0 -0
  3. tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/__init__.cpython-312.pyc +0 -0
  4. tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/decoders.cpython-312.pyc +0 -0
  5. tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/exceptions.cpython-312.pyc +0 -0
  6. tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/multipart.cpython-312.pyc +0 -0
  7. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/__init__.cpython-312.pyc +0 -0
  8. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/__main__.cpython-312.pyc +0 -0
  9. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/cmdline.cpython-312.pyc +0 -0
  10. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/console.cpython-312.pyc +0 -0
  11. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/filter.cpython-312.pyc +0 -0
  12. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/formatter.cpython-312.pyc +0 -0
  13. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/lexer.cpython-312.pyc +0 -0
  14. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/modeline.cpython-312.pyc +0 -0
  15. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/plugin.cpython-312.pyc +0 -0
  16. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/regexopt.cpython-312.pyc +0 -0
  17. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/scanner.cpython-312.pyc +0 -0
  18. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/sphinxext.cpython-312.pyc +0 -0
  19. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/style.cpython-312.pyc +0 -0
  20. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/token.cpython-312.pyc +0 -0
  21. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/unistring.cpython-312.pyc +0 -0
  22. tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/util.cpython-312.pyc +0 -0
  23. tool_server/.venv/lib/python3.12/site-packages/pygments/filters/__init__.py +940 -0
  24. tool_server/.venv/lib/python3.12/site-packages/pygments/filters/__pycache__/__init__.cpython-312.pyc +0 -0
  25. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__init__.py +157 -0
  26. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/__init__.cpython-312.pyc +0 -0
  27. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/_mapping.cpython-312.pyc +0 -0
  28. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/bbcode.cpython-312.pyc +0 -0
  29. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/groff.cpython-312.pyc +0 -0
  30. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/html.cpython-312.pyc +0 -0
  31. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/img.cpython-312.pyc +0 -0
  32. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/irc.cpython-312.pyc +0 -0
  33. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/latex.cpython-312.pyc +0 -0
  34. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/other.cpython-312.pyc +0 -0
  35. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/pangomarkup.cpython-312.pyc +0 -0
  36. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/rtf.cpython-312.pyc +0 -0
  37. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/svg.cpython-312.pyc +0 -0
  38. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/terminal.cpython-312.pyc +0 -0
  39. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/terminal256.cpython-312.pyc +0 -0
  40. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/_mapping.py +23 -0
  41. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/bbcode.py +108 -0
  42. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/groff.py +170 -0
  43. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/html.py +995 -0
  44. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/img.py +686 -0
  45. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/irc.py +154 -0
  46. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/latex.py +518 -0
  47. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/other.py +160 -0
  48. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/pangomarkup.py +83 -0
  49. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/rtf.py +349 -0
  50. tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/svg.py +185 -0
.gitattributes CHANGED
@@ -4023,3 +4023,5 @@ tool_server/.venv/lib/python3.12/site-packages/setuptools/command/__pycache__/ea
4023
  tool_server/.venv/lib/python3.12/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4024
  tool_server/.venv/lib/python3.12/site-packages/regex/__pycache__/_regex_core.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4025
  tool_server/.venv/lib/python3.12/site-packages/regex/__pycache__/test_regex.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
 
 
 
4023
  tool_server/.venv/lib/python3.12/site-packages/setuptools/config/_validate_pyproject/__pycache__/fastjsonschema_validations.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4024
  tool_server/.venv/lib/python3.12/site-packages/regex/__pycache__/_regex_core.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4025
  tool_server/.venv/lib/python3.12/site-packages/regex/__pycache__/test_regex.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
4026
+ tool_server/.venv/lib/python3.12/site-packages/zmq/backend/cython/_zmq.abi3.so filter=lfs diff=lfs merge=lfs -text
4027
+ tool_server/.venv/lib/python3.12/site-packages/pygments/lexers/__pycache__/lisp.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
tool_server/.venv/lib/python3.12/site-packages/_yaml/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (857 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (1.43 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/decoders.cpython-312.pyc ADDED
Binary file (226 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/exceptions.cpython-312.pyc ADDED
Binary file (230 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/multipart/__pycache__/multipart.cpython-312.pyc ADDED
Binary file (228 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (3.45 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/__main__.cpython-312.pyc ADDED
Binary file (770 Bytes). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/cmdline.cpython-312.pyc ADDED
Binary file (26.5 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/console.cpython-312.pyc ADDED
Binary file (2.62 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/filter.cpython-312.pyc ADDED
Binary file (3.21 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/formatter.cpython-312.pyc ADDED
Binary file (4.68 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/lexer.cpython-312.pyc ADDED
Binary file (38.7 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/modeline.cpython-312.pyc ADDED
Binary file (1.56 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/plugin.cpython-312.pyc ADDED
Binary file (2.62 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/regexopt.cpython-312.pyc ADDED
Binary file (4.07 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/scanner.cpython-312.pyc ADDED
Binary file (4.74 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/sphinxext.cpython-312.pyc ADDED
Binary file (12.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/style.cpython-312.pyc ADDED
Binary file (6.69 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/token.cpython-312.pyc ADDED
Binary file (8.18 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/unistring.cpython-312.pyc ADDED
Binary file (33 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/__pycache__/util.cpython-312.pyc ADDED
Binary file (14.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/filters/__init__.py ADDED
@@ -0,0 +1,940 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.filters
3
+ ~~~~~~~~~~~~~~~~
4
+
5
+ Module containing filter lookup functions and default
6
+ filters.
7
+
8
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import re
13
+
14
+ from pygments.token import String, Comment, Keyword, Name, Error, Whitespace, \
15
+ string_to_tokentype
16
+ from pygments.filter import Filter
17
+ from pygments.util import get_list_opt, get_int_opt, get_bool_opt, \
18
+ get_choice_opt, ClassNotFound, OptionError
19
+ from pygments.plugin import find_plugin_filters
20
+
21
+
22
+ def find_filter_class(filtername):
23
+ """Lookup a filter by name. Return None if not found."""
24
+ if filtername in FILTERS:
25
+ return FILTERS[filtername]
26
+ for name, cls in find_plugin_filters():
27
+ if name == filtername:
28
+ return cls
29
+ return None
30
+
31
+
32
+ def get_filter_by_name(filtername, **options):
33
+ """Return an instantiated filter.
34
+
35
+ Options are passed to the filter initializer if wanted.
36
+ Raise a ClassNotFound if not found.
37
+ """
38
+ cls = find_filter_class(filtername)
39
+ if cls:
40
+ return cls(**options)
41
+ else:
42
+ raise ClassNotFound(f'filter {filtername!r} not found')
43
+
44
+
45
+ def get_all_filters():
46
+ """Return a generator of all filter names."""
47
+ yield from FILTERS
48
+ for name, _ in find_plugin_filters():
49
+ yield name
50
+
51
+
52
+ def _replace_special(ttype, value, regex, specialttype,
53
+ replacefunc=lambda x: x):
54
+ last = 0
55
+ for match in regex.finditer(value):
56
+ start, end = match.start(), match.end()
57
+ if start != last:
58
+ yield ttype, value[last:start]
59
+ yield specialttype, replacefunc(value[start:end])
60
+ last = end
61
+ if last != len(value):
62
+ yield ttype, value[last:]
63
+
64
+
65
+ class CodeTagFilter(Filter):
66
+ """Highlight special code tags in comments and docstrings.
67
+
68
+ Options accepted:
69
+
70
+ `codetags` : list of strings
71
+ A list of strings that are flagged as code tags. The default is to
72
+ highlight ``XXX``, ``TODO``, ``FIXME``, ``BUG`` and ``NOTE``.
73
+
74
+ .. versionchanged:: 2.13
75
+ Now recognizes ``FIXME`` by default.
76
+ """
77
+
78
+ def __init__(self, **options):
79
+ Filter.__init__(self, **options)
80
+ tags = get_list_opt(options, 'codetags',
81
+ ['XXX', 'TODO', 'FIXME', 'BUG', 'NOTE'])
82
+ self.tag_re = re.compile(r'\b({})\b'.format('|'.join([
83
+ re.escape(tag) for tag in tags if tag
84
+ ])))
85
+
86
+ def filter(self, lexer, stream):
87
+ regex = self.tag_re
88
+ for ttype, value in stream:
89
+ if ttype in String.Doc or \
90
+ ttype in Comment and \
91
+ ttype not in Comment.Preproc:
92
+ yield from _replace_special(ttype, value, regex, Comment.Special)
93
+ else:
94
+ yield ttype, value
95
+
96
+
97
+ class SymbolFilter(Filter):
98
+ """Convert mathematical symbols such as \\<longrightarrow> in Isabelle
99
+ or \\longrightarrow in LaTeX into Unicode characters.
100
+
101
+ This is mostly useful for HTML or console output when you want to
102
+ approximate the source rendering you'd see in an IDE.
103
+
104
+ Options accepted:
105
+
106
+ `lang` : string
107
+ The symbol language. Must be one of ``'isabelle'`` or
108
+ ``'latex'``. The default is ``'isabelle'``.
109
+ """
110
+
111
+ latex_symbols = {
112
+ '\\alpha' : '\U000003b1',
113
+ '\\beta' : '\U000003b2',
114
+ '\\gamma' : '\U000003b3',
115
+ '\\delta' : '\U000003b4',
116
+ '\\varepsilon' : '\U000003b5',
117
+ '\\zeta' : '\U000003b6',
118
+ '\\eta' : '\U000003b7',
119
+ '\\vartheta' : '\U000003b8',
120
+ '\\iota' : '\U000003b9',
121
+ '\\kappa' : '\U000003ba',
122
+ '\\lambda' : '\U000003bb',
123
+ '\\mu' : '\U000003bc',
124
+ '\\nu' : '\U000003bd',
125
+ '\\xi' : '\U000003be',
126
+ '\\pi' : '\U000003c0',
127
+ '\\varrho' : '\U000003c1',
128
+ '\\sigma' : '\U000003c3',
129
+ '\\tau' : '\U000003c4',
130
+ '\\upsilon' : '\U000003c5',
131
+ '\\varphi' : '\U000003c6',
132
+ '\\chi' : '\U000003c7',
133
+ '\\psi' : '\U000003c8',
134
+ '\\omega' : '\U000003c9',
135
+ '\\Gamma' : '\U00000393',
136
+ '\\Delta' : '\U00000394',
137
+ '\\Theta' : '\U00000398',
138
+ '\\Lambda' : '\U0000039b',
139
+ '\\Xi' : '\U0000039e',
140
+ '\\Pi' : '\U000003a0',
141
+ '\\Sigma' : '\U000003a3',
142
+ '\\Upsilon' : '\U000003a5',
143
+ '\\Phi' : '\U000003a6',
144
+ '\\Psi' : '\U000003a8',
145
+ '\\Omega' : '\U000003a9',
146
+ '\\leftarrow' : '\U00002190',
147
+ '\\longleftarrow' : '\U000027f5',
148
+ '\\rightarrow' : '\U00002192',
149
+ '\\longrightarrow' : '\U000027f6',
150
+ '\\Leftarrow' : '\U000021d0',
151
+ '\\Longleftarrow' : '\U000027f8',
152
+ '\\Rightarrow' : '\U000021d2',
153
+ '\\Longrightarrow' : '\U000027f9',
154
+ '\\leftrightarrow' : '\U00002194',
155
+ '\\longleftrightarrow' : '\U000027f7',
156
+ '\\Leftrightarrow' : '\U000021d4',
157
+ '\\Longleftrightarrow' : '\U000027fa',
158
+ '\\mapsto' : '\U000021a6',
159
+ '\\longmapsto' : '\U000027fc',
160
+ '\\relbar' : '\U00002500',
161
+ '\\Relbar' : '\U00002550',
162
+ '\\hookleftarrow' : '\U000021a9',
163
+ '\\hookrightarrow' : '\U000021aa',
164
+ '\\leftharpoondown' : '\U000021bd',
165
+ '\\rightharpoondown' : '\U000021c1',
166
+ '\\leftharpoonup' : '\U000021bc',
167
+ '\\rightharpoonup' : '\U000021c0',
168
+ '\\rightleftharpoons' : '\U000021cc',
169
+ '\\leadsto' : '\U0000219d',
170
+ '\\downharpoonleft' : '\U000021c3',
171
+ '\\downharpoonright' : '\U000021c2',
172
+ '\\upharpoonleft' : '\U000021bf',
173
+ '\\upharpoonright' : '\U000021be',
174
+ '\\restriction' : '\U000021be',
175
+ '\\uparrow' : '\U00002191',
176
+ '\\Uparrow' : '\U000021d1',
177
+ '\\downarrow' : '\U00002193',
178
+ '\\Downarrow' : '\U000021d3',
179
+ '\\updownarrow' : '\U00002195',
180
+ '\\Updownarrow' : '\U000021d5',
181
+ '\\langle' : '\U000027e8',
182
+ '\\rangle' : '\U000027e9',
183
+ '\\lceil' : '\U00002308',
184
+ '\\rceil' : '\U00002309',
185
+ '\\lfloor' : '\U0000230a',
186
+ '\\rfloor' : '\U0000230b',
187
+ '\\flqq' : '\U000000ab',
188
+ '\\frqq' : '\U000000bb',
189
+ '\\bot' : '\U000022a5',
190
+ '\\top' : '\U000022a4',
191
+ '\\wedge' : '\U00002227',
192
+ '\\bigwedge' : '\U000022c0',
193
+ '\\vee' : '\U00002228',
194
+ '\\bigvee' : '\U000022c1',
195
+ '\\forall' : '\U00002200',
196
+ '\\exists' : '\U00002203',
197
+ '\\nexists' : '\U00002204',
198
+ '\\neg' : '\U000000ac',
199
+ '\\Box' : '\U000025a1',
200
+ '\\Diamond' : '\U000025c7',
201
+ '\\vdash' : '\U000022a2',
202
+ '\\models' : '\U000022a8',
203
+ '\\dashv' : '\U000022a3',
204
+ '\\surd' : '\U0000221a',
205
+ '\\le' : '\U00002264',
206
+ '\\ge' : '\U00002265',
207
+ '\\ll' : '\U0000226a',
208
+ '\\gg' : '\U0000226b',
209
+ '\\lesssim' : '\U00002272',
210
+ '\\gtrsim' : '\U00002273',
211
+ '\\lessapprox' : '\U00002a85',
212
+ '\\gtrapprox' : '\U00002a86',
213
+ '\\in' : '\U00002208',
214
+ '\\notin' : '\U00002209',
215
+ '\\subset' : '\U00002282',
216
+ '\\supset' : '\U00002283',
217
+ '\\subseteq' : '\U00002286',
218
+ '\\supseteq' : '\U00002287',
219
+ '\\sqsubset' : '\U0000228f',
220
+ '\\sqsupset' : '\U00002290',
221
+ '\\sqsubseteq' : '\U00002291',
222
+ '\\sqsupseteq' : '\U00002292',
223
+ '\\cap' : '\U00002229',
224
+ '\\bigcap' : '\U000022c2',
225
+ '\\cup' : '\U0000222a',
226
+ '\\bigcup' : '\U000022c3',
227
+ '\\sqcup' : '\U00002294',
228
+ '\\bigsqcup' : '\U00002a06',
229
+ '\\sqcap' : '\U00002293',
230
+ '\\Bigsqcap' : '\U00002a05',
231
+ '\\setminus' : '\U00002216',
232
+ '\\propto' : '\U0000221d',
233
+ '\\uplus' : '\U0000228e',
234
+ '\\bigplus' : '\U00002a04',
235
+ '\\sim' : '\U0000223c',
236
+ '\\doteq' : '\U00002250',
237
+ '\\simeq' : '\U00002243',
238
+ '\\approx' : '\U00002248',
239
+ '\\asymp' : '\U0000224d',
240
+ '\\cong' : '\U00002245',
241
+ '\\equiv' : '\U00002261',
242
+ '\\Join' : '\U000022c8',
243
+ '\\bowtie' : '\U00002a1d',
244
+ '\\prec' : '\U0000227a',
245
+ '\\succ' : '\U0000227b',
246
+ '\\preceq' : '\U0000227c',
247
+ '\\succeq' : '\U0000227d',
248
+ '\\parallel' : '\U00002225',
249
+ '\\mid' : '\U000000a6',
250
+ '\\pm' : '\U000000b1',
251
+ '\\mp' : '\U00002213',
252
+ '\\times' : '\U000000d7',
253
+ '\\div' : '\U000000f7',
254
+ '\\cdot' : '\U000022c5',
255
+ '\\star' : '\U000022c6',
256
+ '\\circ' : '\U00002218',
257
+ '\\dagger' : '\U00002020',
258
+ '\\ddagger' : '\U00002021',
259
+ '\\lhd' : '\U000022b2',
260
+ '\\rhd' : '\U000022b3',
261
+ '\\unlhd' : '\U000022b4',
262
+ '\\unrhd' : '\U000022b5',
263
+ '\\triangleleft' : '\U000025c3',
264
+ '\\triangleright' : '\U000025b9',
265
+ '\\triangle' : '\U000025b3',
266
+ '\\triangleq' : '\U0000225c',
267
+ '\\oplus' : '\U00002295',
268
+ '\\bigoplus' : '\U00002a01',
269
+ '\\otimes' : '\U00002297',
270
+ '\\bigotimes' : '\U00002a02',
271
+ '\\odot' : '\U00002299',
272
+ '\\bigodot' : '\U00002a00',
273
+ '\\ominus' : '\U00002296',
274
+ '\\oslash' : '\U00002298',
275
+ '\\dots' : '\U00002026',
276
+ '\\cdots' : '\U000022ef',
277
+ '\\sum' : '\U00002211',
278
+ '\\prod' : '\U0000220f',
279
+ '\\coprod' : '\U00002210',
280
+ '\\infty' : '\U0000221e',
281
+ '\\int' : '\U0000222b',
282
+ '\\oint' : '\U0000222e',
283
+ '\\clubsuit' : '\U00002663',
284
+ '\\diamondsuit' : '\U00002662',
285
+ '\\heartsuit' : '\U00002661',
286
+ '\\spadesuit' : '\U00002660',
287
+ '\\aleph' : '\U00002135',
288
+ '\\emptyset' : '\U00002205',
289
+ '\\nabla' : '\U00002207',
290
+ '\\partial' : '\U00002202',
291
+ '\\flat' : '\U0000266d',
292
+ '\\natural' : '\U0000266e',
293
+ '\\sharp' : '\U0000266f',
294
+ '\\angle' : '\U00002220',
295
+ '\\copyright' : '\U000000a9',
296
+ '\\textregistered' : '\U000000ae',
297
+ '\\textonequarter' : '\U000000bc',
298
+ '\\textonehalf' : '\U000000bd',
299
+ '\\textthreequarters' : '\U000000be',
300
+ '\\textordfeminine' : '\U000000aa',
301
+ '\\textordmasculine' : '\U000000ba',
302
+ '\\euro' : '\U000020ac',
303
+ '\\pounds' : '\U000000a3',
304
+ '\\yen' : '\U000000a5',
305
+ '\\textcent' : '\U000000a2',
306
+ '\\textcurrency' : '\U000000a4',
307
+ '\\textdegree' : '\U000000b0',
308
+ }
309
+
310
+ isabelle_symbols = {
311
+ '\\<zero>' : '\U0001d7ec',
312
+ '\\<one>' : '\U0001d7ed',
313
+ '\\<two>' : '\U0001d7ee',
314
+ '\\<three>' : '\U0001d7ef',
315
+ '\\<four>' : '\U0001d7f0',
316
+ '\\<five>' : '\U0001d7f1',
317
+ '\\<six>' : '\U0001d7f2',
318
+ '\\<seven>' : '\U0001d7f3',
319
+ '\\<eight>' : '\U0001d7f4',
320
+ '\\<nine>' : '\U0001d7f5',
321
+ '\\<A>' : '\U0001d49c',
322
+ '\\<B>' : '\U0000212c',
323
+ '\\<C>' : '\U0001d49e',
324
+ '\\<D>' : '\U0001d49f',
325
+ '\\<E>' : '\U00002130',
326
+ '\\<F>' : '\U00002131',
327
+ '\\<G>' : '\U0001d4a2',
328
+ '\\<H>' : '\U0000210b',
329
+ '\\<I>' : '\U00002110',
330
+ '\\<J>' : '\U0001d4a5',
331
+ '\\<K>' : '\U0001d4a6',
332
+ '\\<L>' : '\U00002112',
333
+ '\\<M>' : '\U00002133',
334
+ '\\<N>' : '\U0001d4a9',
335
+ '\\<O>' : '\U0001d4aa',
336
+ '\\<P>' : '\U0001d4ab',
337
+ '\\<Q>' : '\U0001d4ac',
338
+ '\\<R>' : '\U0000211b',
339
+ '\\<S>' : '\U0001d4ae',
340
+ '\\<T>' : '\U0001d4af',
341
+ '\\<U>' : '\U0001d4b0',
342
+ '\\<V>' : '\U0001d4b1',
343
+ '\\<W>' : '\U0001d4b2',
344
+ '\\<X>' : '\U0001d4b3',
345
+ '\\<Y>' : '\U0001d4b4',
346
+ '\\<Z>' : '\U0001d4b5',
347
+ '\\<a>' : '\U0001d5ba',
348
+ '\\<b>' : '\U0001d5bb',
349
+ '\\<c>' : '\U0001d5bc',
350
+ '\\<d>' : '\U0001d5bd',
351
+ '\\<e>' : '\U0001d5be',
352
+ '\\<f>' : '\U0001d5bf',
353
+ '\\<g>' : '\U0001d5c0',
354
+ '\\<h>' : '\U0001d5c1',
355
+ '\\<i>' : '\U0001d5c2',
356
+ '\\<j>' : '\U0001d5c3',
357
+ '\\<k>' : '\U0001d5c4',
358
+ '\\<l>' : '\U0001d5c5',
359
+ '\\<m>' : '\U0001d5c6',
360
+ '\\<n>' : '\U0001d5c7',
361
+ '\\<o>' : '\U0001d5c8',
362
+ '\\<p>' : '\U0001d5c9',
363
+ '\\<q>' : '\U0001d5ca',
364
+ '\\<r>' : '\U0001d5cb',
365
+ '\\<s>' : '\U0001d5cc',
366
+ '\\<t>' : '\U0001d5cd',
367
+ '\\<u>' : '\U0001d5ce',
368
+ '\\<v>' : '\U0001d5cf',
369
+ '\\<w>' : '\U0001d5d0',
370
+ '\\<x>' : '\U0001d5d1',
371
+ '\\<y>' : '\U0001d5d2',
372
+ '\\<z>' : '\U0001d5d3',
373
+ '\\<AA>' : '\U0001d504',
374
+ '\\<BB>' : '\U0001d505',
375
+ '\\<CC>' : '\U0000212d',
376
+ '\\<DD>' : '\U0001d507',
377
+ '\\<EE>' : '\U0001d508',
378
+ '\\<FF>' : '\U0001d509',
379
+ '\\<GG>' : '\U0001d50a',
380
+ '\\<HH>' : '\U0000210c',
381
+ '\\<II>' : '\U00002111',
382
+ '\\<JJ>' : '\U0001d50d',
383
+ '\\<KK>' : '\U0001d50e',
384
+ '\\<LL>' : '\U0001d50f',
385
+ '\\<MM>' : '\U0001d510',
386
+ '\\<NN>' : '\U0001d511',
387
+ '\\<OO>' : '\U0001d512',
388
+ '\\<PP>' : '\U0001d513',
389
+ '\\<QQ>' : '\U0001d514',
390
+ '\\<RR>' : '\U0000211c',
391
+ '\\<SS>' : '\U0001d516',
392
+ '\\<TT>' : '\U0001d517',
393
+ '\\<UU>' : '\U0001d518',
394
+ '\\<VV>' : '\U0001d519',
395
+ '\\<WW>' : '\U0001d51a',
396
+ '\\<XX>' : '\U0001d51b',
397
+ '\\<YY>' : '\U0001d51c',
398
+ '\\<ZZ>' : '\U00002128',
399
+ '\\<aa>' : '\U0001d51e',
400
+ '\\<bb>' : '\U0001d51f',
401
+ '\\<cc>' : '\U0001d520',
402
+ '\\<dd>' : '\U0001d521',
403
+ '\\<ee>' : '\U0001d522',
404
+ '\\<ff>' : '\U0001d523',
405
+ '\\<gg>' : '\U0001d524',
406
+ '\\<hh>' : '\U0001d525',
407
+ '\\<ii>' : '\U0001d526',
408
+ '\\<jj>' : '\U0001d527',
409
+ '\\<kk>' : '\U0001d528',
410
+ '\\<ll>' : '\U0001d529',
411
+ '\\<mm>' : '\U0001d52a',
412
+ '\\<nn>' : '\U0001d52b',
413
+ '\\<oo>' : '\U0001d52c',
414
+ '\\<pp>' : '\U0001d52d',
415
+ '\\<qq>' : '\U0001d52e',
416
+ '\\<rr>' : '\U0001d52f',
417
+ '\\<ss>' : '\U0001d530',
418
+ '\\<tt>' : '\U0001d531',
419
+ '\\<uu>' : '\U0001d532',
420
+ '\\<vv>' : '\U0001d533',
421
+ '\\<ww>' : '\U0001d534',
422
+ '\\<xx>' : '\U0001d535',
423
+ '\\<yy>' : '\U0001d536',
424
+ '\\<zz>' : '\U0001d537',
425
+ '\\<alpha>' : '\U000003b1',
426
+ '\\<beta>' : '\U000003b2',
427
+ '\\<gamma>' : '\U000003b3',
428
+ '\\<delta>' : '\U000003b4',
429
+ '\\<epsilon>' : '\U000003b5',
430
+ '\\<zeta>' : '\U000003b6',
431
+ '\\<eta>' : '\U000003b7',
432
+ '\\<theta>' : '\U000003b8',
433
+ '\\<iota>' : '\U000003b9',
434
+ '\\<kappa>' : '\U000003ba',
435
+ '\\<lambda>' : '\U000003bb',
436
+ '\\<mu>' : '\U000003bc',
437
+ '\\<nu>' : '\U000003bd',
438
+ '\\<xi>' : '\U000003be',
439
+ '\\<pi>' : '\U000003c0',
440
+ '\\<rho>' : '\U000003c1',
441
+ '\\<sigma>' : '\U000003c3',
442
+ '\\<tau>' : '\U000003c4',
443
+ '\\<upsilon>' : '\U000003c5',
444
+ '\\<phi>' : '\U000003c6',
445
+ '\\<chi>' : '\U000003c7',
446
+ '\\<psi>' : '\U000003c8',
447
+ '\\<omega>' : '\U000003c9',
448
+ '\\<Gamma>' : '\U00000393',
449
+ '\\<Delta>' : '\U00000394',
450
+ '\\<Theta>' : '\U00000398',
451
+ '\\<Lambda>' : '\U0000039b',
452
+ '\\<Xi>' : '\U0000039e',
453
+ '\\<Pi>' : '\U000003a0',
454
+ '\\<Sigma>' : '\U000003a3',
455
+ '\\<Upsilon>' : '\U000003a5',
456
+ '\\<Phi>' : '\U000003a6',
457
+ '\\<Psi>' : '\U000003a8',
458
+ '\\<Omega>' : '\U000003a9',
459
+ '\\<bool>' : '\U0001d539',
460
+ '\\<complex>' : '\U00002102',
461
+ '\\<nat>' : '\U00002115',
462
+ '\\<rat>' : '\U0000211a',
463
+ '\\<real>' : '\U0000211d',
464
+ '\\<int>' : '\U00002124',
465
+ '\\<leftarrow>' : '\U00002190',
466
+ '\\<longleftarrow>' : '\U000027f5',
467
+ '\\<rightarrow>' : '\U00002192',
468
+ '\\<longrightarrow>' : '\U000027f6',
469
+ '\\<Leftarrow>' : '\U000021d0',
470
+ '\\<Longleftarrow>' : '\U000027f8',
471
+ '\\<Rightarrow>' : '\U000021d2',
472
+ '\\<Longrightarrow>' : '\U000027f9',
473
+ '\\<leftrightarrow>' : '\U00002194',
474
+ '\\<longleftrightarrow>' : '\U000027f7',
475
+ '\\<Leftrightarrow>' : '\U000021d4',
476
+ '\\<Longleftrightarrow>' : '\U000027fa',
477
+ '\\<mapsto>' : '\U000021a6',
478
+ '\\<longmapsto>' : '\U000027fc',
479
+ '\\<midarrow>' : '\U00002500',
480
+ '\\<Midarrow>' : '\U00002550',
481
+ '\\<hookleftarrow>' : '\U000021a9',
482
+ '\\<hookrightarrow>' : '\U000021aa',
483
+ '\\<leftharpoondown>' : '\U000021bd',
484
+ '\\<rightharpoondown>' : '\U000021c1',
485
+ '\\<leftharpoonup>' : '\U000021bc',
486
+ '\\<rightharpoonup>' : '\U000021c0',
487
+ '\\<rightleftharpoons>' : '\U000021cc',
488
+ '\\<leadsto>' : '\U0000219d',
489
+ '\\<downharpoonleft>' : '\U000021c3',
490
+ '\\<downharpoonright>' : '\U000021c2',
491
+ '\\<upharpoonleft>' : '\U000021bf',
492
+ '\\<upharpoonright>' : '\U000021be',
493
+ '\\<restriction>' : '\U000021be',
494
+ '\\<Colon>' : '\U00002237',
495
+ '\\<up>' : '\U00002191',
496
+ '\\<Up>' : '\U000021d1',
497
+ '\\<down>' : '\U00002193',
498
+ '\\<Down>' : '\U000021d3',
499
+ '\\<updown>' : '\U00002195',
500
+ '\\<Updown>' : '\U000021d5',
501
+ '\\<langle>' : '\U000027e8',
502
+ '\\<rangle>' : '\U000027e9',
503
+ '\\<lceil>' : '\U00002308',
504
+ '\\<rceil>' : '\U00002309',
505
+ '\\<lfloor>' : '\U0000230a',
506
+ '\\<rfloor>' : '\U0000230b',
507
+ '\\<lparr>' : '\U00002987',
508
+ '\\<rparr>' : '\U00002988',
509
+ '\\<lbrakk>' : '\U000027e6',
510
+ '\\<rbrakk>' : '\U000027e7',
511
+ '\\<lbrace>' : '\U00002983',
512
+ '\\<rbrace>' : '\U00002984',
513
+ '\\<guillemotleft>' : '\U000000ab',
514
+ '\\<guillemotright>' : '\U000000bb',
515
+ '\\<bottom>' : '\U000022a5',
516
+ '\\<top>' : '\U000022a4',
517
+ '\\<and>' : '\U00002227',
518
+ '\\<And>' : '\U000022c0',
519
+ '\\<or>' : '\U00002228',
520
+ '\\<Or>' : '\U000022c1',
521
+ '\\<forall>' : '\U00002200',
522
+ '\\<exists>' : '\U00002203',
523
+ '\\<nexists>' : '\U00002204',
524
+ '\\<not>' : '\U000000ac',
525
+ '\\<box>' : '\U000025a1',
526
+ '\\<diamond>' : '\U000025c7',
527
+ '\\<turnstile>' : '\U000022a2',
528
+ '\\<Turnstile>' : '\U000022a8',
529
+ '\\<tturnstile>' : '\U000022a9',
530
+ '\\<TTurnstile>' : '\U000022ab',
531
+ '\\<stileturn>' : '\U000022a3',
532
+ '\\<surd>' : '\U0000221a',
533
+ '\\<le>' : '\U00002264',
534
+ '\\<ge>' : '\U00002265',
535
+ '\\<lless>' : '\U0000226a',
536
+ '\\<ggreater>' : '\U0000226b',
537
+ '\\<lesssim>' : '\U00002272',
538
+ '\\<greatersim>' : '\U00002273',
539
+ '\\<lessapprox>' : '\U00002a85',
540
+ '\\<greaterapprox>' : '\U00002a86',
541
+ '\\<in>' : '\U00002208',
542
+ '\\<notin>' : '\U00002209',
543
+ '\\<subset>' : '\U00002282',
544
+ '\\<supset>' : '\U00002283',
545
+ '\\<subseteq>' : '\U00002286',
546
+ '\\<supseteq>' : '\U00002287',
547
+ '\\<sqsubset>' : '\U0000228f',
548
+ '\\<sqsupset>' : '\U00002290',
549
+ '\\<sqsubseteq>' : '\U00002291',
550
+ '\\<sqsupseteq>' : '\U00002292',
551
+ '\\<inter>' : '\U00002229',
552
+ '\\<Inter>' : '\U000022c2',
553
+ '\\<union>' : '\U0000222a',
554
+ '\\<Union>' : '\U000022c3',
555
+ '\\<squnion>' : '\U00002294',
556
+ '\\<Squnion>' : '\U00002a06',
557
+ '\\<sqinter>' : '\U00002293',
558
+ '\\<Sqinter>' : '\U00002a05',
559
+ '\\<setminus>' : '\U00002216',
560
+ '\\<propto>' : '\U0000221d',
561
+ '\\<uplus>' : '\U0000228e',
562
+ '\\<Uplus>' : '\U00002a04',
563
+ '\\<noteq>' : '\U00002260',
564
+ '\\<sim>' : '\U0000223c',
565
+ '\\<doteq>' : '\U00002250',
566
+ '\\<simeq>' : '\U00002243',
567
+ '\\<approx>' : '\U00002248',
568
+ '\\<asymp>' : '\U0000224d',
569
+ '\\<cong>' : '\U00002245',
570
+ '\\<smile>' : '\U00002323',
571
+ '\\<equiv>' : '\U00002261',
572
+ '\\<frown>' : '\U00002322',
573
+ '\\<Join>' : '\U000022c8',
574
+ '\\<bowtie>' : '\U00002a1d',
575
+ '\\<prec>' : '\U0000227a',
576
+ '\\<succ>' : '\U0000227b',
577
+ '\\<preceq>' : '\U0000227c',
578
+ '\\<succeq>' : '\U0000227d',
579
+ '\\<parallel>' : '\U00002225',
580
+ '\\<bar>' : '\U000000a6',
581
+ '\\<plusminus>' : '\U000000b1',
582
+ '\\<minusplus>' : '\U00002213',
583
+ '\\<times>' : '\U000000d7',
584
+ '\\<div>' : '\U000000f7',
585
+ '\\<cdot>' : '\U000022c5',
586
+ '\\<star>' : '\U000022c6',
587
+ '\\<bullet>' : '\U00002219',
588
+ '\\<circ>' : '\U00002218',
589
+ '\\<dagger>' : '\U00002020',
590
+ '\\<ddagger>' : '\U00002021',
591
+ '\\<lhd>' : '\U000022b2',
592
+ '\\<rhd>' : '\U000022b3',
593
+ '\\<unlhd>' : '\U000022b4',
594
+ '\\<unrhd>' : '\U000022b5',
595
+ '\\<triangleleft>' : '\U000025c3',
596
+ '\\<triangleright>' : '\U000025b9',
597
+ '\\<triangle>' : '\U000025b3',
598
+ '\\<triangleq>' : '\U0000225c',
599
+ '\\<oplus>' : '\U00002295',
600
+ '\\<Oplus>' : '\U00002a01',
601
+ '\\<otimes>' : '\U00002297',
602
+ '\\<Otimes>' : '\U00002a02',
603
+ '\\<odot>' : '\U00002299',
604
+ '\\<Odot>' : '\U00002a00',
605
+ '\\<ominus>' : '\U00002296',
606
+ '\\<oslash>' : '\U00002298',
607
+ '\\<dots>' : '\U00002026',
608
+ '\\<cdots>' : '\U000022ef',
609
+ '\\<Sum>' : '\U00002211',
610
+ '\\<Prod>' : '\U0000220f',
611
+ '\\<Coprod>' : '\U00002210',
612
+ '\\<infinity>' : '\U0000221e',
613
+ '\\<integral>' : '\U0000222b',
614
+ '\\<ointegral>' : '\U0000222e',
615
+ '\\<clubsuit>' : '\U00002663',
616
+ '\\<diamondsuit>' : '\U00002662',
617
+ '\\<heartsuit>' : '\U00002661',
618
+ '\\<spadesuit>' : '\U00002660',
619
+ '\\<aleph>' : '\U00002135',
620
+ '\\<emptyset>' : '\U00002205',
621
+ '\\<nabla>' : '\U00002207',
622
+ '\\<partial>' : '\U00002202',
623
+ '\\<flat>' : '\U0000266d',
624
+ '\\<natural>' : '\U0000266e',
625
+ '\\<sharp>' : '\U0000266f',
626
+ '\\<angle>' : '\U00002220',
627
+ '\\<copyright>' : '\U000000a9',
628
+ '\\<registered>' : '\U000000ae',
629
+ '\\<hyphen>' : '\U000000ad',
630
+ '\\<inverse>' : '\U000000af',
631
+ '\\<onequarter>' : '\U000000bc',
632
+ '\\<onehalf>' : '\U000000bd',
633
+ '\\<threequarters>' : '\U000000be',
634
+ '\\<ordfeminine>' : '\U000000aa',
635
+ '\\<ordmasculine>' : '\U000000ba',
636
+ '\\<section>' : '\U000000a7',
637
+ '\\<paragraph>' : '\U000000b6',
638
+ '\\<exclamdown>' : '\U000000a1',
639
+ '\\<questiondown>' : '\U000000bf',
640
+ '\\<euro>' : '\U000020ac',
641
+ '\\<pounds>' : '\U000000a3',
642
+ '\\<yen>' : '\U000000a5',
643
+ '\\<cent>' : '\U000000a2',
644
+ '\\<currency>' : '\U000000a4',
645
+ '\\<degree>' : '\U000000b0',
646
+ '\\<amalg>' : '\U00002a3f',
647
+ '\\<mho>' : '\U00002127',
648
+ '\\<lozenge>' : '\U000025ca',
649
+ '\\<wp>' : '\U00002118',
650
+ '\\<wrong>' : '\U00002240',
651
+ '\\<struct>' : '\U000022c4',
652
+ '\\<acute>' : '\U000000b4',
653
+ '\\<index>' : '\U00000131',
654
+ '\\<dieresis>' : '\U000000a8',
655
+ '\\<cedilla>' : '\U000000b8',
656
+ '\\<hungarumlaut>' : '\U000002dd',
657
+ '\\<some>' : '\U000003f5',
658
+ '\\<newline>' : '\U000023ce',
659
+ '\\<open>' : '\U00002039',
660
+ '\\<close>' : '\U0000203a',
661
+ '\\<here>' : '\U00002302',
662
+ '\\<^sub>' : '\U000021e9',
663
+ '\\<^sup>' : '\U000021e7',
664
+ '\\<^bold>' : '\U00002759',
665
+ '\\<^bsub>' : '\U000021d8',
666
+ '\\<^esub>' : '\U000021d9',
667
+ '\\<^bsup>' : '\U000021d7',
668
+ '\\<^esup>' : '\U000021d6',
669
+ }
670
+
671
+ lang_map = {'isabelle' : isabelle_symbols, 'latex' : latex_symbols}
672
+
673
+ def __init__(self, **options):
674
+ Filter.__init__(self, **options)
675
+ lang = get_choice_opt(options, 'lang',
676
+ ['isabelle', 'latex'], 'isabelle')
677
+ self.symbols = self.lang_map[lang]
678
+
679
+ def filter(self, lexer, stream):
680
+ for ttype, value in stream:
681
+ if value in self.symbols:
682
+ yield ttype, self.symbols[value]
683
+ else:
684
+ yield ttype, value
685
+
686
+
687
+ class KeywordCaseFilter(Filter):
688
+ """Convert keywords to lowercase or uppercase or capitalize them, which
689
+ means first letter uppercase, rest lowercase.
690
+
691
+ This can be useful e.g. if you highlight Pascal code and want to adapt the
692
+ code to your styleguide.
693
+
694
+ Options accepted:
695
+
696
+ `case` : string
697
+ The casing to convert keywords to. Must be one of ``'lower'``,
698
+ ``'upper'`` or ``'capitalize'``. The default is ``'lower'``.
699
+ """
700
+
701
+ def __init__(self, **options):
702
+ Filter.__init__(self, **options)
703
+ case = get_choice_opt(options, 'case',
704
+ ['lower', 'upper', 'capitalize'], 'lower')
705
+ self.convert = getattr(str, case)
706
+
707
+ def filter(self, lexer, stream):
708
+ for ttype, value in stream:
709
+ if ttype in Keyword:
710
+ yield ttype, self.convert(value)
711
+ else:
712
+ yield ttype, value
713
+
714
+
715
+ class NameHighlightFilter(Filter):
716
+ """Highlight a normal Name (and Name.*) token with a different token type.
717
+
718
+ Example::
719
+
720
+ filter = NameHighlightFilter(
721
+ names=['foo', 'bar', 'baz'],
722
+ tokentype=Name.Function,
723
+ )
724
+
725
+ This would highlight the names "foo", "bar" and "baz"
726
+ as functions. `Name.Function` is the default token type.
727
+
728
+ Options accepted:
729
+
730
+ `names` : list of strings
731
+ A list of names that should be given the different token type.
732
+ There is no default.
733
+ `tokentype` : TokenType or string
734
+ A token type or a string containing a token type name that is
735
+ used for highlighting the strings in `names`. The default is
736
+ `Name.Function`.
737
+ """
738
+
739
+ def __init__(self, **options):
740
+ Filter.__init__(self, **options)
741
+ self.names = set(get_list_opt(options, 'names', []))
742
+ tokentype = options.get('tokentype')
743
+ if tokentype:
744
+ self.tokentype = string_to_tokentype(tokentype)
745
+ else:
746
+ self.tokentype = Name.Function
747
+
748
+ def filter(self, lexer, stream):
749
+ for ttype, value in stream:
750
+ if ttype in Name and value in self.names:
751
+ yield self.tokentype, value
752
+ else:
753
+ yield ttype, value
754
+
755
+
756
+ class ErrorToken(Exception):
757
+ pass
758
+
759
+
760
+ class RaiseOnErrorTokenFilter(Filter):
761
+ """Raise an exception when the lexer generates an error token.
762
+
763
+ Options accepted:
764
+
765
+ `excclass` : Exception class
766
+ The exception class to raise.
767
+ The default is `pygments.filters.ErrorToken`.
768
+
769
+ .. versionadded:: 0.8
770
+ """
771
+
772
+ def __init__(self, **options):
773
+ Filter.__init__(self, **options)
774
+ self.exception = options.get('excclass', ErrorToken)
775
+ try:
776
+ # issubclass() will raise TypeError if first argument is not a class
777
+ if not issubclass(self.exception, Exception):
778
+ raise TypeError
779
+ except TypeError:
780
+ raise OptionError('excclass option is not an exception class')
781
+
782
+ def filter(self, lexer, stream):
783
+ for ttype, value in stream:
784
+ if ttype is Error:
785
+ raise self.exception(value)
786
+ yield ttype, value
787
+
788
+
789
+ class VisibleWhitespaceFilter(Filter):
790
+ """Convert tabs, newlines and/or spaces to visible characters.
791
+
792
+ Options accepted:
793
+
794
+ `spaces` : string or bool
795
+ If this is a one-character string, spaces will be replaces by this string.
796
+ If it is another true value, spaces will be replaced by ``·`` (unicode
797
+ MIDDLE DOT). If it is a false value, spaces will not be replaced. The
798
+ default is ``False``.
799
+ `tabs` : string or bool
800
+ The same as for `spaces`, but the default replacement character is ``»``
801
+ (unicode RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK). The default value
802
+ is ``False``. Note: this will not work if the `tabsize` option for the
803
+ lexer is nonzero, as tabs will already have been expanded then.
804
+ `tabsize` : int
805
+ If tabs are to be replaced by this filter (see the `tabs` option), this
806
+ is the total number of characters that a tab should be expanded to.
807
+ The default is ``8``.
808
+ `newlines` : string or bool
809
+ The same as for `spaces`, but the default replacement character is ``¶``
810
+ (unicode PILCROW SIGN). The default value is ``False``.
811
+ `wstokentype` : bool
812
+ If true, give whitespace the special `Whitespace` token type. This allows
813
+ styling the visible whitespace differently (e.g. greyed out), but it can
814
+ disrupt background colors. The default is ``True``.
815
+
816
+ .. versionadded:: 0.8
817
+ """
818
+
819
+ def __init__(self, **options):
820
+ Filter.__init__(self, **options)
821
+ for name, default in [('spaces', '·'),
822
+ ('tabs', '»'),
823
+ ('newlines', '¶')]:
824
+ opt = options.get(name, False)
825
+ if isinstance(opt, str) and len(opt) == 1:
826
+ setattr(self, name, opt)
827
+ else:
828
+ setattr(self, name, (opt and default or ''))
829
+ tabsize = get_int_opt(options, 'tabsize', 8)
830
+ if self.tabs:
831
+ self.tabs += ' ' * (tabsize - 1)
832
+ if self.newlines:
833
+ self.newlines += '\n'
834
+ self.wstt = get_bool_opt(options, 'wstokentype', True)
835
+
836
+ def filter(self, lexer, stream):
837
+ if self.wstt:
838
+ spaces = self.spaces or ' '
839
+ tabs = self.tabs or '\t'
840
+ newlines = self.newlines or '\n'
841
+ regex = re.compile(r'\s')
842
+
843
+ def replacefunc(wschar):
844
+ if wschar == ' ':
845
+ return spaces
846
+ elif wschar == '\t':
847
+ return tabs
848
+ elif wschar == '\n':
849
+ return newlines
850
+ return wschar
851
+
852
+ for ttype, value in stream:
853
+ yield from _replace_special(ttype, value, regex, Whitespace,
854
+ replacefunc)
855
+ else:
856
+ spaces, tabs, newlines = self.spaces, self.tabs, self.newlines
857
+ # simpler processing
858
+ for ttype, value in stream:
859
+ if spaces:
860
+ value = value.replace(' ', spaces)
861
+ if tabs:
862
+ value = value.replace('\t', tabs)
863
+ if newlines:
864
+ value = value.replace('\n', newlines)
865
+ yield ttype, value
866
+
867
+
868
+ class GobbleFilter(Filter):
869
+ """Gobbles source code lines (eats initial characters).
870
+
871
+ This filter drops the first ``n`` characters off every line of code. This
872
+ may be useful when the source code fed to the lexer is indented by a fixed
873
+ amount of space that isn't desired in the output.
874
+
875
+ Options accepted:
876
+
877
+ `n` : int
878
+ The number of characters to gobble.
879
+
880
+ .. versionadded:: 1.2
881
+ """
882
+ def __init__(self, **options):
883
+ Filter.__init__(self, **options)
884
+ self.n = get_int_opt(options, 'n', 0)
885
+
886
+ def gobble(self, value, left):
887
+ if left < len(value):
888
+ return value[left:], 0
889
+ else:
890
+ return '', left - len(value)
891
+
892
+ def filter(self, lexer, stream):
893
+ n = self.n
894
+ left = n # How many characters left to gobble.
895
+ for ttype, value in stream:
896
+ # Remove ``left`` tokens from first line, ``n`` from all others.
897
+ parts = value.split('\n')
898
+ (parts[0], left) = self.gobble(parts[0], left)
899
+ for i in range(1, len(parts)):
900
+ (parts[i], left) = self.gobble(parts[i], n)
901
+ value = '\n'.join(parts)
902
+
903
+ if value != '':
904
+ yield ttype, value
905
+
906
+
907
+ class TokenMergeFilter(Filter):
908
+ """Merges consecutive tokens with the same token type in the output
909
+ stream of a lexer.
910
+
911
+ .. versionadded:: 1.2
912
+ """
913
+ def __init__(self, **options):
914
+ Filter.__init__(self, **options)
915
+
916
+ def filter(self, lexer, stream):
917
+ current_type = None
918
+ current_value = None
919
+ for ttype, value in stream:
920
+ if ttype is current_type:
921
+ current_value += value
922
+ else:
923
+ if current_type is not None:
924
+ yield current_type, current_value
925
+ current_type = ttype
926
+ current_value = value
927
+ if current_type is not None:
928
+ yield current_type, current_value
929
+
930
+
931
+ FILTERS = {
932
+ 'codetagify': CodeTagFilter,
933
+ 'keywordcase': KeywordCaseFilter,
934
+ 'highlight': NameHighlightFilter,
935
+ 'raiseonerror': RaiseOnErrorTokenFilter,
936
+ 'whitespace': VisibleWhitespaceFilter,
937
+ 'gobble': GobbleFilter,
938
+ 'tokenmerge': TokenMergeFilter,
939
+ 'symbols': SymbolFilter,
940
+ }
tool_server/.venv/lib/python3.12/site-packages/pygments/filters/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (37.9 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__init__.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters
3
+ ~~~~~~~~~~~~~~~~~~~
4
+
5
+ Pygments formatters.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ import re
12
+ import sys
13
+ import types
14
+ import fnmatch
15
+ from os.path import basename
16
+
17
+ from pygments.formatters._mapping import FORMATTERS
18
+ from pygments.plugin import find_plugin_formatters
19
+ from pygments.util import ClassNotFound
20
+
21
+ __all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
22
+ 'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS)
23
+
24
+ _formatter_cache = {} # classes by name
25
+ _pattern_cache = {}
26
+
27
+
28
+ def _fn_matches(fn, glob):
29
+ """Return whether the supplied file name fn matches pattern filename."""
30
+ if glob not in _pattern_cache:
31
+ pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
32
+ return pattern.match(fn)
33
+ return _pattern_cache[glob].match(fn)
34
+
35
+
36
+ def _load_formatters(module_name):
37
+ """Load a formatter (and all others in the module too)."""
38
+ mod = __import__(module_name, None, None, ['__all__'])
39
+ for formatter_name in mod.__all__:
40
+ cls = getattr(mod, formatter_name)
41
+ _formatter_cache[cls.name] = cls
42
+
43
+
44
+ def get_all_formatters():
45
+ """Return a generator for all formatter classes."""
46
+ # NB: this returns formatter classes, not info like get_all_lexers().
47
+ for info in FORMATTERS.values():
48
+ if info[1] not in _formatter_cache:
49
+ _load_formatters(info[0])
50
+ yield _formatter_cache[info[1]]
51
+ for _, formatter in find_plugin_formatters():
52
+ yield formatter
53
+
54
+
55
+ def find_formatter_class(alias):
56
+ """Lookup a formatter by alias.
57
+
58
+ Returns None if not found.
59
+ """
60
+ for module_name, name, aliases, _, _ in FORMATTERS.values():
61
+ if alias in aliases:
62
+ if name not in _formatter_cache:
63
+ _load_formatters(module_name)
64
+ return _formatter_cache[name]
65
+ for _, cls in find_plugin_formatters():
66
+ if alias in cls.aliases:
67
+ return cls
68
+
69
+
70
+ def get_formatter_by_name(_alias, **options):
71
+ """
72
+ Return an instance of a :class:`.Formatter` subclass that has `alias` in its
73
+ aliases list. The formatter is given the `options` at its instantiation.
74
+
75
+ Will raise :exc:`pygments.util.ClassNotFound` if no formatter with that
76
+ alias is found.
77
+ """
78
+ cls = find_formatter_class(_alias)
79
+ if cls is None:
80
+ raise ClassNotFound(f"no formatter found for name {_alias!r}")
81
+ return cls(**options)
82
+
83
+
84
+ def load_formatter_from_file(filename, formattername="CustomFormatter", **options):
85
+ """
86
+ Return a `Formatter` subclass instance loaded from the provided file, relative
87
+ to the current directory.
88
+
89
+ The file is expected to contain a Formatter class named ``formattername``
90
+ (by default, CustomFormatter). Users should be very careful with the input, because
91
+ this method is equivalent to running ``eval()`` on the input file. The formatter is
92
+ given the `options` at its instantiation.
93
+
94
+ :exc:`pygments.util.ClassNotFound` is raised if there are any errors loading
95
+ the formatter.
96
+
97
+ .. versionadded:: 2.2
98
+ """
99
+ try:
100
+ # This empty dict will contain the namespace for the exec'd file
101
+ custom_namespace = {}
102
+ with open(filename, 'rb') as f:
103
+ exec(f.read(), custom_namespace)
104
+ # Retrieve the class `formattername` from that namespace
105
+ if formattername not in custom_namespace:
106
+ raise ClassNotFound(f'no valid {formattername} class found in {filename}')
107
+ formatter_class = custom_namespace[formattername]
108
+ # And finally instantiate it with the options
109
+ return formatter_class(**options)
110
+ except OSError as err:
111
+ raise ClassNotFound(f'cannot read {filename}: {err}')
112
+ except ClassNotFound:
113
+ raise
114
+ except Exception as err:
115
+ raise ClassNotFound(f'error when loading custom formatter: {err}')
116
+
117
+
118
+ def get_formatter_for_filename(fn, **options):
119
+ """
120
+ Return a :class:`.Formatter` subclass instance that has a filename pattern
121
+ matching `fn`. The formatter is given the `options` at its instantiation.
122
+
123
+ Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename
124
+ is found.
125
+ """
126
+ fn = basename(fn)
127
+ for modname, name, _, filenames, _ in FORMATTERS.values():
128
+ for filename in filenames:
129
+ if _fn_matches(fn, filename):
130
+ if name not in _formatter_cache:
131
+ _load_formatters(modname)
132
+ return _formatter_cache[name](**options)
133
+ for _name, cls in find_plugin_formatters():
134
+ for filename in cls.filenames:
135
+ if _fn_matches(fn, filename):
136
+ return cls(**options)
137
+ raise ClassNotFound(f"no formatter found for file name {fn!r}")
138
+
139
+
140
+ class _automodule(types.ModuleType):
141
+ """Automatically import formatters."""
142
+
143
+ def __getattr__(self, name):
144
+ info = FORMATTERS.get(name)
145
+ if info:
146
+ _load_formatters(info[0])
147
+ cls = _formatter_cache[info[1]]
148
+ setattr(self, name, cls)
149
+ return cls
150
+ raise AttributeError(name)
151
+
152
+
153
+ oldmod = sys.modules[__name__]
154
+ newmod = _automodule(__name__)
155
+ newmod.__dict__.update(oldmod.__dict__)
156
+ sys.modules[__name__] = newmod
157
+ del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (6.9 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/_mapping.cpython-312.pyc ADDED
Binary file (4.2 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/bbcode.cpython-312.pyc ADDED
Binary file (4.2 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/groff.cpython-312.pyc ADDED
Binary file (7.3 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/html.cpython-312.pyc ADDED
Binary file (41.4 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/img.cpython-312.pyc ADDED
Binary file (28.7 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/irc.cpython-312.pyc ADDED
Binary file (6.02 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/latex.cpython-312.pyc ADDED
Binary file (20.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/other.cpython-312.pyc ADDED
Binary file (6.84 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/pangomarkup.cpython-312.pyc ADDED
Binary file (2.94 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/rtf.cpython-312.pyc ADDED
Binary file (13.8 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/svg.cpython-312.pyc ADDED
Binary file (9.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/terminal.cpython-312.pyc ADDED
Binary file (5.77 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/__pycache__/terminal256.cpython-312.pyc ADDED
Binary file (15.1 kB). View file
 
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/_mapping.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Automatically generated by scripts/gen_mapfiles.py.
2
+ # DO NOT EDIT BY HAND; run `tox -e mapfiles` instead.
3
+
4
+ FORMATTERS = {
5
+ 'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'),
6
+ 'BmpImageFormatter': ('pygments.formatters.img', 'img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
7
+ 'GifImageFormatter': ('pygments.formatters.img', 'img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
8
+ 'GroffFormatter': ('pygments.formatters.groff', 'groff', ('groff', 'troff', 'roff'), (), 'Format tokens with groff escapes to change their color and font style.'),
9
+ 'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ``<span>`` tags. By default, the content is enclosed in a ``<pre>`` tag, itself wrapped in a ``<div>`` tag (but see the `nowrap` option). The ``<div>``'s CSS class can be set by the `cssclass` option."),
10
+ 'IRCFormatter': ('pygments.formatters.irc', 'IRC', ('irc', 'IRC'), (), 'Format tokens with IRC color sequences'),
11
+ 'ImageFormatter': ('pygments.formatters.img', 'img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
12
+ 'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'),
13
+ 'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'),
14
+ 'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'),
15
+ 'PangoMarkupFormatter': ('pygments.formatters.pangomarkup', 'Pango Markup', ('pango', 'pangomarkup'), (), 'Format tokens as Pango Markup code. It can then be rendered to an SVG.'),
16
+ 'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'),
17
+ 'RtfFormatter': ('pygments.formatters.rtf', 'RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.'),
18
+ 'SvgFormatter': ('pygments.formatters.svg', 'SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'),
19
+ 'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
20
+ 'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'),
21
+ 'TerminalTrueColorFormatter': ('pygments.formatters.terminal256', 'TerminalTrueColor', ('terminal16m', 'console16m', '16m'), (), 'Format tokens with ANSI color sequences, for output in a true-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
22
+ 'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.'),
23
+ }
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/bbcode.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.bbcode
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ BBcode formatter.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+
12
+ from pygments.formatter import Formatter
13
+ from pygments.util import get_bool_opt
14
+
15
+ __all__ = ['BBCodeFormatter']
16
+
17
+
18
+ class BBCodeFormatter(Formatter):
19
+ """
20
+ Format tokens with BBcodes. These formatting codes are used by many
21
+ bulletin boards, so you can highlight your sourcecode with pygments before
22
+ posting it there.
23
+
24
+ This formatter has no support for background colors and borders, as there
25
+ are no common BBcode tags for that.
26
+
27
+ Some board systems (e.g. phpBB) don't support colors in their [code] tag,
28
+ so you can't use the highlighting together with that tag.
29
+ Text in a [code] tag usually is shown with a monospace font (which this
30
+ formatter can do with the ``monofont`` option) and no spaces (which you
31
+ need for indentation) are removed.
32
+
33
+ Additional options accepted:
34
+
35
+ `style`
36
+ The style to use, can be a string or a Style subclass (default:
37
+ ``'default'``).
38
+
39
+ `codetag`
40
+ If set to true, put the output into ``[code]`` tags (default:
41
+ ``false``)
42
+
43
+ `monofont`
44
+ If set to true, add a tag to show the code with a monospace font
45
+ (default: ``false``).
46
+ """
47
+ name = 'BBCode'
48
+ aliases = ['bbcode', 'bb']
49
+ filenames = []
50
+
51
+ def __init__(self, **options):
52
+ Formatter.__init__(self, **options)
53
+ self._code = get_bool_opt(options, 'codetag', False)
54
+ self._mono = get_bool_opt(options, 'monofont', False)
55
+
56
+ self.styles = {}
57
+ self._make_styles()
58
+
59
+ def _make_styles(self):
60
+ for ttype, ndef in self.style:
61
+ start = end = ''
62
+ if ndef['color']:
63
+ start += '[color=#{}]'.format(ndef['color'])
64
+ end = '[/color]' + end
65
+ if ndef['bold']:
66
+ start += '[b]'
67
+ end = '[/b]' + end
68
+ if ndef['italic']:
69
+ start += '[i]'
70
+ end = '[/i]' + end
71
+ if ndef['underline']:
72
+ start += '[u]'
73
+ end = '[/u]' + end
74
+ # there are no common BBcodes for background-color and border
75
+
76
+ self.styles[ttype] = start, end
77
+
78
+ def format_unencoded(self, tokensource, outfile):
79
+ if self._code:
80
+ outfile.write('[code]')
81
+ if self._mono:
82
+ outfile.write('[font=monospace]')
83
+
84
+ lastval = ''
85
+ lasttype = None
86
+
87
+ for ttype, value in tokensource:
88
+ while ttype not in self.styles:
89
+ ttype = ttype.parent
90
+ if ttype == lasttype:
91
+ lastval += value
92
+ else:
93
+ if lastval:
94
+ start, end = self.styles[lasttype]
95
+ outfile.write(''.join((start, lastval, end)))
96
+ lastval = value
97
+ lasttype = ttype
98
+
99
+ if lastval:
100
+ start, end = self.styles[lasttype]
101
+ outfile.write(''.join((start, lastval, end)))
102
+
103
+ if self._mono:
104
+ outfile.write('[/font]')
105
+ if self._code:
106
+ outfile.write('[/code]')
107
+ if self._code or self._mono:
108
+ outfile.write('\n')
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/groff.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.groff
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Formatter for groff output.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ import math
12
+ from pygments.formatter import Formatter
13
+ from pygments.util import get_bool_opt, get_int_opt
14
+
15
+ __all__ = ['GroffFormatter']
16
+
17
+
18
+ class GroffFormatter(Formatter):
19
+ """
20
+ Format tokens with groff escapes to change their color and font style.
21
+
22
+ .. versionadded:: 2.11
23
+
24
+ Additional options accepted:
25
+
26
+ `style`
27
+ The style to use, can be a string or a Style subclass (default:
28
+ ``'default'``).
29
+
30
+ `monospaced`
31
+ If set to true, monospace font will be used (default: ``true``).
32
+
33
+ `linenos`
34
+ If set to true, print the line numbers (default: ``false``).
35
+
36
+ `wrap`
37
+ Wrap lines to the specified number of characters. Disabled if set to 0
38
+ (default: ``0``).
39
+ """
40
+
41
+ name = 'groff'
42
+ aliases = ['groff','troff','roff']
43
+ filenames = []
44
+
45
+ def __init__(self, **options):
46
+ Formatter.__init__(self, **options)
47
+
48
+ self.monospaced = get_bool_opt(options, 'monospaced', True)
49
+ self.linenos = get_bool_opt(options, 'linenos', False)
50
+ self._lineno = 0
51
+ self.wrap = get_int_opt(options, 'wrap', 0)
52
+ self._linelen = 0
53
+
54
+ self.styles = {}
55
+ self._make_styles()
56
+
57
+
58
+ def _make_styles(self):
59
+ regular = '\\f[CR]' if self.monospaced else '\\f[R]'
60
+ bold = '\\f[CB]' if self.monospaced else '\\f[B]'
61
+ italic = '\\f[CI]' if self.monospaced else '\\f[I]'
62
+
63
+ for ttype, ndef in self.style:
64
+ start = end = ''
65
+ if ndef['color']:
66
+ start += '\\m[{}]'.format(ndef['color'])
67
+ end = '\\m[]' + end
68
+ if ndef['bold']:
69
+ start += bold
70
+ end = regular + end
71
+ if ndef['italic']:
72
+ start += italic
73
+ end = regular + end
74
+ if ndef['bgcolor']:
75
+ start += '\\M[{}]'.format(ndef['bgcolor'])
76
+ end = '\\M[]' + end
77
+
78
+ self.styles[ttype] = start, end
79
+
80
+
81
+ def _define_colors(self, outfile):
82
+ colors = set()
83
+ for _, ndef in self.style:
84
+ if ndef['color'] is not None:
85
+ colors.add(ndef['color'])
86
+
87
+ for color in sorted(colors):
88
+ outfile.write('.defcolor ' + color + ' rgb #' + color + '\n')
89
+
90
+
91
+ def _write_lineno(self, outfile):
92
+ self._lineno += 1
93
+ outfile.write("%s% 4d " % (self._lineno != 1 and '\n' or '', self._lineno))
94
+
95
+
96
+ def _wrap_line(self, line):
97
+ length = len(line.rstrip('\n'))
98
+ space = ' ' if self.linenos else ''
99
+ newline = ''
100
+
101
+ if length > self.wrap:
102
+ for i in range(0, math.floor(length / self.wrap)):
103
+ chunk = line[i*self.wrap:i*self.wrap+self.wrap]
104
+ newline += (chunk + '\n' + space)
105
+ remainder = length % self.wrap
106
+ if remainder > 0:
107
+ newline += line[-remainder-1:]
108
+ self._linelen = remainder
109
+ elif self._linelen + length > self.wrap:
110
+ newline = ('\n' + space) + line
111
+ self._linelen = length
112
+ else:
113
+ newline = line
114
+ self._linelen += length
115
+
116
+ return newline
117
+
118
+
119
+ def _escape_chars(self, text):
120
+ text = text.replace('\\', '\\[u005C]'). \
121
+ replace('.', '\\[char46]'). \
122
+ replace('\'', '\\[u0027]'). \
123
+ replace('`', '\\[u0060]'). \
124
+ replace('~', '\\[u007E]')
125
+ copy = text
126
+
127
+ for char in copy:
128
+ if len(char) != len(char.encode()):
129
+ uni = char.encode('unicode_escape') \
130
+ .decode()[1:] \
131
+ .replace('x', 'u00') \
132
+ .upper()
133
+ text = text.replace(char, '\\[u' + uni[1:] + ']')
134
+
135
+ return text
136
+
137
+
138
+ def format_unencoded(self, tokensource, outfile):
139
+ self._define_colors(outfile)
140
+
141
+ outfile.write('.nf\n\\f[CR]\n')
142
+
143
+ if self.linenos:
144
+ self._write_lineno(outfile)
145
+
146
+ for ttype, value in tokensource:
147
+ while ttype not in self.styles:
148
+ ttype = ttype.parent
149
+ start, end = self.styles[ttype]
150
+
151
+ for line in value.splitlines(True):
152
+ if self.wrap > 0:
153
+ line = self._wrap_line(line)
154
+
155
+ if start and end:
156
+ text = self._escape_chars(line.rstrip('\n'))
157
+ if text != '':
158
+ outfile.write(''.join((start, text, end)))
159
+ else:
160
+ outfile.write(self._escape_chars(line.rstrip('\n')))
161
+
162
+ if line.endswith('\n'):
163
+ if self.linenos:
164
+ self._write_lineno(outfile)
165
+ self._linelen = 0
166
+ else:
167
+ outfile.write('\n')
168
+ self._linelen = 0
169
+
170
+ outfile.write('\n.fi')
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/html.py ADDED
@@ -0,0 +1,995 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.html
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Formatter for HTML output.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ import functools
12
+ import os
13
+ import sys
14
+ import os.path
15
+ from io import StringIO
16
+
17
+ from pygments.formatter import Formatter
18
+ from pygments.token import Token, Text, STANDARD_TYPES
19
+ from pygments.util import get_bool_opt, get_int_opt, get_list_opt
20
+
21
+ try:
22
+ import ctags
23
+ except ImportError:
24
+ ctags = None
25
+
26
+ __all__ = ['HtmlFormatter']
27
+
28
+
29
+ _escape_html_table = {
30
+ ord('&'): '&amp;',
31
+ ord('<'): '&lt;',
32
+ ord('>'): '&gt;',
33
+ ord('"'): '&quot;',
34
+ ord("'"): '&#39;',
35
+ }
36
+
37
+
38
+ def escape_html(text, table=_escape_html_table):
39
+ """Escape &, <, > as well as single and double quotes for HTML."""
40
+ return text.translate(table)
41
+
42
+
43
+ def webify(color):
44
+ if color.startswith('calc') or color.startswith('var'):
45
+ return color
46
+ else:
47
+ # Check if the color can be shortened from 6 to 3 characters
48
+ color = color.upper()
49
+ if (len(color) == 6 and
50
+ ( color[0] == color[1]
51
+ and color[2] == color[3]
52
+ and color[4] == color[5])):
53
+ return f'#{color[0]}{color[2]}{color[4]}'
54
+ else:
55
+ return f'#{color}'
56
+
57
+
58
+ def _get_ttype_class(ttype):
59
+ fname = STANDARD_TYPES.get(ttype)
60
+ if fname:
61
+ return fname
62
+ aname = ''
63
+ while fname is None:
64
+ aname = '-' + ttype[-1] + aname
65
+ ttype = ttype.parent
66
+ fname = STANDARD_TYPES.get(ttype)
67
+ return fname + aname
68
+
69
+
70
+ CSSFILE_TEMPLATE = '''\
71
+ /*
72
+ generated by Pygments <https://pygments.org/>
73
+ Copyright 2006-2025 by the Pygments team.
74
+ Licensed under the BSD license, see LICENSE for details.
75
+ */
76
+ %(styledefs)s
77
+ '''
78
+
79
+ DOC_HEADER = '''\
80
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
81
+ "http://www.w3.org/TR/html4/strict.dtd">
82
+ <!--
83
+ generated by Pygments <https://pygments.org/>
84
+ Copyright 2006-2025 by the Pygments team.
85
+ Licensed under the BSD license, see LICENSE for details.
86
+ -->
87
+ <html>
88
+ <head>
89
+ <title>%(title)s</title>
90
+ <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
91
+ <style type="text/css">
92
+ ''' + CSSFILE_TEMPLATE + '''
93
+ </style>
94
+ </head>
95
+ <body>
96
+ <h2>%(title)s</h2>
97
+
98
+ '''
99
+
100
+ DOC_HEADER_EXTERNALCSS = '''\
101
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
102
+ "http://www.w3.org/TR/html4/strict.dtd">
103
+
104
+ <html>
105
+ <head>
106
+ <title>%(title)s</title>
107
+ <meta http-equiv="content-type" content="text/html; charset=%(encoding)s">
108
+ <link rel="stylesheet" href="%(cssfile)s" type="text/css">
109
+ </head>
110
+ <body>
111
+ <h2>%(title)s</h2>
112
+
113
+ '''
114
+
115
+ DOC_FOOTER = '''\
116
+ </body>
117
+ </html>
118
+ '''
119
+
120
+
121
+ class HtmlFormatter(Formatter):
122
+ r"""
123
+ Format tokens as HTML 4 ``<span>`` tags. By default, the content is enclosed
124
+ in a ``<pre>`` tag, itself wrapped in a ``<div>`` tag (but see the `nowrap` option).
125
+ The ``<div>``'s CSS class can be set by the `cssclass` option.
126
+
127
+ If the `linenos` option is set to ``"table"``, the ``<pre>`` is
128
+ additionally wrapped inside a ``<table>`` which has one row and two
129
+ cells: one containing the line numbers and one containing the code.
130
+ Example:
131
+
132
+ .. sourcecode:: html
133
+
134
+ <div class="highlight" >
135
+ <table><tr>
136
+ <td class="linenos" title="click to toggle"
137
+ onclick="with (this.firstChild.style)
138
+ { display = (display == '') ? 'none' : '' }">
139
+ <pre>1
140
+ 2</pre>
141
+ </td>
142
+ <td class="code">
143
+ <pre><span class="Ke">def </span><span class="NaFu">foo</span>(bar):
144
+ <span class="Ke">pass</span>
145
+ </pre>
146
+ </td>
147
+ </tr></table></div>
148
+
149
+ (whitespace added to improve clarity).
150
+
151
+ A list of lines can be specified using the `hl_lines` option to make these
152
+ lines highlighted (as of Pygments 0.11).
153
+
154
+ With the `full` option, a complete HTML 4 document is output, including
155
+ the style definitions inside a ``<style>`` tag, or in a separate file if
156
+ the `cssfile` option is given.
157
+
158
+ When `tagsfile` is set to the path of a ctags index file, it is used to
159
+ generate hyperlinks from names to their definition. You must enable
160
+ `lineanchors` and run ctags with the `-n` option for this to work. The
161
+ `python-ctags` module from PyPI must be installed to use this feature;
162
+ otherwise a `RuntimeError` will be raised.
163
+
164
+ The `get_style_defs(arg='')` method of a `HtmlFormatter` returns a string
165
+ containing CSS rules for the CSS classes used by the formatter. The
166
+ argument `arg` can be used to specify additional CSS selectors that
167
+ are prepended to the classes. A call `fmter.get_style_defs('td .code')`
168
+ would result in the following CSS classes:
169
+
170
+ .. sourcecode:: css
171
+
172
+ td .code .kw { font-weight: bold; color: #00FF00 }
173
+ td .code .cm { color: #999999 }
174
+ ...
175
+
176
+ If you have Pygments 0.6 or higher, you can also pass a list or tuple to the
177
+ `get_style_defs()` method to request multiple prefixes for the tokens:
178
+
179
+ .. sourcecode:: python
180
+
181
+ formatter.get_style_defs(['div.syntax pre', 'pre.syntax'])
182
+
183
+ The output would then look like this:
184
+
185
+ .. sourcecode:: css
186
+
187
+ div.syntax pre .kw,
188
+ pre.syntax .kw { font-weight: bold; color: #00FF00 }
189
+ div.syntax pre .cm,
190
+ pre.syntax .cm { color: #999999 }
191
+ ...
192
+
193
+ Additional options accepted:
194
+
195
+ `nowrap`
196
+ If set to ``True``, don't add a ``<pre>`` and a ``<div>`` tag
197
+ around the tokens. This disables most other options (default: ``False``).
198
+
199
+ `full`
200
+ Tells the formatter to output a "full" document, i.e. a complete
201
+ self-contained document (default: ``False``).
202
+
203
+ `title`
204
+ If `full` is true, the title that should be used to caption the
205
+ document (default: ``''``).
206
+
207
+ `style`
208
+ The style to use, can be a string or a Style subclass (default:
209
+ ``'default'``). This option has no effect if the `cssfile`
210
+ and `noclobber_cssfile` option are given and the file specified in
211
+ `cssfile` exists.
212
+
213
+ `noclasses`
214
+ If set to true, token ``<span>`` tags (as well as line number elements)
215
+ will not use CSS classes, but inline styles. This is not recommended
216
+ for larger pieces of code since it increases output size by quite a bit
217
+ (default: ``False``).
218
+
219
+ `classprefix`
220
+ Since the token types use relatively short class names, they may clash
221
+ with some of your own class names. In this case you can use the
222
+ `classprefix` option to give a string to prepend to all Pygments-generated
223
+ CSS class names for token types.
224
+ Note that this option also affects the output of `get_style_defs()`.
225
+
226
+ `cssclass`
227
+ CSS class for the wrapping ``<div>`` tag (default: ``'highlight'``).
228
+ If you set this option, the default selector for `get_style_defs()`
229
+ will be this class.
230
+
231
+ .. versionadded:: 0.9
232
+ If you select the ``'table'`` line numbers, the wrapping table will
233
+ have a CSS class of this string plus ``'table'``, the default is
234
+ accordingly ``'highlighttable'``.
235
+
236
+ `cssstyles`
237
+ Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
238
+
239
+ `prestyles`
240
+ Inline CSS styles for the ``<pre>`` tag (default: ``''``).
241
+
242
+ .. versionadded:: 0.11
243
+
244
+ `cssfile`
245
+ If the `full` option is true and this option is given, it must be the
246
+ name of an external file. If the filename does not include an absolute
247
+ path, the file's path will be assumed to be relative to the main output
248
+ file's path, if the latter can be found. The stylesheet is then written
249
+ to this file instead of the HTML file.
250
+
251
+ .. versionadded:: 0.6
252
+
253
+ `noclobber_cssfile`
254
+ If `cssfile` is given and the specified file exists, the css file will
255
+ not be overwritten. This allows the use of the `full` option in
256
+ combination with a user specified css file. Default is ``False``.
257
+
258
+ .. versionadded:: 1.1
259
+
260
+ `linenos`
261
+ If set to ``'table'``, output line numbers as a table with two cells,
262
+ one containing the line numbers, the other the whole code. This is
263
+ copy-and-paste-friendly, but may cause alignment problems with some
264
+ browsers or fonts. If set to ``'inline'``, the line numbers will be
265
+ integrated in the ``<pre>`` tag that contains the code (that setting
266
+ is *new in Pygments 0.8*).
267
+
268
+ For compatibility with Pygments 0.7 and earlier, every true value
269
+ except ``'inline'`` means the same as ``'table'`` (in particular, that
270
+ means also ``True``).
271
+
272
+ The default value is ``False``, which means no line numbers at all.
273
+
274
+ **Note:** with the default ("table") line number mechanism, the line
275
+ numbers and code can have different line heights in Internet Explorer
276
+ unless you give the enclosing ``<pre>`` tags an explicit ``line-height``
277
+ CSS property (you get the default line spacing with ``line-height:
278
+ 125%``).
279
+
280
+ `hl_lines`
281
+ Specify a list of lines to be highlighted. The line numbers are always
282
+ relative to the input (i.e. the first line is line 1) and are
283
+ independent of `linenostart`.
284
+
285
+ .. versionadded:: 0.11
286
+
287
+ `linenostart`
288
+ The line number for the first line (default: ``1``).
289
+
290
+ `linenostep`
291
+ If set to a number n > 1, only every nth line number is printed.
292
+
293
+ `linenospecial`
294
+ If set to a number n > 0, every nth line number is given the CSS
295
+ class ``"special"`` (default: ``0``).
296
+
297
+ `nobackground`
298
+ If set to ``True``, the formatter won't output the background color
299
+ for the wrapping element (this automatically defaults to ``False``
300
+ when there is no wrapping element [eg: no argument for the
301
+ `get_syntax_defs` method given]) (default: ``False``).
302
+
303
+ .. versionadded:: 0.6
304
+
305
+ `lineseparator`
306
+ This string is output between lines of code. It defaults to ``"\n"``,
307
+ which is enough to break a line inside ``<pre>`` tags, but you can
308
+ e.g. set it to ``"<br>"`` to get HTML line breaks.
309
+
310
+ .. versionadded:: 0.7
311
+
312
+ `lineanchors`
313
+ If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
314
+ output line in an anchor tag with an ``id`` (and `name`) of ``foo-linenumber``.
315
+ This allows easy linking to certain lines.
316
+
317
+ .. versionadded:: 0.9
318
+
319
+ `linespans`
320
+ If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
321
+ output line in a span tag with an ``id`` of ``foo-linenumber``.
322
+ This allows easy access to lines via javascript.
323
+
324
+ .. versionadded:: 1.6
325
+
326
+ `anchorlinenos`
327
+ If set to `True`, will wrap line numbers in <a> tags. Used in
328
+ combination with `linenos` and `lineanchors`.
329
+
330
+ `tagsfile`
331
+ If set to the path of a ctags file, wrap names in anchor tags that
332
+ link to their definitions. `lineanchors` should be used, and the
333
+ tags file should specify line numbers (see the `-n` option to ctags).
334
+ The tags file is assumed to be encoded in UTF-8.
335
+
336
+ .. versionadded:: 1.6
337
+
338
+ `tagurlformat`
339
+ A string formatting pattern used to generate links to ctags definitions.
340
+ Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
341
+ Defaults to an empty string, resulting in just `#prefix-number` links.
342
+
343
+ .. versionadded:: 1.6
344
+
345
+ `filename`
346
+ A string used to generate a filename when rendering ``<pre>`` blocks,
347
+ for example if displaying source code. If `linenos` is set to
348
+ ``'table'`` then the filename will be rendered in an initial row
349
+ containing a single `<th>` which spans both columns.
350
+
351
+ .. versionadded:: 2.1
352
+
353
+ `wrapcode`
354
+ Wrap the code inside ``<pre>`` blocks using ``<code>``, as recommended
355
+ by the HTML5 specification.
356
+
357
+ .. versionadded:: 2.4
358
+
359
+ `debug_token_types`
360
+ Add ``title`` attributes to all token ``<span>`` tags that show the
361
+ name of the token.
362
+
363
+ .. versionadded:: 2.10
364
+
365
+
366
+ **Subclassing the HTML formatter**
367
+
368
+ .. versionadded:: 0.7
369
+
370
+ The HTML formatter is now built in a way that allows easy subclassing, thus
371
+ customizing the output HTML code. The `format()` method calls
372
+ `self._format_lines()` which returns a generator that yields tuples of ``(1,
373
+ line)``, where the ``1`` indicates that the ``line`` is a line of the
374
+ formatted source code.
375
+
376
+ If the `nowrap` option is set, the generator is the iterated over and the
377
+ resulting HTML is output.
378
+
379
+ Otherwise, `format()` calls `self.wrap()`, which wraps the generator with
380
+ other generators. These may add some HTML code to the one generated by
381
+ `_format_lines()`, either by modifying the lines generated by the latter,
382
+ then yielding them again with ``(1, line)``, and/or by yielding other HTML
383
+ code before or after the lines, with ``(0, html)``. The distinction between
384
+ source lines and other code makes it possible to wrap the generator multiple
385
+ times.
386
+
387
+ The default `wrap()` implementation adds a ``<div>`` and a ``<pre>`` tag.
388
+
389
+ A custom `HtmlFormatter` subclass could look like this:
390
+
391
+ .. sourcecode:: python
392
+
393
+ class CodeHtmlFormatter(HtmlFormatter):
394
+
395
+ def wrap(self, source, *, include_div):
396
+ return self._wrap_code(source)
397
+
398
+ def _wrap_code(self, source):
399
+ yield 0, '<code>'
400
+ for i, t in source:
401
+ if i == 1:
402
+ # it's a line of formatted code
403
+ t += '<br>'
404
+ yield i, t
405
+ yield 0, '</code>'
406
+
407
+ This results in wrapping the formatted lines with a ``<code>`` tag, where the
408
+ source lines are broken using ``<br>`` tags.
409
+
410
+ After calling `wrap()`, the `format()` method also adds the "line numbers"
411
+ and/or "full document" wrappers if the respective options are set. Then, all
412
+ HTML yielded by the wrapped generator is output.
413
+ """
414
+
415
+ name = 'HTML'
416
+ aliases = ['html']
417
+ filenames = ['*.html', '*.htm']
418
+
419
+ def __init__(self, **options):
420
+ Formatter.__init__(self, **options)
421
+ self.title = self._decodeifneeded(self.title)
422
+ self.nowrap = get_bool_opt(options, 'nowrap', False)
423
+ self.noclasses = get_bool_opt(options, 'noclasses', False)
424
+ self.classprefix = options.get('classprefix', '')
425
+ self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
426
+ self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
427
+ self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
428
+ self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
429
+ self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
430
+ self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
431
+ self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
432
+ self.filename = self._decodeifneeded(options.get('filename', ''))
433
+ self.wrapcode = get_bool_opt(options, 'wrapcode', False)
434
+ self.span_element_openers = {}
435
+ self.debug_token_types = get_bool_opt(options, 'debug_token_types', False)
436
+
437
+ if self.tagsfile:
438
+ if not ctags:
439
+ raise RuntimeError('The "ctags" package must to be installed '
440
+ 'to be able to use the "tagsfile" feature.')
441
+ self._ctags = ctags.CTags(self.tagsfile)
442
+
443
+ linenos = options.get('linenos', False)
444
+ if linenos == 'inline':
445
+ self.linenos = 2
446
+ elif linenos:
447
+ # compatibility with <= 0.7
448
+ self.linenos = 1
449
+ else:
450
+ self.linenos = 0
451
+ self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
452
+ self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
453
+ self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
454
+ self.nobackground = get_bool_opt(options, 'nobackground', False)
455
+ self.lineseparator = options.get('lineseparator', '\n')
456
+ self.lineanchors = options.get('lineanchors', '')
457
+ self.linespans = options.get('linespans', '')
458
+ self.anchorlinenos = get_bool_opt(options, 'anchorlinenos', False)
459
+ self.hl_lines = set()
460
+ for lineno in get_list_opt(options, 'hl_lines', []):
461
+ try:
462
+ self.hl_lines.add(int(lineno))
463
+ except ValueError:
464
+ pass
465
+
466
+ self._create_stylesheet()
467
+
468
+ def _get_css_class(self, ttype):
469
+ """Return the css class of this token type prefixed with
470
+ the classprefix option."""
471
+ ttypeclass = _get_ttype_class(ttype)
472
+ if ttypeclass:
473
+ return self.classprefix + ttypeclass
474
+ return ''
475
+
476
+ def _get_css_classes(self, ttype):
477
+ """Return the CSS classes of this token type prefixed with the classprefix option."""
478
+ cls = self._get_css_class(ttype)
479
+ while ttype not in STANDARD_TYPES:
480
+ ttype = ttype.parent
481
+ cls = self._get_css_class(ttype) + ' ' + cls
482
+ return cls or ''
483
+
484
+ def _get_css_inline_styles(self, ttype):
485
+ """Return the inline CSS styles for this token type."""
486
+ cclass = self.ttype2class.get(ttype)
487
+ while cclass is None:
488
+ ttype = ttype.parent
489
+ cclass = self.ttype2class.get(ttype)
490
+ return cclass or ''
491
+
492
+ def _create_stylesheet(self):
493
+ t2c = self.ttype2class = {Token: ''}
494
+ c2s = self.class2style = {}
495
+ for ttype, ndef in self.style:
496
+ name = self._get_css_class(ttype)
497
+ style = ''
498
+ if ndef['color']:
499
+ style += 'color: {}; '.format(webify(ndef['color']))
500
+ if ndef['bold']:
501
+ style += 'font-weight: bold; '
502
+ if ndef['italic']:
503
+ style += 'font-style: italic; '
504
+ if ndef['underline']:
505
+ style += 'text-decoration: underline; '
506
+ if ndef['bgcolor']:
507
+ style += 'background-color: {}; '.format(webify(ndef['bgcolor']))
508
+ if ndef['border']:
509
+ style += 'border: 1px solid {}; '.format(webify(ndef['border']))
510
+ if style:
511
+ t2c[ttype] = name
512
+ # save len(ttype) to enable ordering the styles by
513
+ # hierarchy (necessary for CSS cascading rules!)
514
+ c2s[name] = (style[:-2], ttype, len(ttype))
515
+
516
+ def get_style_defs(self, arg=None):
517
+ """
518
+ Return CSS style definitions for the classes produced by the current
519
+ highlighting style. ``arg`` can be a string or list of selectors to
520
+ insert before the token type classes.
521
+ """
522
+ style_lines = []
523
+
524
+ style_lines.extend(self.get_linenos_style_defs())
525
+ style_lines.extend(self.get_background_style_defs(arg))
526
+ style_lines.extend(self.get_token_style_defs(arg))
527
+
528
+ return '\n'.join(style_lines)
529
+
530
+ def get_token_style_defs(self, arg=None):
531
+ prefix = self.get_css_prefix(arg)
532
+
533
+ styles = [
534
+ (level, ttype, cls, style)
535
+ for cls, (style, ttype, level) in self.class2style.items()
536
+ if cls and style
537
+ ]
538
+ styles.sort()
539
+
540
+ lines = [
541
+ f'{prefix(cls)} {{ {style} }} /* {repr(ttype)[6:]} */'
542
+ for (level, ttype, cls, style) in styles
543
+ ]
544
+
545
+ return lines
546
+
547
+ def get_background_style_defs(self, arg=None):
548
+ prefix = self.get_css_prefix(arg)
549
+ bg_color = self.style.background_color
550
+ hl_color = self.style.highlight_color
551
+
552
+ lines = []
553
+
554
+ if arg and not self.nobackground and bg_color is not None:
555
+ text_style = ''
556
+ if Text in self.ttype2class:
557
+ text_style = ' ' + self.class2style[self.ttype2class[Text]][0]
558
+ lines.insert(
559
+ 0, '{}{{ background: {};{} }}'.format(
560
+ prefix(''), bg_color, text_style
561
+ )
562
+ )
563
+ if hl_color is not None:
564
+ lines.insert(
565
+ 0, '{} {{ background-color: {} }}'.format(prefix('hll'), hl_color)
566
+ )
567
+
568
+ return lines
569
+
570
+ def get_linenos_style_defs(self):
571
+ lines = [
572
+ f'pre {{ {self._pre_style} }}',
573
+ f'td.linenos .normal {{ {self._linenos_style} }}',
574
+ f'span.linenos {{ {self._linenos_style} }}',
575
+ f'td.linenos .special {{ {self._linenos_special_style} }}',
576
+ f'span.linenos.special {{ {self._linenos_special_style} }}',
577
+ ]
578
+
579
+ return lines
580
+
581
+ def get_css_prefix(self, arg):
582
+ if arg is None:
583
+ arg = ('cssclass' in self.options and '.'+self.cssclass or '')
584
+ if isinstance(arg, str):
585
+ args = [arg]
586
+ else:
587
+ args = list(arg)
588
+
589
+ def prefix(cls):
590
+ if cls:
591
+ cls = '.' + cls
592
+ tmp = []
593
+ for arg in args:
594
+ tmp.append((arg and arg + ' ' or '') + cls)
595
+ return ', '.join(tmp)
596
+
597
+ return prefix
598
+
599
+ @property
600
+ def _pre_style(self):
601
+ return 'line-height: 125%;'
602
+
603
+ @property
604
+ def _linenos_style(self):
605
+ color = self.style.line_number_color
606
+ background_color = self.style.line_number_background_color
607
+ return f'color: {color}; background-color: {background_color}; padding-left: 5px; padding-right: 5px;'
608
+
609
+ @property
610
+ def _linenos_special_style(self):
611
+ color = self.style.line_number_special_color
612
+ background_color = self.style.line_number_special_background_color
613
+ return f'color: {color}; background-color: {background_color}; padding-left: 5px; padding-right: 5px;'
614
+
615
+ def _decodeifneeded(self, value):
616
+ if isinstance(value, bytes):
617
+ if self.encoding:
618
+ return value.decode(self.encoding)
619
+ return value.decode()
620
+ return value
621
+
622
+ def _wrap_full(self, inner, outfile):
623
+ if self.cssfile:
624
+ if os.path.isabs(self.cssfile):
625
+ # it's an absolute filename
626
+ cssfilename = self.cssfile
627
+ else:
628
+ try:
629
+ filename = outfile.name
630
+ if not filename or filename[0] == '<':
631
+ # pseudo files, e.g. name == '<fdopen>'
632
+ raise AttributeError
633
+ cssfilename = os.path.join(os.path.dirname(filename),
634
+ self.cssfile)
635
+ except AttributeError:
636
+ print('Note: Cannot determine output file name, '
637
+ 'using current directory as base for the CSS file name',
638
+ file=sys.stderr)
639
+ cssfilename = self.cssfile
640
+ # write CSS file only if noclobber_cssfile isn't given as an option.
641
+ try:
642
+ if not os.path.exists(cssfilename) or not self.noclobber_cssfile:
643
+ with open(cssfilename, "w", encoding="utf-8") as cf:
644
+ cf.write(CSSFILE_TEMPLATE %
645
+ {'styledefs': self.get_style_defs('body')})
646
+ except OSError as err:
647
+ err.strerror = 'Error writing CSS file: ' + err.strerror
648
+ raise
649
+
650
+ yield 0, (DOC_HEADER_EXTERNALCSS %
651
+ dict(title=self.title,
652
+ cssfile=self.cssfile,
653
+ encoding=self.encoding))
654
+ else:
655
+ yield 0, (DOC_HEADER %
656
+ dict(title=self.title,
657
+ styledefs=self.get_style_defs('body'),
658
+ encoding=self.encoding))
659
+
660
+ yield from inner
661
+ yield 0, DOC_FOOTER
662
+
663
+ def _wrap_tablelinenos(self, inner):
664
+ dummyoutfile = StringIO()
665
+ lncount = 0
666
+ for t, line in inner:
667
+ if t:
668
+ lncount += 1
669
+ dummyoutfile.write(line)
670
+
671
+ fl = self.linenostart
672
+ mw = len(str(lncount + fl - 1))
673
+ sp = self.linenospecial
674
+ st = self.linenostep
675
+ anchor_name = self.lineanchors or self.linespans
676
+ aln = self.anchorlinenos
677
+ nocls = self.noclasses
678
+
679
+ lines = []
680
+
681
+ for i in range(fl, fl+lncount):
682
+ print_line = i % st == 0
683
+ special_line = sp and i % sp == 0
684
+
685
+ if print_line:
686
+ line = '%*d' % (mw, i)
687
+ if aln:
688
+ line = '<a href="#%s-%d">%s</a>' % (anchor_name, i, line)
689
+ else:
690
+ line = ' ' * mw
691
+
692
+ if nocls:
693
+ if special_line:
694
+ style = f' style="{self._linenos_special_style}"'
695
+ else:
696
+ style = f' style="{self._linenos_style}"'
697
+ else:
698
+ if special_line:
699
+ style = ' class="special"'
700
+ else:
701
+ style = ' class="normal"'
702
+
703
+ if style:
704
+ line = f'<span{style}>{line}</span>'
705
+
706
+ lines.append(line)
707
+
708
+ ls = '\n'.join(lines)
709
+
710
+ # If a filename was specified, we can't put it into the code table as it
711
+ # would misalign the line numbers. Hence we emit a separate row for it.
712
+ filename_tr = ""
713
+ if self.filename:
714
+ filename_tr = (
715
+ '<tr><th colspan="2" class="filename">'
716
+ '<span class="filename">' + self.filename + '</span>'
717
+ '</th></tr>')
718
+
719
+ # in case you wonder about the seemingly redundant <div> here: since the
720
+ # content in the other cell also is wrapped in a div, some browsers in
721
+ # some configurations seem to mess up the formatting...
722
+ yield 0, (f'<table class="{self.cssclass}table">' + filename_tr +
723
+ '<tr><td class="linenos"><div class="linenodiv"><pre>' +
724
+ ls + '</pre></div></td><td class="code">')
725
+ yield 0, '<div>'
726
+ yield 0, dummyoutfile.getvalue()
727
+ yield 0, '</div>'
728
+ yield 0, '</td></tr></table>'
729
+
730
+
731
+ def _wrap_inlinelinenos(self, inner):
732
+ # need a list of lines since we need the width of a single number :(
733
+ inner_lines = list(inner)
734
+ sp = self.linenospecial
735
+ st = self.linenostep
736
+ num = self.linenostart
737
+ mw = len(str(len(inner_lines) + num - 1))
738
+ anchor_name = self.lineanchors or self.linespans
739
+ aln = self.anchorlinenos
740
+ nocls = self.noclasses
741
+
742
+ for _, inner_line in inner_lines:
743
+ print_line = num % st == 0
744
+ special_line = sp and num % sp == 0
745
+
746
+ if print_line:
747
+ line = '%*d' % (mw, num)
748
+ else:
749
+ line = ' ' * mw
750
+
751
+ if nocls:
752
+ if special_line:
753
+ style = f' style="{self._linenos_special_style}"'
754
+ else:
755
+ style = f' style="{self._linenos_style}"'
756
+ else:
757
+ if special_line:
758
+ style = ' class="linenos special"'
759
+ else:
760
+ style = ' class="linenos"'
761
+
762
+ if style:
763
+ linenos = f'<span{style}>{line}</span>'
764
+ else:
765
+ linenos = line
766
+
767
+ if aln:
768
+ yield 1, ('<a href="#%s-%d">%s</a>' % (anchor_name, num, linenos) +
769
+ inner_line)
770
+ else:
771
+ yield 1, linenos + inner_line
772
+ num += 1
773
+
774
+ def _wrap_lineanchors(self, inner):
775
+ s = self.lineanchors
776
+ # subtract 1 since we have to increment i *before* yielding
777
+ i = self.linenostart - 1
778
+ for t, line in inner:
779
+ if t:
780
+ i += 1
781
+ href = "" if self.linenos else ' href="#%s-%d"' % (s, i)
782
+ yield 1, '<a id="%s-%d" name="%s-%d"%s></a>' % (s, i, s, i, href) + line
783
+ else:
784
+ yield 0, line
785
+
786
+ def _wrap_linespans(self, inner):
787
+ s = self.linespans
788
+ i = self.linenostart - 1
789
+ for t, line in inner:
790
+ if t:
791
+ i += 1
792
+ yield 1, '<span id="%s-%d">%s</span>' % (s, i, line)
793
+ else:
794
+ yield 0, line
795
+
796
+ def _wrap_div(self, inner):
797
+ style = []
798
+ if (self.noclasses and not self.nobackground and
799
+ self.style.background_color is not None):
800
+ style.append(f'background: {self.style.background_color}')
801
+ if self.cssstyles:
802
+ style.append(self.cssstyles)
803
+ style = '; '.join(style)
804
+
805
+ yield 0, ('<div' + (self.cssclass and f' class="{self.cssclass}"') +
806
+ (style and (f' style="{style}"')) + '>')
807
+ yield from inner
808
+ yield 0, '</div>\n'
809
+
810
+ def _wrap_pre(self, inner):
811
+ style = []
812
+ if self.prestyles:
813
+ style.append(self.prestyles)
814
+ if self.noclasses:
815
+ style.append(self._pre_style)
816
+ style = '; '.join(style)
817
+
818
+ if self.filename and self.linenos != 1:
819
+ yield 0, ('<span class="filename">' + self.filename + '</span>')
820
+
821
+ # the empty span here is to keep leading empty lines from being
822
+ # ignored by HTML parsers
823
+ yield 0, ('<pre' + (style and f' style="{style}"') + '><span></span>')
824
+ yield from inner
825
+ yield 0, '</pre>'
826
+
827
+ def _wrap_code(self, inner):
828
+ yield 0, '<code>'
829
+ yield from inner
830
+ yield 0, '</code>'
831
+
832
+ @functools.lru_cache(maxsize=100)
833
+ def _translate_parts(self, value):
834
+ """HTML-escape a value and split it by newlines."""
835
+ return value.translate(_escape_html_table).split('\n')
836
+
837
+ def _format_lines(self, tokensource):
838
+ """
839
+ Just format the tokens, without any wrapping tags.
840
+ Yield individual lines.
841
+ """
842
+ nocls = self.noclasses
843
+ lsep = self.lineseparator
844
+ tagsfile = self.tagsfile
845
+
846
+ lspan = ''
847
+ line = []
848
+ for ttype, value in tokensource:
849
+ try:
850
+ cspan = self.span_element_openers[ttype]
851
+ except KeyError:
852
+ title = ' title="{}"'.format('.'.join(ttype)) if self.debug_token_types else ''
853
+ if nocls:
854
+ css_style = self._get_css_inline_styles(ttype)
855
+ if css_style:
856
+ css_style = self.class2style[css_style][0]
857
+ cspan = f'<span style="{css_style}"{title}>'
858
+ else:
859
+ cspan = ''
860
+ else:
861
+ css_class = self._get_css_classes(ttype)
862
+ if css_class:
863
+ cspan = f'<span class="{css_class}"{title}>'
864
+ else:
865
+ cspan = ''
866
+ self.span_element_openers[ttype] = cspan
867
+
868
+ parts = self._translate_parts(value)
869
+
870
+ if tagsfile and ttype in Token.Name:
871
+ filename, linenumber = self._lookup_ctag(value)
872
+ if linenumber:
873
+ base, filename = os.path.split(filename)
874
+ if base:
875
+ base += '/'
876
+ filename, extension = os.path.splitext(filename)
877
+ url = self.tagurlformat % {'path': base, 'fname': filename,
878
+ 'fext': extension}
879
+ parts[0] = "<a href=\"%s#%s-%d\">%s" % \
880
+ (url, self.lineanchors, linenumber, parts[0])
881
+ parts[-1] = parts[-1] + "</a>"
882
+
883
+ # for all but the last line
884
+ for part in parts[:-1]:
885
+ if line:
886
+ # Also check for part being non-empty, so we avoid creating
887
+ # empty <span> tags
888
+ if lspan != cspan and part:
889
+ line.extend(((lspan and '</span>'), cspan, part,
890
+ (cspan and '</span>'), lsep))
891
+ else: # both are the same, or the current part was empty
892
+ line.extend((part, (lspan and '</span>'), lsep))
893
+ yield 1, ''.join(line)
894
+ line = []
895
+ elif part:
896
+ yield 1, ''.join((cspan, part, (cspan and '</span>'), lsep))
897
+ else:
898
+ yield 1, lsep
899
+ # for the last line
900
+ if line and parts[-1]:
901
+ if lspan != cspan:
902
+ line.extend(((lspan and '</span>'), cspan, parts[-1]))
903
+ lspan = cspan
904
+ else:
905
+ line.append(parts[-1])
906
+ elif parts[-1]:
907
+ line = [cspan, parts[-1]]
908
+ lspan = cspan
909
+ # else we neither have to open a new span nor set lspan
910
+
911
+ if line:
912
+ line.extend(((lspan and '</span>'), lsep))
913
+ yield 1, ''.join(line)
914
+
915
+ def _lookup_ctag(self, token):
916
+ entry = ctags.TagEntry()
917
+ if self._ctags.find(entry, token.encode(), 0):
918
+ return entry['file'].decode(), entry['lineNumber']
919
+ else:
920
+ return None, None
921
+
922
+ def _highlight_lines(self, tokensource):
923
+ """
924
+ Highlighted the lines specified in the `hl_lines` option by
925
+ post-processing the token stream coming from `_format_lines`.
926
+ """
927
+ hls = self.hl_lines
928
+
929
+ for i, (t, value) in enumerate(tokensource):
930
+ if t != 1:
931
+ yield t, value
932
+ if i + 1 in hls: # i + 1 because Python indexes start at 0
933
+ if self.noclasses:
934
+ style = ''
935
+ if self.style.highlight_color is not None:
936
+ style = (f' style="background-color: {self.style.highlight_color}"')
937
+ yield 1, f'<span{style}>{value}</span>'
938
+ else:
939
+ yield 1, f'<span class="hll">{value}</span>'
940
+ else:
941
+ yield 1, value
942
+
943
+ def wrap(self, source):
944
+ """
945
+ Wrap the ``source``, which is a generator yielding
946
+ individual lines, in custom generators. See docstring
947
+ for `format`. Can be overridden.
948
+ """
949
+
950
+ output = source
951
+ if self.wrapcode:
952
+ output = self._wrap_code(output)
953
+
954
+ output = self._wrap_pre(output)
955
+
956
+ return output
957
+
958
+ def format_unencoded(self, tokensource, outfile):
959
+ """
960
+ The formatting process uses several nested generators; which of
961
+ them are used is determined by the user's options.
962
+
963
+ Each generator should take at least one argument, ``inner``,
964
+ and wrap the pieces of text generated by this.
965
+
966
+ Always yield 2-tuples: (code, text). If "code" is 1, the text
967
+ is part of the original tokensource being highlighted, if it's
968
+ 0, the text is some piece of wrapping. This makes it possible to
969
+ use several different wrappers that process the original source
970
+ linewise, e.g. line number generators.
971
+ """
972
+ source = self._format_lines(tokensource)
973
+
974
+ # As a special case, we wrap line numbers before line highlighting
975
+ # so the line numbers get wrapped in the highlighting tag.
976
+ if not self.nowrap and self.linenos == 2:
977
+ source = self._wrap_inlinelinenos(source)
978
+
979
+ if self.hl_lines:
980
+ source = self._highlight_lines(source)
981
+
982
+ if not self.nowrap:
983
+ if self.lineanchors:
984
+ source = self._wrap_lineanchors(source)
985
+ if self.linespans:
986
+ source = self._wrap_linespans(source)
987
+ source = self.wrap(source)
988
+ if self.linenos == 1:
989
+ source = self._wrap_tablelinenos(source)
990
+ source = self._wrap_div(source)
991
+ if self.full:
992
+ source = self._wrap_full(source, outfile)
993
+
994
+ for t, piece in source:
995
+ outfile.write(piece)
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/img.py ADDED
@@ -0,0 +1,686 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.img
3
+ ~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Formatter for Pixmap output.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+ import os
11
+ import sys
12
+
13
+ from pygments.formatter import Formatter
14
+ from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
15
+ get_choice_opt
16
+
17
+ import subprocess
18
+
19
+ # Import this carefully
20
+ try:
21
+ from PIL import Image, ImageDraw, ImageFont
22
+ pil_available = True
23
+ except ImportError:
24
+ pil_available = False
25
+
26
+ try:
27
+ import _winreg
28
+ except ImportError:
29
+ try:
30
+ import winreg as _winreg
31
+ except ImportError:
32
+ _winreg = None
33
+
34
+ __all__ = ['ImageFormatter', 'GifImageFormatter', 'JpgImageFormatter',
35
+ 'BmpImageFormatter']
36
+
37
+
38
+ # For some unknown reason every font calls it something different
39
+ STYLES = {
40
+ 'NORMAL': ['', 'Roman', 'Book', 'Normal', 'Regular', 'Medium'],
41
+ 'ITALIC': ['Oblique', 'Italic'],
42
+ 'BOLD': ['Bold'],
43
+ 'BOLDITALIC': ['Bold Oblique', 'Bold Italic'],
44
+ }
45
+
46
+ # A sane default for modern systems
47
+ DEFAULT_FONT_NAME_NIX = 'DejaVu Sans Mono'
48
+ DEFAULT_FONT_NAME_WIN = 'Courier New'
49
+ DEFAULT_FONT_NAME_MAC = 'Menlo'
50
+
51
+
52
+ class PilNotAvailable(ImportError):
53
+ """When Python imaging library is not available"""
54
+
55
+
56
+ class FontNotFound(Exception):
57
+ """When there are no usable fonts specified"""
58
+
59
+
60
+ class FontManager:
61
+ """
62
+ Manages a set of fonts: normal, italic, bold, etc...
63
+ """
64
+
65
+ def __init__(self, font_name, font_size=14):
66
+ self.font_name = font_name
67
+ self.font_size = font_size
68
+ self.fonts = {}
69
+ self.encoding = None
70
+ self.variable = False
71
+ if hasattr(font_name, 'read') or os.path.isfile(font_name):
72
+ font = ImageFont.truetype(font_name, self.font_size)
73
+ self.variable = True
74
+ for style in STYLES:
75
+ self.fonts[style] = font
76
+
77
+ return
78
+
79
+ if sys.platform.startswith('win'):
80
+ if not font_name:
81
+ self.font_name = DEFAULT_FONT_NAME_WIN
82
+ self._create_win()
83
+ elif sys.platform.startswith('darwin'):
84
+ if not font_name:
85
+ self.font_name = DEFAULT_FONT_NAME_MAC
86
+ self._create_mac()
87
+ else:
88
+ if not font_name:
89
+ self.font_name = DEFAULT_FONT_NAME_NIX
90
+ self._create_nix()
91
+
92
+ def _get_nix_font_path(self, name, style):
93
+ proc = subprocess.Popen(['fc-list', f"{name}:style={style}", 'file'],
94
+ stdout=subprocess.PIPE, stderr=None)
95
+ stdout, _ = proc.communicate()
96
+ if proc.returncode == 0:
97
+ lines = stdout.splitlines()
98
+ for line in lines:
99
+ if line.startswith(b'Fontconfig warning:'):
100
+ continue
101
+ path = line.decode().strip().strip(':')
102
+ if path:
103
+ return path
104
+ return None
105
+
106
+ def _create_nix(self):
107
+ for name in STYLES['NORMAL']:
108
+ path = self._get_nix_font_path(self.font_name, name)
109
+ if path is not None:
110
+ self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
111
+ break
112
+ else:
113
+ raise FontNotFound(f'No usable fonts named: "{self.font_name}"')
114
+ for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
115
+ for stylename in STYLES[style]:
116
+ path = self._get_nix_font_path(self.font_name, stylename)
117
+ if path is not None:
118
+ self.fonts[style] = ImageFont.truetype(path, self.font_size)
119
+ break
120
+ else:
121
+ if style == 'BOLDITALIC':
122
+ self.fonts[style] = self.fonts['BOLD']
123
+ else:
124
+ self.fonts[style] = self.fonts['NORMAL']
125
+
126
+ def _get_mac_font_path(self, font_map, name, style):
127
+ return font_map.get((name + ' ' + style).strip().lower())
128
+
129
+ def _create_mac(self):
130
+ font_map = {}
131
+ for font_dir in (os.path.join(os.getenv("HOME"), 'Library/Fonts/'),
132
+ '/Library/Fonts/', '/System/Library/Fonts/'):
133
+ font_map.update(
134
+ (os.path.splitext(f)[0].lower(), os.path.join(font_dir, f))
135
+ for _, _, files in os.walk(font_dir)
136
+ for f in files
137
+ if f.lower().endswith(('ttf', 'ttc')))
138
+
139
+ for name in STYLES['NORMAL']:
140
+ path = self._get_mac_font_path(font_map, self.font_name, name)
141
+ if path is not None:
142
+ self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
143
+ break
144
+ else:
145
+ raise FontNotFound(f'No usable fonts named: "{self.font_name}"')
146
+ for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
147
+ for stylename in STYLES[style]:
148
+ path = self._get_mac_font_path(font_map, self.font_name, stylename)
149
+ if path is not None:
150
+ self.fonts[style] = ImageFont.truetype(path, self.font_size)
151
+ break
152
+ else:
153
+ if style == 'BOLDITALIC':
154
+ self.fonts[style] = self.fonts['BOLD']
155
+ else:
156
+ self.fonts[style] = self.fonts['NORMAL']
157
+
158
+ def _lookup_win(self, key, basename, styles, fail=False):
159
+ for suffix in ('', ' (TrueType)'):
160
+ for style in styles:
161
+ try:
162
+ valname = '{}{}{}'.format(basename, style and ' '+style, suffix)
163
+ val, _ = _winreg.QueryValueEx(key, valname)
164
+ return val
165
+ except OSError:
166
+ continue
167
+ else:
168
+ if fail:
169
+ raise FontNotFound(f'Font {basename} ({styles[0]}) not found in registry')
170
+ return None
171
+
172
+ def _create_win(self):
173
+ lookuperror = None
174
+ keynames = [ (_winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows NT\CurrentVersion\Fonts'),
175
+ (_winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Fonts'),
176
+ (_winreg.HKEY_LOCAL_MACHINE, r'Software\Microsoft\Windows NT\CurrentVersion\Fonts'),
177
+ (_winreg.HKEY_LOCAL_MACHINE, r'Software\Microsoft\Windows\CurrentVersion\Fonts') ]
178
+ for keyname in keynames:
179
+ try:
180
+ key = _winreg.OpenKey(*keyname)
181
+ try:
182
+ path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
183
+ self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
184
+ for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
185
+ path = self._lookup_win(key, self.font_name, STYLES[style])
186
+ if path:
187
+ self.fonts[style] = ImageFont.truetype(path, self.font_size)
188
+ else:
189
+ if style == 'BOLDITALIC':
190
+ self.fonts[style] = self.fonts['BOLD']
191
+ else:
192
+ self.fonts[style] = self.fonts['NORMAL']
193
+ return
194
+ except FontNotFound as err:
195
+ lookuperror = err
196
+ finally:
197
+ _winreg.CloseKey(key)
198
+ except OSError:
199
+ pass
200
+ else:
201
+ # If we get here, we checked all registry keys and had no luck
202
+ # We can be in one of two situations now:
203
+ # * All key lookups failed. In this case lookuperror is None and we
204
+ # will raise a generic error
205
+ # * At least one lookup failed with a FontNotFound error. In this
206
+ # case, we will raise that as a more specific error
207
+ if lookuperror:
208
+ raise lookuperror
209
+ raise FontNotFound('Can\'t open Windows font registry key')
210
+
211
+ def get_char_size(self):
212
+ """
213
+ Get the character size.
214
+ """
215
+ return self.get_text_size('M')
216
+
217
+ def get_text_size(self, text):
218
+ """
219
+ Get the text size (width, height).
220
+ """
221
+ font = self.fonts['NORMAL']
222
+ if hasattr(font, 'getbbox'): # Pillow >= 9.2.0
223
+ return font.getbbox(text)[2:4]
224
+ else:
225
+ return font.getsize(text)
226
+
227
+ def get_font(self, bold, oblique):
228
+ """
229
+ Get the font based on bold and italic flags.
230
+ """
231
+ if bold and oblique:
232
+ if self.variable:
233
+ return self.get_style('BOLDITALIC')
234
+
235
+ return self.fonts['BOLDITALIC']
236
+ elif bold:
237
+ if self.variable:
238
+ return self.get_style('BOLD')
239
+
240
+ return self.fonts['BOLD']
241
+ elif oblique:
242
+ if self.variable:
243
+ return self.get_style('ITALIC')
244
+
245
+ return self.fonts['ITALIC']
246
+ else:
247
+ if self.variable:
248
+ return self.get_style('NORMAL')
249
+
250
+ return self.fonts['NORMAL']
251
+
252
+ def get_style(self, style):
253
+ """
254
+ Get the specified style of the font if it is a variable font.
255
+ If not found, return the normal font.
256
+ """
257
+ font = self.fonts[style]
258
+ for style_name in STYLES[style]:
259
+ try:
260
+ font.set_variation_by_name(style_name)
261
+ return font
262
+ except ValueError:
263
+ pass
264
+ except OSError:
265
+ return font
266
+
267
+ return font
268
+
269
+
270
+ class ImageFormatter(Formatter):
271
+ """
272
+ Create a PNG image from source code. This uses the Python Imaging Library to
273
+ generate a pixmap from the source code.
274
+
275
+ .. versionadded:: 0.10
276
+
277
+ Additional options accepted:
278
+
279
+ `image_format`
280
+ An image format to output to that is recognised by PIL, these include:
281
+
282
+ * "PNG" (default)
283
+ * "JPEG"
284
+ * "BMP"
285
+ * "GIF"
286
+
287
+ `line_pad`
288
+ The extra spacing (in pixels) between each line of text.
289
+
290
+ Default: 2
291
+
292
+ `font_name`
293
+ The font name to be used as the base font from which others, such as
294
+ bold and italic fonts will be generated. This really should be a
295
+ monospace font to look sane.
296
+ If a filename or a file-like object is specified, the user must
297
+ provide different styles of the font.
298
+
299
+ Default: "Courier New" on Windows, "Menlo" on Mac OS, and
300
+ "DejaVu Sans Mono" on \\*nix
301
+
302
+ `font_size`
303
+ The font size in points to be used.
304
+
305
+ Default: 14
306
+
307
+ `image_pad`
308
+ The padding, in pixels to be used at each edge of the resulting image.
309
+
310
+ Default: 10
311
+
312
+ `line_numbers`
313
+ Whether line numbers should be shown: True/False
314
+
315
+ Default: True
316
+
317
+ `line_number_start`
318
+ The line number of the first line.
319
+
320
+ Default: 1
321
+
322
+ `line_number_step`
323
+ The step used when printing line numbers.
324
+
325
+ Default: 1
326
+
327
+ `line_number_bg`
328
+ The background colour (in "#123456" format) of the line number bar, or
329
+ None to use the style background color.
330
+
331
+ Default: "#eed"
332
+
333
+ `line_number_fg`
334
+ The text color of the line numbers (in "#123456"-like format).
335
+
336
+ Default: "#886"
337
+
338
+ `line_number_chars`
339
+ The number of columns of line numbers allowable in the line number
340
+ margin.
341
+
342
+ Default: 2
343
+
344
+ `line_number_bold`
345
+ Whether line numbers will be bold: True/False
346
+
347
+ Default: False
348
+
349
+ `line_number_italic`
350
+ Whether line numbers will be italicized: True/False
351
+
352
+ Default: False
353
+
354
+ `line_number_separator`
355
+ Whether a line will be drawn between the line number area and the
356
+ source code area: True/False
357
+
358
+ Default: True
359
+
360
+ `line_number_pad`
361
+ The horizontal padding (in pixels) between the line number margin, and
362
+ the source code area.
363
+
364
+ Default: 6
365
+
366
+ `hl_lines`
367
+ Specify a list of lines to be highlighted.
368
+
369
+ .. versionadded:: 1.2
370
+
371
+ Default: empty list
372
+
373
+ `hl_color`
374
+ Specify the color for highlighting lines.
375
+
376
+ .. versionadded:: 1.2
377
+
378
+ Default: highlight color of the selected style
379
+ """
380
+
381
+ # Required by the pygments mapper
382
+ name = 'img'
383
+ aliases = ['img', 'IMG', 'png']
384
+ filenames = ['*.png']
385
+
386
+ unicodeoutput = False
387
+
388
+ default_image_format = 'png'
389
+
390
+ def __init__(self, **options):
391
+ """
392
+ See the class docstring for explanation of options.
393
+ """
394
+ if not pil_available:
395
+ raise PilNotAvailable(
396
+ 'Python Imaging Library is required for this formatter')
397
+ Formatter.__init__(self, **options)
398
+ self.encoding = 'latin1' # let pygments.format() do the right thing
399
+ # Read the style
400
+ self.styles = dict(self.style)
401
+ if self.style.background_color is None:
402
+ self.background_color = '#fff'
403
+ else:
404
+ self.background_color = self.style.background_color
405
+ # Image options
406
+ self.image_format = get_choice_opt(
407
+ options, 'image_format', ['png', 'jpeg', 'gif', 'bmp'],
408
+ self.default_image_format, normcase=True)
409
+ self.image_pad = get_int_opt(options, 'image_pad', 10)
410
+ self.line_pad = get_int_opt(options, 'line_pad', 2)
411
+ # The fonts
412
+ fontsize = get_int_opt(options, 'font_size', 14)
413
+ self.fonts = FontManager(options.get('font_name', ''), fontsize)
414
+ self.fontw, self.fonth = self.fonts.get_char_size()
415
+ # Line number options
416
+ self.line_number_fg = options.get('line_number_fg', '#886')
417
+ self.line_number_bg = options.get('line_number_bg', '#eed')
418
+ self.line_number_chars = get_int_opt(options,
419
+ 'line_number_chars', 2)
420
+ self.line_number_bold = get_bool_opt(options,
421
+ 'line_number_bold', False)
422
+ self.line_number_italic = get_bool_opt(options,
423
+ 'line_number_italic', False)
424
+ self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
425
+ self.line_numbers = get_bool_opt(options, 'line_numbers', True)
426
+ self.line_number_separator = get_bool_opt(options,
427
+ 'line_number_separator', True)
428
+ self.line_number_step = get_int_opt(options, 'line_number_step', 1)
429
+ self.line_number_start = get_int_opt(options, 'line_number_start', 1)
430
+ if self.line_numbers:
431
+ self.line_number_width = (self.fontw * self.line_number_chars +
432
+ self.line_number_pad * 2)
433
+ else:
434
+ self.line_number_width = 0
435
+ self.hl_lines = []
436
+ hl_lines_str = get_list_opt(options, 'hl_lines', [])
437
+ for line in hl_lines_str:
438
+ try:
439
+ self.hl_lines.append(int(line))
440
+ except ValueError:
441
+ pass
442
+ self.hl_color = options.get('hl_color',
443
+ self.style.highlight_color) or '#f90'
444
+ self.drawables = []
445
+
446
+ def get_style_defs(self, arg=''):
447
+ raise NotImplementedError('The -S option is meaningless for the image '
448
+ 'formatter. Use -O style=<stylename> instead.')
449
+
450
+ def _get_line_height(self):
451
+ """
452
+ Get the height of a line.
453
+ """
454
+ return self.fonth + self.line_pad
455
+
456
+ def _get_line_y(self, lineno):
457
+ """
458
+ Get the Y coordinate of a line number.
459
+ """
460
+ return lineno * self._get_line_height() + self.image_pad
461
+
462
+ def _get_char_width(self):
463
+ """
464
+ Get the width of a character.
465
+ """
466
+ return self.fontw
467
+
468
+ def _get_char_x(self, linelength):
469
+ """
470
+ Get the X coordinate of a character position.
471
+ """
472
+ return linelength + self.image_pad + self.line_number_width
473
+
474
+ def _get_text_pos(self, linelength, lineno):
475
+ """
476
+ Get the actual position for a character and line position.
477
+ """
478
+ return self._get_char_x(linelength), self._get_line_y(lineno)
479
+
480
+ def _get_linenumber_pos(self, lineno):
481
+ """
482
+ Get the actual position for the start of a line number.
483
+ """
484
+ return (self.image_pad, self._get_line_y(lineno))
485
+
486
+ def _get_text_color(self, style):
487
+ """
488
+ Get the correct color for the token from the style.
489
+ """
490
+ if style['color'] is not None:
491
+ fill = '#' + style['color']
492
+ else:
493
+ fill = '#000'
494
+ return fill
495
+
496
+ def _get_text_bg_color(self, style):
497
+ """
498
+ Get the correct background color for the token from the style.
499
+ """
500
+ if style['bgcolor'] is not None:
501
+ bg_color = '#' + style['bgcolor']
502
+ else:
503
+ bg_color = None
504
+ return bg_color
505
+
506
+ def _get_style_font(self, style):
507
+ """
508
+ Get the correct font for the style.
509
+ """
510
+ return self.fonts.get_font(style['bold'], style['italic'])
511
+
512
+ def _get_image_size(self, maxlinelength, maxlineno):
513
+ """
514
+ Get the required image size.
515
+ """
516
+ return (self._get_char_x(maxlinelength) + self.image_pad,
517
+ self._get_line_y(maxlineno + 0) + self.image_pad)
518
+
519
+ def _draw_linenumber(self, posno, lineno):
520
+ """
521
+ Remember a line number drawable to paint later.
522
+ """
523
+ self._draw_text(
524
+ self._get_linenumber_pos(posno),
525
+ str(lineno).rjust(self.line_number_chars),
526
+ font=self.fonts.get_font(self.line_number_bold,
527
+ self.line_number_italic),
528
+ text_fg=self.line_number_fg,
529
+ text_bg=None,
530
+ )
531
+
532
+ def _draw_text(self, pos, text, font, text_fg, text_bg):
533
+ """
534
+ Remember a single drawable tuple to paint later.
535
+ """
536
+ self.drawables.append((pos, text, font, text_fg, text_bg))
537
+
538
+ def _create_drawables(self, tokensource):
539
+ """
540
+ Create drawables for the token content.
541
+ """
542
+ lineno = charno = maxcharno = 0
543
+ maxlinelength = linelength = 0
544
+ for ttype, value in tokensource:
545
+ while ttype not in self.styles:
546
+ ttype = ttype.parent
547
+ style = self.styles[ttype]
548
+ # TODO: make sure tab expansion happens earlier in the chain. It
549
+ # really ought to be done on the input, as to do it right here is
550
+ # quite complex.
551
+ value = value.expandtabs(4)
552
+ lines = value.splitlines(True)
553
+ # print lines
554
+ for i, line in enumerate(lines):
555
+ temp = line.rstrip('\n')
556
+ if temp:
557
+ self._draw_text(
558
+ self._get_text_pos(linelength, lineno),
559
+ temp,
560
+ font = self._get_style_font(style),
561
+ text_fg = self._get_text_color(style),
562
+ text_bg = self._get_text_bg_color(style),
563
+ )
564
+ temp_width, _ = self.fonts.get_text_size(temp)
565
+ linelength += temp_width
566
+ maxlinelength = max(maxlinelength, linelength)
567
+ charno += len(temp)
568
+ maxcharno = max(maxcharno, charno)
569
+ if line.endswith('\n'):
570
+ # add a line for each extra line in the value
571
+ linelength = 0
572
+ charno = 0
573
+ lineno += 1
574
+ self.maxlinelength = maxlinelength
575
+ self.maxcharno = maxcharno
576
+ self.maxlineno = lineno
577
+
578
+ def _draw_line_numbers(self):
579
+ """
580
+ Create drawables for the line numbers.
581
+ """
582
+ if not self.line_numbers:
583
+ return
584
+ for p in range(self.maxlineno):
585
+ n = p + self.line_number_start
586
+ if (n % self.line_number_step) == 0:
587
+ self._draw_linenumber(p, n)
588
+
589
+ def _paint_line_number_bg(self, im):
590
+ """
591
+ Paint the line number background on the image.
592
+ """
593
+ if not self.line_numbers:
594
+ return
595
+ if self.line_number_fg is None:
596
+ return
597
+ draw = ImageDraw.Draw(im)
598
+ recth = im.size[-1]
599
+ rectw = self.image_pad + self.line_number_width - self.line_number_pad
600
+ draw.rectangle([(0, 0), (rectw, recth)],
601
+ fill=self.line_number_bg)
602
+ if self.line_number_separator:
603
+ draw.line([(rectw, 0), (rectw, recth)], fill=self.line_number_fg)
604
+ del draw
605
+
606
+ def format(self, tokensource, outfile):
607
+ """
608
+ Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
609
+ tuples and write it into ``outfile``.
610
+
611
+ This implementation calculates where it should draw each token on the
612
+ pixmap, then calculates the required pixmap size and draws the items.
613
+ """
614
+ self._create_drawables(tokensource)
615
+ self._draw_line_numbers()
616
+ im = Image.new(
617
+ 'RGB',
618
+ self._get_image_size(self.maxlinelength, self.maxlineno),
619
+ self.background_color
620
+ )
621
+ self._paint_line_number_bg(im)
622
+ draw = ImageDraw.Draw(im)
623
+ # Highlight
624
+ if self.hl_lines:
625
+ x = self.image_pad + self.line_number_width - self.line_number_pad + 1
626
+ recth = self._get_line_height()
627
+ rectw = im.size[0] - x
628
+ for linenumber in self.hl_lines:
629
+ y = self._get_line_y(linenumber - 1)
630
+ draw.rectangle([(x, y), (x + rectw, y + recth)],
631
+ fill=self.hl_color)
632
+ for pos, value, font, text_fg, text_bg in self.drawables:
633
+ if text_bg:
634
+ # see deprecations https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
635
+ if hasattr(draw, 'textsize'):
636
+ text_size = draw.textsize(text=value, font=font)
637
+ else:
638
+ text_size = font.getbbox(value)[2:]
639
+ draw.rectangle([pos[0], pos[1], pos[0] + text_size[0], pos[1] + text_size[1]], fill=text_bg)
640
+ draw.text(pos, value, font=font, fill=text_fg)
641
+ im.save(outfile, self.image_format.upper())
642
+
643
+
644
+ # Add one formatter per format, so that the "-f gif" option gives the correct result
645
+ # when used in pygmentize.
646
+
647
+ class GifImageFormatter(ImageFormatter):
648
+ """
649
+ Create a GIF image from source code. This uses the Python Imaging Library to
650
+ generate a pixmap from the source code.
651
+
652
+ .. versionadded:: 1.0
653
+ """
654
+
655
+ name = 'img_gif'
656
+ aliases = ['gif']
657
+ filenames = ['*.gif']
658
+ default_image_format = 'gif'
659
+
660
+
661
+ class JpgImageFormatter(ImageFormatter):
662
+ """
663
+ Create a JPEG image from source code. This uses the Python Imaging Library to
664
+ generate a pixmap from the source code.
665
+
666
+ .. versionadded:: 1.0
667
+ """
668
+
669
+ name = 'img_jpg'
670
+ aliases = ['jpg', 'jpeg']
671
+ filenames = ['*.jpg']
672
+ default_image_format = 'jpeg'
673
+
674
+
675
+ class BmpImageFormatter(ImageFormatter):
676
+ """
677
+ Create a bitmap image from source code. This uses the Python Imaging Library to
678
+ generate a pixmap from the source code.
679
+
680
+ .. versionadded:: 1.0
681
+ """
682
+
683
+ name = 'img_bmp'
684
+ aliases = ['bmp', 'bitmap']
685
+ filenames = ['*.bmp']
686
+ default_image_format = 'bmp'
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/irc.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.irc
3
+ ~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Formatter for IRC output
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ from pygments.formatter import Formatter
12
+ from pygments.token import Keyword, Name, Comment, String, Error, \
13
+ Number, Operator, Generic, Token, Whitespace
14
+ from pygments.util import get_choice_opt
15
+
16
+
17
+ __all__ = ['IRCFormatter']
18
+
19
+
20
+ #: Map token types to a tuple of color values for light and dark
21
+ #: backgrounds.
22
+ IRC_COLORS = {
23
+ Token: ('', ''),
24
+
25
+ Whitespace: ('gray', 'brightblack'),
26
+ Comment: ('gray', 'brightblack'),
27
+ Comment.Preproc: ('cyan', 'brightcyan'),
28
+ Keyword: ('blue', 'brightblue'),
29
+ Keyword.Type: ('cyan', 'brightcyan'),
30
+ Operator.Word: ('magenta', 'brightcyan'),
31
+ Name.Builtin: ('cyan', 'brightcyan'),
32
+ Name.Function: ('green', 'brightgreen'),
33
+ Name.Namespace: ('_cyan_', '_brightcyan_'),
34
+ Name.Class: ('_green_', '_brightgreen_'),
35
+ Name.Exception: ('cyan', 'brightcyan'),
36
+ Name.Decorator: ('brightblack', 'gray'),
37
+ Name.Variable: ('red', 'brightred'),
38
+ Name.Constant: ('red', 'brightred'),
39
+ Name.Attribute: ('cyan', 'brightcyan'),
40
+ Name.Tag: ('brightblue', 'brightblue'),
41
+ String: ('yellow', 'yellow'),
42
+ Number: ('blue', 'brightblue'),
43
+
44
+ Generic.Deleted: ('brightred', 'brightred'),
45
+ Generic.Inserted: ('green', 'brightgreen'),
46
+ Generic.Heading: ('**', '**'),
47
+ Generic.Subheading: ('*magenta*', '*brightmagenta*'),
48
+ Generic.Error: ('brightred', 'brightred'),
49
+
50
+ Error: ('_brightred_', '_brightred_'),
51
+ }
52
+
53
+
54
+ IRC_COLOR_MAP = {
55
+ 'white': 0,
56
+ 'black': 1,
57
+ 'blue': 2,
58
+ 'brightgreen': 3,
59
+ 'brightred': 4,
60
+ 'yellow': 5,
61
+ 'magenta': 6,
62
+ 'orange': 7,
63
+ 'green': 7, #compat w/ ansi
64
+ 'brightyellow': 8,
65
+ 'lightgreen': 9,
66
+ 'brightcyan': 9, # compat w/ ansi
67
+ 'cyan': 10,
68
+ 'lightblue': 11,
69
+ 'red': 11, # compat w/ ansi
70
+ 'brightblue': 12,
71
+ 'brightmagenta': 13,
72
+ 'brightblack': 14,
73
+ 'gray': 15,
74
+ }
75
+
76
+ def ircformat(color, text):
77
+ if len(color) < 1:
78
+ return text
79
+ add = sub = ''
80
+ if '_' in color: # italic
81
+ add += '\x1D'
82
+ sub = '\x1D' + sub
83
+ color = color.strip('_')
84
+ if '*' in color: # bold
85
+ add += '\x02'
86
+ sub = '\x02' + sub
87
+ color = color.strip('*')
88
+ # underline (\x1F) not supported
89
+ # backgrounds (\x03FF,BB) not supported
90
+ if len(color) > 0: # actual color - may have issues with ircformat("red", "blah")+"10" type stuff
91
+ add += '\x03' + str(IRC_COLOR_MAP[color]).zfill(2)
92
+ sub = '\x03' + sub
93
+ return add + text + sub
94
+ return '<'+add+'>'+text+'</'+sub+'>'
95
+
96
+
97
+ class IRCFormatter(Formatter):
98
+ r"""
99
+ Format tokens with IRC color sequences
100
+
101
+ The `get_style_defs()` method doesn't do anything special since there is
102
+ no support for common styles.
103
+
104
+ Options accepted:
105
+
106
+ `bg`
107
+ Set to ``"light"`` or ``"dark"`` depending on the terminal's background
108
+ (default: ``"light"``).
109
+
110
+ `colorscheme`
111
+ A dictionary mapping token types to (lightbg, darkbg) color names or
112
+ ``None`` (default: ``None`` = use builtin colorscheme).
113
+
114
+ `linenos`
115
+ Set to ``True`` to have line numbers in the output as well
116
+ (default: ``False`` = no line numbers).
117
+ """
118
+ name = 'IRC'
119
+ aliases = ['irc', 'IRC']
120
+ filenames = []
121
+
122
+ def __init__(self, **options):
123
+ Formatter.__init__(self, **options)
124
+ self.darkbg = get_choice_opt(options, 'bg',
125
+ ['light', 'dark'], 'light') == 'dark'
126
+ self.colorscheme = options.get('colorscheme', None) or IRC_COLORS
127
+ self.linenos = options.get('linenos', False)
128
+ self._lineno = 0
129
+
130
+ def _write_lineno(self, outfile):
131
+ if self.linenos:
132
+ self._lineno += 1
133
+ outfile.write("%04d: " % self._lineno)
134
+
135
+ def format_unencoded(self, tokensource, outfile):
136
+ self._write_lineno(outfile)
137
+
138
+ for ttype, value in tokensource:
139
+ color = self.colorscheme.get(ttype)
140
+ while color is None:
141
+ ttype = ttype[:-1]
142
+ color = self.colorscheme.get(ttype)
143
+ if color:
144
+ color = color[self.darkbg]
145
+ spl = value.split('\n')
146
+ for line in spl[:-1]:
147
+ if line:
148
+ outfile.write(ircformat(color, line))
149
+ outfile.write('\n')
150
+ self._write_lineno(outfile)
151
+ if spl[-1]:
152
+ outfile.write(ircformat(color, spl[-1]))
153
+ else:
154
+ outfile.write(value)
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/latex.py ADDED
@@ -0,0 +1,518 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.latex
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Formatter for LaTeX fancyvrb output.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ from io import StringIO
12
+
13
+ from pygments.formatter import Formatter
14
+ from pygments.lexer import Lexer, do_insertions
15
+ from pygments.token import Token, STANDARD_TYPES
16
+ from pygments.util import get_bool_opt, get_int_opt
17
+
18
+
19
+ __all__ = ['LatexFormatter']
20
+
21
+
22
+ def escape_tex(text, commandprefix):
23
+ return text.replace('\\', '\x00'). \
24
+ replace('{', '\x01'). \
25
+ replace('}', '\x02'). \
26
+ replace('\x00', rf'\{commandprefix}Zbs{{}}'). \
27
+ replace('\x01', rf'\{commandprefix}Zob{{}}'). \
28
+ replace('\x02', rf'\{commandprefix}Zcb{{}}'). \
29
+ replace('^', rf'\{commandprefix}Zca{{}}'). \
30
+ replace('_', rf'\{commandprefix}Zus{{}}'). \
31
+ replace('&', rf'\{commandprefix}Zam{{}}'). \
32
+ replace('<', rf'\{commandprefix}Zlt{{}}'). \
33
+ replace('>', rf'\{commandprefix}Zgt{{}}'). \
34
+ replace('#', rf'\{commandprefix}Zsh{{}}'). \
35
+ replace('%', rf'\{commandprefix}Zpc{{}}'). \
36
+ replace('$', rf'\{commandprefix}Zdl{{}}'). \
37
+ replace('-', rf'\{commandprefix}Zhy{{}}'). \
38
+ replace("'", rf'\{commandprefix}Zsq{{}}'). \
39
+ replace('"', rf'\{commandprefix}Zdq{{}}'). \
40
+ replace('~', rf'\{commandprefix}Zti{{}}')
41
+
42
+
43
+ DOC_TEMPLATE = r'''
44
+ \documentclass{%(docclass)s}
45
+ \usepackage{fancyvrb}
46
+ \usepackage{color}
47
+ \usepackage[%(encoding)s]{inputenc}
48
+ %(preamble)s
49
+
50
+ %(styledefs)s
51
+
52
+ \begin{document}
53
+
54
+ \section*{%(title)s}
55
+
56
+ %(code)s
57
+ \end{document}
58
+ '''
59
+
60
+ ## Small explanation of the mess below :)
61
+ #
62
+ # The previous version of the LaTeX formatter just assigned a command to
63
+ # each token type defined in the current style. That obviously is
64
+ # problematic if the highlighted code is produced for a different style
65
+ # than the style commands themselves.
66
+ #
67
+ # This version works much like the HTML formatter which assigns multiple
68
+ # CSS classes to each <span> tag, from the most specific to the least
69
+ # specific token type, thus falling back to the parent token type if one
70
+ # is not defined. Here, the classes are there too and use the same short
71
+ # forms given in token.STANDARD_TYPES.
72
+ #
73
+ # Highlighted code now only uses one custom command, which by default is
74
+ # \PY and selectable by the commandprefix option (and in addition the
75
+ # escapes \PYZat, \PYZlb and \PYZrb which haven't been renamed for
76
+ # backwards compatibility purposes).
77
+ #
78
+ # \PY has two arguments: the classes, separated by +, and the text to
79
+ # render in that style. The classes are resolved into the respective
80
+ # style commands by magic, which serves to ignore unknown classes.
81
+ #
82
+ # The magic macros are:
83
+ # * \PY@it, \PY@bf, etc. are unconditionally wrapped around the text
84
+ # to render in \PY@do. Their definition determines the style.
85
+ # * \PY@reset resets \PY@it etc. to do nothing.
86
+ # * \PY@toks parses the list of classes, using magic inspired by the
87
+ # keyval package (but modified to use plusses instead of commas
88
+ # because fancyvrb redefines commas inside its environments).
89
+ # * \PY@tok processes one class, calling the \PY@tok@classname command
90
+ # if it exists.
91
+ # * \PY@tok@classname sets the \PY@it etc. to reflect the chosen style
92
+ # for its class.
93
+ # * \PY resets the style, parses the classnames and then calls \PY@do.
94
+ #
95
+ # Tip: to read this code, print it out in substituted form using e.g.
96
+ # >>> print STYLE_TEMPLATE % {'cp': 'PY'}
97
+
98
+ STYLE_TEMPLATE = r'''
99
+ \makeatletter
100
+ \def\%(cp)s@reset{\let\%(cp)s@it=\relax \let\%(cp)s@bf=\relax%%
101
+ \let\%(cp)s@ul=\relax \let\%(cp)s@tc=\relax%%
102
+ \let\%(cp)s@bc=\relax \let\%(cp)s@ff=\relax}
103
+ \def\%(cp)s@tok#1{\csname %(cp)s@tok@#1\endcsname}
104
+ \def\%(cp)s@toks#1+{\ifx\relax#1\empty\else%%
105
+ \%(cp)s@tok{#1}\expandafter\%(cp)s@toks\fi}
106
+ \def\%(cp)s@do#1{\%(cp)s@bc{\%(cp)s@tc{\%(cp)s@ul{%%
107
+ \%(cp)s@it{\%(cp)s@bf{\%(cp)s@ff{#1}}}}}}}
108
+ \def\%(cp)s#1#2{\%(cp)s@reset\%(cp)s@toks#1+\relax+\%(cp)s@do{#2}}
109
+
110
+ %(styles)s
111
+
112
+ \def\%(cp)sZbs{\char`\\}
113
+ \def\%(cp)sZus{\char`\_}
114
+ \def\%(cp)sZob{\char`\{}
115
+ \def\%(cp)sZcb{\char`\}}
116
+ \def\%(cp)sZca{\char`\^}
117
+ \def\%(cp)sZam{\char`\&}
118
+ \def\%(cp)sZlt{\char`\<}
119
+ \def\%(cp)sZgt{\char`\>}
120
+ \def\%(cp)sZsh{\char`\#}
121
+ \def\%(cp)sZpc{\char`\%%}
122
+ \def\%(cp)sZdl{\char`\$}
123
+ \def\%(cp)sZhy{\char`\-}
124
+ \def\%(cp)sZsq{\char`\'}
125
+ \def\%(cp)sZdq{\char`\"}
126
+ \def\%(cp)sZti{\char`\~}
127
+ %% for compatibility with earlier versions
128
+ \def\%(cp)sZat{@}
129
+ \def\%(cp)sZlb{[}
130
+ \def\%(cp)sZrb{]}
131
+ \makeatother
132
+ '''
133
+
134
+
135
+ def _get_ttype_name(ttype):
136
+ fname = STANDARD_TYPES.get(ttype)
137
+ if fname:
138
+ return fname
139
+ aname = ''
140
+ while fname is None:
141
+ aname = ttype[-1] + aname
142
+ ttype = ttype.parent
143
+ fname = STANDARD_TYPES.get(ttype)
144
+ return fname + aname
145
+
146
+
147
+ class LatexFormatter(Formatter):
148
+ r"""
149
+ Format tokens as LaTeX code. This needs the `fancyvrb` and `color`
150
+ standard packages.
151
+
152
+ Without the `full` option, code is formatted as one ``Verbatim``
153
+ environment, like this:
154
+
155
+ .. sourcecode:: latex
156
+
157
+ \begin{Verbatim}[commandchars=\\\{\}]
158
+ \PY{k}{def }\PY{n+nf}{foo}(\PY{n}{bar}):
159
+ \PY{k}{pass}
160
+ \end{Verbatim}
161
+
162
+ Wrapping can be disabled using the `nowrap` option.
163
+
164
+ The special command used here (``\PY``) and all the other macros it needs
165
+ are output by the `get_style_defs` method.
166
+
167
+ With the `full` option, a complete LaTeX document is output, including
168
+ the command definitions in the preamble.
169
+
170
+ The `get_style_defs()` method of a `LatexFormatter` returns a string
171
+ containing ``\def`` commands defining the macros needed inside the
172
+ ``Verbatim`` environments.
173
+
174
+ Additional options accepted:
175
+
176
+ `nowrap`
177
+ If set to ``True``, don't wrap the tokens at all, not even inside a
178
+ ``\begin{Verbatim}`` environment. This disables most other options
179
+ (default: ``False``).
180
+
181
+ `style`
182
+ The style to use, can be a string or a Style subclass (default:
183
+ ``'default'``).
184
+
185
+ `full`
186
+ Tells the formatter to output a "full" document, i.e. a complete
187
+ self-contained document (default: ``False``).
188
+
189
+ `title`
190
+ If `full` is true, the title that should be used to caption the
191
+ document (default: ``''``).
192
+
193
+ `docclass`
194
+ If the `full` option is enabled, this is the document class to use
195
+ (default: ``'article'``).
196
+
197
+ `preamble`
198
+ If the `full` option is enabled, this can be further preamble commands,
199
+ e.g. ``\usepackage`` (default: ``''``).
200
+
201
+ `linenos`
202
+ If set to ``True``, output line numbers (default: ``False``).
203
+
204
+ `linenostart`
205
+ The line number for the first line (default: ``1``).
206
+
207
+ `linenostep`
208
+ If set to a number n > 1, only every nth line number is printed.
209
+
210
+ `verboptions`
211
+ Additional options given to the Verbatim environment (see the *fancyvrb*
212
+ docs for possible values) (default: ``''``).
213
+
214
+ `commandprefix`
215
+ The LaTeX commands used to produce colored output are constructed
216
+ using this prefix and some letters (default: ``'PY'``).
217
+
218
+ .. versionadded:: 0.7
219
+ .. versionchanged:: 0.10
220
+ The default is now ``'PY'`` instead of ``'C'``.
221
+
222
+ `texcomments`
223
+ If set to ``True``, enables LaTeX comment lines. That is, LaTex markup
224
+ in comment tokens is not escaped so that LaTeX can render it (default:
225
+ ``False``).
226
+
227
+ .. versionadded:: 1.2
228
+
229
+ `mathescape`
230
+ If set to ``True``, enables LaTeX math mode escape in comments. That
231
+ is, ``'$...$'`` inside a comment will trigger math mode (default:
232
+ ``False``).
233
+
234
+ .. versionadded:: 1.2
235
+
236
+ `escapeinside`
237
+ If set to a string of length 2, enables escaping to LaTeX. Text
238
+ delimited by these 2 characters is read as LaTeX code and
239
+ typeset accordingly. It has no effect in string literals. It has
240
+ no effect in comments if `texcomments` or `mathescape` is
241
+ set. (default: ``''``).
242
+
243
+ .. versionadded:: 2.0
244
+
245
+ `envname`
246
+ Allows you to pick an alternative environment name replacing Verbatim.
247
+ The alternate environment still has to support Verbatim's option syntax.
248
+ (default: ``'Verbatim'``).
249
+
250
+ .. versionadded:: 2.0
251
+ """
252
+ name = 'LaTeX'
253
+ aliases = ['latex', 'tex']
254
+ filenames = ['*.tex']
255
+
256
+ def __init__(self, **options):
257
+ Formatter.__init__(self, **options)
258
+ self.nowrap = get_bool_opt(options, 'nowrap', False)
259
+ self.docclass = options.get('docclass', 'article')
260
+ self.preamble = options.get('preamble', '')
261
+ self.linenos = get_bool_opt(options, 'linenos', False)
262
+ self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
263
+ self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
264
+ self.verboptions = options.get('verboptions', '')
265
+ self.nobackground = get_bool_opt(options, 'nobackground', False)
266
+ self.commandprefix = options.get('commandprefix', 'PY')
267
+ self.texcomments = get_bool_opt(options, 'texcomments', False)
268
+ self.mathescape = get_bool_opt(options, 'mathescape', False)
269
+ self.escapeinside = options.get('escapeinside', '')
270
+ if len(self.escapeinside) == 2:
271
+ self.left = self.escapeinside[0]
272
+ self.right = self.escapeinside[1]
273
+ else:
274
+ self.escapeinside = ''
275
+ self.envname = options.get('envname', 'Verbatim')
276
+
277
+ self._create_stylesheet()
278
+
279
+ def _create_stylesheet(self):
280
+ t2n = self.ttype2name = {Token: ''}
281
+ c2d = self.cmd2def = {}
282
+ cp = self.commandprefix
283
+
284
+ def rgbcolor(col):
285
+ if col:
286
+ return ','.join(['%.2f' % (int(col[i] + col[i + 1], 16) / 255.0)
287
+ for i in (0, 2, 4)])
288
+ else:
289
+ return '1,1,1'
290
+
291
+ for ttype, ndef in self.style:
292
+ name = _get_ttype_name(ttype)
293
+ cmndef = ''
294
+ if ndef['bold']:
295
+ cmndef += r'\let\$$@bf=\textbf'
296
+ if ndef['italic']:
297
+ cmndef += r'\let\$$@it=\textit'
298
+ if ndef['underline']:
299
+ cmndef += r'\let\$$@ul=\underline'
300
+ if ndef['roman']:
301
+ cmndef += r'\let\$$@ff=\textrm'
302
+ if ndef['sans']:
303
+ cmndef += r'\let\$$@ff=\textsf'
304
+ if ndef['mono']:
305
+ cmndef += r'\let\$$@ff=\textsf'
306
+ if ndef['color']:
307
+ cmndef += (r'\def\$$@tc##1{{\textcolor[rgb]{{{}}}{{##1}}}}'.format(rgbcolor(ndef['color'])))
308
+ if ndef['border']:
309
+ cmndef += (r'\def\$$@bc##1{{{{\setlength{{\fboxsep}}{{\string -\fboxrule}}'
310
+ r'\fcolorbox[rgb]{{{}}}{{{}}}{{\strut ##1}}}}}}'.format(rgbcolor(ndef['border']),
311
+ rgbcolor(ndef['bgcolor'])))
312
+ elif ndef['bgcolor']:
313
+ cmndef += (r'\def\$$@bc##1{{{{\setlength{{\fboxsep}}{{0pt}}'
314
+ r'\colorbox[rgb]{{{}}}{{\strut ##1}}}}}}'.format(rgbcolor(ndef['bgcolor'])))
315
+ if cmndef == '':
316
+ continue
317
+ cmndef = cmndef.replace('$$', cp)
318
+ t2n[ttype] = name
319
+ c2d[name] = cmndef
320
+
321
+ def get_style_defs(self, arg=''):
322
+ """
323
+ Return the command sequences needed to define the commands
324
+ used to format text in the verbatim environment. ``arg`` is ignored.
325
+ """
326
+ cp = self.commandprefix
327
+ styles = []
328
+ for name, definition in self.cmd2def.items():
329
+ styles.append(rf'\@namedef{{{cp}@tok@{name}}}{{{definition}}}')
330
+ return STYLE_TEMPLATE % {'cp': self.commandprefix,
331
+ 'styles': '\n'.join(styles)}
332
+
333
+ def format_unencoded(self, tokensource, outfile):
334
+ # TODO: add support for background colors
335
+ t2n = self.ttype2name
336
+ cp = self.commandprefix
337
+
338
+ if self.full:
339
+ realoutfile = outfile
340
+ outfile = StringIO()
341
+
342
+ if not self.nowrap:
343
+ outfile.write('\\begin{' + self.envname + '}[commandchars=\\\\\\{\\}')
344
+ if self.linenos:
345
+ start, step = self.linenostart, self.linenostep
346
+ outfile.write(',numbers=left' +
347
+ (start and ',firstnumber=%d' % start or '') +
348
+ (step and ',stepnumber=%d' % step or ''))
349
+ if self.mathescape or self.texcomments or self.escapeinside:
350
+ outfile.write(',codes={\\catcode`\\$=3\\catcode`\\^=7'
351
+ '\\catcode`\\_=8\\relax}')
352
+ if self.verboptions:
353
+ outfile.write(',' + self.verboptions)
354
+ outfile.write(']\n')
355
+
356
+ for ttype, value in tokensource:
357
+ if ttype in Token.Comment:
358
+ if self.texcomments:
359
+ # Try to guess comment starting lexeme and escape it ...
360
+ start = value[0:1]
361
+ for i in range(1, len(value)):
362
+ if start[0] != value[i]:
363
+ break
364
+ start += value[i]
365
+
366
+ value = value[len(start):]
367
+ start = escape_tex(start, cp)
368
+
369
+ # ... but do not escape inside comment.
370
+ value = start + value
371
+ elif self.mathescape:
372
+ # Only escape parts not inside a math environment.
373
+ parts = value.split('$')
374
+ in_math = False
375
+ for i, part in enumerate(parts):
376
+ if not in_math:
377
+ parts[i] = escape_tex(part, cp)
378
+ in_math = not in_math
379
+ value = '$'.join(parts)
380
+ elif self.escapeinside:
381
+ text = value
382
+ value = ''
383
+ while text:
384
+ a, sep1, text = text.partition(self.left)
385
+ if sep1:
386
+ b, sep2, text = text.partition(self.right)
387
+ if sep2:
388
+ value += escape_tex(a, cp) + b
389
+ else:
390
+ value += escape_tex(a + sep1 + b, cp)
391
+ else:
392
+ value += escape_tex(a, cp)
393
+ else:
394
+ value = escape_tex(value, cp)
395
+ elif ttype not in Token.Escape:
396
+ value = escape_tex(value, cp)
397
+ styles = []
398
+ while ttype is not Token:
399
+ try:
400
+ styles.append(t2n[ttype])
401
+ except KeyError:
402
+ # not in current style
403
+ styles.append(_get_ttype_name(ttype))
404
+ ttype = ttype.parent
405
+ styleval = '+'.join(reversed(styles))
406
+ if styleval:
407
+ spl = value.split('\n')
408
+ for line in spl[:-1]:
409
+ if line:
410
+ outfile.write(f"\\{cp}{{{styleval}}}{{{line}}}")
411
+ outfile.write('\n')
412
+ if spl[-1]:
413
+ outfile.write(f"\\{cp}{{{styleval}}}{{{spl[-1]}}}")
414
+ else:
415
+ outfile.write(value)
416
+
417
+ if not self.nowrap:
418
+ outfile.write('\\end{' + self.envname + '}\n')
419
+
420
+ if self.full:
421
+ encoding = self.encoding or 'utf8'
422
+ # map known existings encodings from LaTeX distribution
423
+ encoding = {
424
+ 'utf_8': 'utf8',
425
+ 'latin_1': 'latin1',
426
+ 'iso_8859_1': 'latin1',
427
+ }.get(encoding.replace('-', '_'), encoding)
428
+ realoutfile.write(DOC_TEMPLATE %
429
+ dict(docclass = self.docclass,
430
+ preamble = self.preamble,
431
+ title = self.title,
432
+ encoding = encoding,
433
+ styledefs = self.get_style_defs(),
434
+ code = outfile.getvalue()))
435
+
436
+
437
+ class LatexEmbeddedLexer(Lexer):
438
+ """
439
+ This lexer takes one lexer as argument, the lexer for the language
440
+ being formatted, and the left and right delimiters for escaped text.
441
+
442
+ First everything is scanned using the language lexer to obtain
443
+ strings and comments. All other consecutive tokens are merged and
444
+ the resulting text is scanned for escaped segments, which are given
445
+ the Token.Escape type. Finally text that is not escaped is scanned
446
+ again with the language lexer.
447
+ """
448
+ def __init__(self, left, right, lang, **options):
449
+ self.left = left
450
+ self.right = right
451
+ self.lang = lang
452
+ Lexer.__init__(self, **options)
453
+
454
+ def get_tokens_unprocessed(self, text):
455
+ # find and remove all the escape tokens (replace with an empty string)
456
+ # this is very similar to DelegatingLexer.get_tokens_unprocessed.
457
+ buffered = ''
458
+ insertions = []
459
+ insertion_buf = []
460
+ for i, t, v in self._find_safe_escape_tokens(text):
461
+ if t is None:
462
+ if insertion_buf:
463
+ insertions.append((len(buffered), insertion_buf))
464
+ insertion_buf = []
465
+ buffered += v
466
+ else:
467
+ insertion_buf.append((i, t, v))
468
+ if insertion_buf:
469
+ insertions.append((len(buffered), insertion_buf))
470
+ return do_insertions(insertions,
471
+ self.lang.get_tokens_unprocessed(buffered))
472
+
473
+ def _find_safe_escape_tokens(self, text):
474
+ """ find escape tokens that are not in strings or comments """
475
+ for i, t, v in self._filter_to(
476
+ self.lang.get_tokens_unprocessed(text),
477
+ lambda t: t in Token.Comment or t in Token.String
478
+ ):
479
+ if t is None:
480
+ for i2, t2, v2 in self._find_escape_tokens(v):
481
+ yield i + i2, t2, v2
482
+ else:
483
+ yield i, None, v
484
+
485
+ def _filter_to(self, it, pred):
486
+ """ Keep only the tokens that match `pred`, merge the others together """
487
+ buf = ''
488
+ idx = 0
489
+ for i, t, v in it:
490
+ if pred(t):
491
+ if buf:
492
+ yield idx, None, buf
493
+ buf = ''
494
+ yield i, t, v
495
+ else:
496
+ if not buf:
497
+ idx = i
498
+ buf += v
499
+ if buf:
500
+ yield idx, None, buf
501
+
502
+ def _find_escape_tokens(self, text):
503
+ """ Find escape tokens within text, give token=None otherwise """
504
+ index = 0
505
+ while text:
506
+ a, sep1, text = text.partition(self.left)
507
+ if a:
508
+ yield index, None, a
509
+ index += len(a)
510
+ if sep1:
511
+ b, sep2, text = text.partition(self.right)
512
+ if sep2:
513
+ yield index + len(sep1), Token.Escape, b
514
+ index += len(sep1) + len(b) + len(sep2)
515
+ else:
516
+ yield index, Token.Error, sep1
517
+ index += len(sep1)
518
+ text = b
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/other.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.other
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Other formatters: NullFormatter, RawTokenFormatter.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ from pygments.formatter import Formatter
12
+ from pygments.util import get_choice_opt
13
+ from pygments.token import Token
14
+ from pygments.console import colorize
15
+
16
+ __all__ = ['NullFormatter', 'RawTokenFormatter', 'TestcaseFormatter']
17
+
18
+
19
+ class NullFormatter(Formatter):
20
+ """
21
+ Output the text unchanged without any formatting.
22
+ """
23
+ name = 'Text only'
24
+ aliases = ['text', 'null']
25
+ filenames = ['*.txt']
26
+
27
+ def format(self, tokensource, outfile):
28
+ enc = self.encoding
29
+ for ttype, value in tokensource:
30
+ if enc:
31
+ outfile.write(value.encode(enc))
32
+ else:
33
+ outfile.write(value)
34
+
35
+
36
+ class RawTokenFormatter(Formatter):
37
+ r"""
38
+ Format tokens as a raw representation for storing token streams.
39
+
40
+ The format is ``tokentype<TAB>repr(tokenstring)\n``. The output can later
41
+ be converted to a token stream with the `RawTokenLexer`, described in the
42
+ :doc:`lexer list <lexers>`.
43
+
44
+ Only two options are accepted:
45
+
46
+ `compress`
47
+ If set to ``'gz'`` or ``'bz2'``, compress the output with the given
48
+ compression algorithm after encoding (default: ``''``).
49
+ `error_color`
50
+ If set to a color name, highlight error tokens using that color. If
51
+ set but with no value, defaults to ``'red'``.
52
+
53
+ .. versionadded:: 0.11
54
+
55
+ """
56
+ name = 'Raw tokens'
57
+ aliases = ['raw', 'tokens']
58
+ filenames = ['*.raw']
59
+
60
+ unicodeoutput = False
61
+
62
+ def __init__(self, **options):
63
+ Formatter.__init__(self, **options)
64
+ # We ignore self.encoding if it is set, since it gets set for lexer
65
+ # and formatter if given with -Oencoding on the command line.
66
+ # The RawTokenFormatter outputs only ASCII. Override here.
67
+ self.encoding = 'ascii' # let pygments.format() do the right thing
68
+ self.compress = get_choice_opt(options, 'compress',
69
+ ['', 'none', 'gz', 'bz2'], '')
70
+ self.error_color = options.get('error_color', None)
71
+ if self.error_color is True:
72
+ self.error_color = 'red'
73
+ if self.error_color is not None:
74
+ try:
75
+ colorize(self.error_color, '')
76
+ except KeyError:
77
+ raise ValueError(f"Invalid color {self.error_color!r} specified")
78
+
79
+ def format(self, tokensource, outfile):
80
+ try:
81
+ outfile.write(b'')
82
+ except TypeError:
83
+ raise TypeError('The raw tokens formatter needs a binary '
84
+ 'output file')
85
+ if self.compress == 'gz':
86
+ import gzip
87
+ outfile = gzip.GzipFile('', 'wb', 9, outfile)
88
+
89
+ write = outfile.write
90
+ flush = outfile.close
91
+ elif self.compress == 'bz2':
92
+ import bz2
93
+ compressor = bz2.BZ2Compressor(9)
94
+
95
+ def write(text):
96
+ outfile.write(compressor.compress(text))
97
+
98
+ def flush():
99
+ outfile.write(compressor.flush())
100
+ outfile.flush()
101
+ else:
102
+ write = outfile.write
103
+ flush = outfile.flush
104
+
105
+ if self.error_color:
106
+ for ttype, value in tokensource:
107
+ line = b"%r\t%r\n" % (ttype, value)
108
+ if ttype is Token.Error:
109
+ write(colorize(self.error_color, line))
110
+ else:
111
+ write(line)
112
+ else:
113
+ for ttype, value in tokensource:
114
+ write(b"%r\t%r\n" % (ttype, value))
115
+ flush()
116
+
117
+
118
+ TESTCASE_BEFORE = '''\
119
+ def testNeedsName(lexer):
120
+ fragment = %r
121
+ tokens = [
122
+ '''
123
+ TESTCASE_AFTER = '''\
124
+ ]
125
+ assert list(lexer.get_tokens(fragment)) == tokens
126
+ '''
127
+
128
+
129
+ class TestcaseFormatter(Formatter):
130
+ """
131
+ Format tokens as appropriate for a new testcase.
132
+
133
+ .. versionadded:: 2.0
134
+ """
135
+ name = 'Testcase'
136
+ aliases = ['testcase']
137
+
138
+ def __init__(self, **options):
139
+ Formatter.__init__(self, **options)
140
+ if self.encoding is not None and self.encoding != 'utf-8':
141
+ raise ValueError("Only None and utf-8 are allowed encodings.")
142
+
143
+ def format(self, tokensource, outfile):
144
+ indentation = ' ' * 12
145
+ rawbuf = []
146
+ outbuf = []
147
+ for ttype, value in tokensource:
148
+ rawbuf.append(value)
149
+ outbuf.append(f'{indentation}({ttype}, {value!r}),\n')
150
+
151
+ before = TESTCASE_BEFORE % (''.join(rawbuf),)
152
+ during = ''.join(outbuf)
153
+ after = TESTCASE_AFTER
154
+ if self.encoding is None:
155
+ outfile.write(before + during + after)
156
+ else:
157
+ outfile.write(before.encode('utf-8'))
158
+ outfile.write(during.encode('utf-8'))
159
+ outfile.write(after.encode('utf-8'))
160
+ outfile.flush()
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/pangomarkup.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.pangomarkup
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Formatter for Pango markup output.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ from pygments.formatter import Formatter
12
+
13
+
14
+ __all__ = ['PangoMarkupFormatter']
15
+
16
+
17
+ _escape_table = {
18
+ ord('&'): '&amp;',
19
+ ord('<'): '&lt;',
20
+ }
21
+
22
+
23
+ def escape_special_chars(text, table=_escape_table):
24
+ """Escape & and < for Pango Markup."""
25
+ return text.translate(table)
26
+
27
+
28
+ class PangoMarkupFormatter(Formatter):
29
+ """
30
+ Format tokens as Pango Markup code. It can then be rendered to an SVG.
31
+
32
+ .. versionadded:: 2.9
33
+ """
34
+
35
+ name = 'Pango Markup'
36
+ aliases = ['pango', 'pangomarkup']
37
+ filenames = []
38
+
39
+ def __init__(self, **options):
40
+ Formatter.__init__(self, **options)
41
+
42
+ self.styles = {}
43
+
44
+ for token, style in self.style:
45
+ start = ''
46
+ end = ''
47
+ if style['color']:
48
+ start += '<span fgcolor="#{}">'.format(style['color'])
49
+ end = '</span>' + end
50
+ if style['bold']:
51
+ start += '<b>'
52
+ end = '</b>' + end
53
+ if style['italic']:
54
+ start += '<i>'
55
+ end = '</i>' + end
56
+ if style['underline']:
57
+ start += '<u>'
58
+ end = '</u>' + end
59
+ self.styles[token] = (start, end)
60
+
61
+ def format_unencoded(self, tokensource, outfile):
62
+ lastval = ''
63
+ lasttype = None
64
+
65
+ outfile.write('<tt>')
66
+
67
+ for ttype, value in tokensource:
68
+ while ttype not in self.styles:
69
+ ttype = ttype.parent
70
+ if ttype == lasttype:
71
+ lastval += escape_special_chars(value)
72
+ else:
73
+ if lastval:
74
+ stylebegin, styleend = self.styles[lasttype]
75
+ outfile.write(stylebegin + lastval + styleend)
76
+ lastval = escape_special_chars(value)
77
+ lasttype = ttype
78
+
79
+ if lastval:
80
+ stylebegin, styleend = self.styles[lasttype]
81
+ outfile.write(stylebegin + lastval + styleend)
82
+
83
+ outfile.write('</tt>')
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/rtf.py ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.rtf
3
+ ~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ A formatter that generates RTF files.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ from collections import OrderedDict
12
+ from pygments.formatter import Formatter
13
+ from pygments.style import _ansimap
14
+ from pygments.util import get_bool_opt, get_int_opt, get_list_opt, surrogatepair
15
+
16
+
17
+ __all__ = ['RtfFormatter']
18
+
19
+
20
+ class RtfFormatter(Formatter):
21
+ """
22
+ Format tokens as RTF markup. This formatter automatically outputs full RTF
23
+ documents with color information and other useful stuff. Perfect for Copy and
24
+ Paste into Microsoft(R) Word(R) documents.
25
+
26
+ Please note that ``encoding`` and ``outencoding`` options are ignored.
27
+ The RTF format is ASCII natively, but handles unicode characters correctly
28
+ thanks to escape sequences.
29
+
30
+ .. versionadded:: 0.6
31
+
32
+ Additional options accepted:
33
+
34
+ `style`
35
+ The style to use, can be a string or a Style subclass (default:
36
+ ``'default'``).
37
+
38
+ `fontface`
39
+ The used font family, for example ``Bitstream Vera Sans``. Defaults to
40
+ some generic font which is supposed to have fixed width.
41
+
42
+ `fontsize`
43
+ Size of the font used. Size is specified in half points. The
44
+ default is 24 half-points, giving a size 12 font.
45
+
46
+ .. versionadded:: 2.0
47
+
48
+ `linenos`
49
+ Turn on line numbering (default: ``False``).
50
+
51
+ .. versionadded:: 2.18
52
+
53
+ `lineno_fontsize`
54
+ Font size for line numbers. Size is specified in half points
55
+ (default: `fontsize`).
56
+
57
+ .. versionadded:: 2.18
58
+
59
+ `lineno_padding`
60
+ Number of spaces between the (inline) line numbers and the
61
+ source code (default: ``2``).
62
+
63
+ .. versionadded:: 2.18
64
+
65
+ `linenostart`
66
+ The line number for the first line (default: ``1``).
67
+
68
+ .. versionadded:: 2.18
69
+
70
+ `linenostep`
71
+ If set to a number n > 1, only every nth line number is printed.
72
+
73
+ .. versionadded:: 2.18
74
+
75
+ `lineno_color`
76
+ Color for line numbers specified as a hex triplet, e.g. ``'5e5e5e'``.
77
+ Defaults to the style's line number color if it is a hex triplet,
78
+ otherwise ansi bright black.
79
+
80
+ .. versionadded:: 2.18
81
+
82
+ `hl_lines`
83
+ Specify a list of lines to be highlighted, as line numbers separated by
84
+ spaces, e.g. ``'3 7 8'``. The line numbers are relative to the input
85
+ (i.e. the first line is line 1) unless `hl_linenostart` is set.
86
+
87
+ .. versionadded:: 2.18
88
+
89
+ `hl_color`
90
+ Color for highlighting the lines specified in `hl_lines`, specified as
91
+ a hex triplet (default: style's `highlight_color`).
92
+
93
+ .. versionadded:: 2.18
94
+
95
+ `hl_linenostart`
96
+ If set to ``True`` line numbers in `hl_lines` are specified
97
+ relative to `linenostart` (default ``False``).
98
+
99
+ .. versionadded:: 2.18
100
+ """
101
+ name = 'RTF'
102
+ aliases = ['rtf']
103
+ filenames = ['*.rtf']
104
+
105
+ def __init__(self, **options):
106
+ r"""
107
+ Additional options accepted:
108
+
109
+ ``fontface``
110
+ Name of the font used. Could for example be ``'Courier New'``
111
+ to further specify the default which is ``'\fmodern'``. The RTF
112
+ specification claims that ``\fmodern`` are "Fixed-pitch serif
113
+ and sans serif fonts". Hope every RTF implementation thinks
114
+ the same about modern...
115
+
116
+ """
117
+ Formatter.__init__(self, **options)
118
+ self.fontface = options.get('fontface') or ''
119
+ self.fontsize = get_int_opt(options, 'fontsize', 0)
120
+ self.linenos = get_bool_opt(options, 'linenos', False)
121
+ self.lineno_fontsize = get_int_opt(options, 'lineno_fontsize',
122
+ self.fontsize)
123
+ self.lineno_padding = get_int_opt(options, 'lineno_padding', 2)
124
+ self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
125
+ self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
126
+ self.hl_linenostart = get_bool_opt(options, 'hl_linenostart', False)
127
+
128
+ self.hl_color = options.get('hl_color', '')
129
+ if not self.hl_color:
130
+ self.hl_color = self.style.highlight_color
131
+
132
+ self.hl_lines = []
133
+ for lineno in get_list_opt(options, 'hl_lines', []):
134
+ try:
135
+ lineno = int(lineno)
136
+ if self.hl_linenostart:
137
+ lineno = lineno - self.linenostart + 1
138
+ self.hl_lines.append(lineno)
139
+ except ValueError:
140
+ pass
141
+
142
+ self.lineno_color = options.get('lineno_color', '')
143
+ if not self.lineno_color:
144
+ if self.style.line_number_color == 'inherit':
145
+ # style color is the css value 'inherit'
146
+ # default to ansi bright-black
147
+ self.lineno_color = _ansimap['ansibrightblack']
148
+ else:
149
+ # style color is assumed to be a hex triplet as other
150
+ # colors in pygments/style.py
151
+ self.lineno_color = self.style.line_number_color
152
+
153
+ self.color_mapping = self._create_color_mapping()
154
+
155
+ def _escape(self, text):
156
+ return text.replace('\\', '\\\\') \
157
+ .replace('{', '\\{') \
158
+ .replace('}', '\\}')
159
+
160
+ def _escape_text(self, text):
161
+ # empty strings, should give a small performance improvement
162
+ if not text:
163
+ return ''
164
+
165
+ # escape text
166
+ text = self._escape(text)
167
+
168
+ buf = []
169
+ for c in text:
170
+ cn = ord(c)
171
+ if cn < (2**7):
172
+ # ASCII character
173
+ buf.append(str(c))
174
+ elif (2**7) <= cn < (2**16):
175
+ # single unicode escape sequence
176
+ buf.append('{\\u%d}' % cn)
177
+ elif (2**16) <= cn:
178
+ # RTF limits unicode to 16 bits.
179
+ # Force surrogate pairs
180
+ buf.append('{\\u%d}{\\u%d}' % surrogatepair(cn))
181
+
182
+ return ''.join(buf).replace('\n', '\\par')
183
+
184
+ @staticmethod
185
+ def hex_to_rtf_color(hex_color):
186
+ if hex_color[0] == "#":
187
+ hex_color = hex_color[1:]
188
+
189
+ return '\\red%d\\green%d\\blue%d;' % (
190
+ int(hex_color[0:2], 16),
191
+ int(hex_color[2:4], 16),
192
+ int(hex_color[4:6], 16)
193
+ )
194
+
195
+ def _split_tokens_on_newlines(self, tokensource):
196
+ """
197
+ Split tokens containing newline characters into multiple token
198
+ each representing a line of the input file. Needed for numbering
199
+ lines of e.g. multiline comments.
200
+ """
201
+ for ttype, value in tokensource:
202
+ if value == '\n':
203
+ yield (ttype, value)
204
+ elif "\n" in value:
205
+ lines = value.split("\n")
206
+ for line in lines[:-1]:
207
+ yield (ttype, line+"\n")
208
+ if lines[-1]:
209
+ yield (ttype, lines[-1])
210
+ else:
211
+ yield (ttype, value)
212
+
213
+ def _create_color_mapping(self):
214
+ """
215
+ Create a mapping of style hex colors to index/offset in
216
+ the RTF color table.
217
+ """
218
+ color_mapping = OrderedDict()
219
+ offset = 1
220
+
221
+ if self.linenos:
222
+ color_mapping[self.lineno_color] = offset
223
+ offset += 1
224
+
225
+ if self.hl_lines:
226
+ color_mapping[self.hl_color] = offset
227
+ offset += 1
228
+
229
+ for _, style in self.style:
230
+ for color in style['color'], style['bgcolor'], style['border']:
231
+ if color and color not in color_mapping:
232
+ color_mapping[color] = offset
233
+ offset += 1
234
+
235
+ return color_mapping
236
+
237
+ @property
238
+ def _lineno_template(self):
239
+ if self.lineno_fontsize != self.fontsize:
240
+ return '{{\\fs{} \\cf{} %s{}}}'.format(self.lineno_fontsize,
241
+ self.color_mapping[self.lineno_color],
242
+ " " * self.lineno_padding)
243
+
244
+ return '{{\\cf{} %s{}}}'.format(self.color_mapping[self.lineno_color],
245
+ " " * self.lineno_padding)
246
+
247
+ @property
248
+ def _hl_open_str(self):
249
+ return rf'{{\highlight{self.color_mapping[self.hl_color]} '
250
+
251
+ @property
252
+ def _rtf_header(self):
253
+ lines = []
254
+ # rtf 1.8 header
255
+ lines.append('{\\rtf1\\ansi\\uc0\\deff0'
256
+ '{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
257
+ % (self.fontface and ' '
258
+ + self._escape(self.fontface) or ''))
259
+
260
+ # color table
261
+ lines.append('{\\colortbl;')
262
+ for color, _ in self.color_mapping.items():
263
+ lines.append(self.hex_to_rtf_color(color))
264
+ lines.append('}')
265
+
266
+ # font and fontsize
267
+ lines.append('\\f0\\sa0')
268
+ if self.fontsize:
269
+ lines.append('\\fs%d' % self.fontsize)
270
+
271
+ # ensure Libre Office Writer imports and renders consecutive
272
+ # space characters the same width, needed for line numbering.
273
+ # https://bugs.documentfoundation.org/show_bug.cgi?id=144050
274
+ lines.append('\\dntblnsbdb')
275
+
276
+ return lines
277
+
278
+ def format_unencoded(self, tokensource, outfile):
279
+ for line in self._rtf_header:
280
+ outfile.write(line + "\n")
281
+
282
+ tokensource = self._split_tokens_on_newlines(tokensource)
283
+
284
+ # first pass of tokens to count lines, needed for line numbering
285
+ if self.linenos:
286
+ line_count = 0
287
+ tokens = [] # for copying the token source generator
288
+ for ttype, value in tokensource:
289
+ tokens.append((ttype, value))
290
+ if value.endswith("\n"):
291
+ line_count += 1
292
+
293
+ # width of line number strings (for padding with spaces)
294
+ linenos_width = len(str(line_count+self.linenostart-1))
295
+
296
+ tokensource = tokens
297
+
298
+ # highlight stream
299
+ lineno = 1
300
+ start_new_line = True
301
+ for ttype, value in tokensource:
302
+ if start_new_line and lineno in self.hl_lines:
303
+ outfile.write(self._hl_open_str)
304
+
305
+ if start_new_line and self.linenos:
306
+ if (lineno-self.linenostart+1)%self.linenostep == 0:
307
+ current_lineno = lineno + self.linenostart - 1
308
+ lineno_str = str(current_lineno).rjust(linenos_width)
309
+ else:
310
+ lineno_str = "".rjust(linenos_width)
311
+ outfile.write(self._lineno_template % lineno_str)
312
+
313
+ while not self.style.styles_token(ttype) and ttype.parent:
314
+ ttype = ttype.parent
315
+ style = self.style.style_for_token(ttype)
316
+ buf = []
317
+ if style['bgcolor']:
318
+ buf.append('\\cb%d' % self.color_mapping[style['bgcolor']])
319
+ if style['color']:
320
+ buf.append('\\cf%d' % self.color_mapping[style['color']])
321
+ if style['bold']:
322
+ buf.append('\\b')
323
+ if style['italic']:
324
+ buf.append('\\i')
325
+ if style['underline']:
326
+ buf.append('\\ul')
327
+ if style['border']:
328
+ buf.append('\\chbrdr\\chcfpat%d' %
329
+ self.color_mapping[style['border']])
330
+ start = ''.join(buf)
331
+ if start:
332
+ outfile.write(f'{{{start} ')
333
+ outfile.write(self._escape_text(value))
334
+ if start:
335
+ outfile.write('}')
336
+ start_new_line = False
337
+
338
+ # complete line of input
339
+ if value.endswith("\n"):
340
+ # close line highlighting
341
+ if lineno in self.hl_lines:
342
+ outfile.write('}')
343
+ # newline in RTF file after closing }
344
+ outfile.write("\n")
345
+
346
+ start_new_line = True
347
+ lineno += 1
348
+
349
+ outfile.write('}\n')
tool_server/.venv/lib/python3.12/site-packages/pygments/formatters/svg.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ pygments.formatters.svg
3
+ ~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ Formatter for SVG output.
6
+
7
+ :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
8
+ :license: BSD, see LICENSE for details.
9
+ """
10
+
11
+ from pygments.formatter import Formatter
12
+ from pygments.token import Comment
13
+ from pygments.util import get_bool_opt, get_int_opt
14
+
15
+ __all__ = ['SvgFormatter']
16
+
17
+
18
+ def escape_html(text):
19
+ """Escape &, <, > as well as single and double quotes for HTML."""
20
+ return text.replace('&', '&amp;'). \
21
+ replace('<', '&lt;'). \
22
+ replace('>', '&gt;'). \
23
+ replace('"', '&quot;'). \
24
+ replace("'", '&#39;')
25
+
26
+
27
+ class2style = {}
28
+
29
+ class SvgFormatter(Formatter):
30
+ """
31
+ Format tokens as an SVG graphics file. This formatter is still experimental.
32
+ Each line of code is a ``<text>`` element with explicit ``x`` and ``y``
33
+ coordinates containing ``<tspan>`` elements with the individual token styles.
34
+
35
+ By default, this formatter outputs a full SVG document including doctype
36
+ declaration and the ``<svg>`` root element.
37
+
38
+ .. versionadded:: 0.9
39
+
40
+ Additional options accepted:
41
+
42
+ `nowrap`
43
+ Don't wrap the SVG ``<text>`` elements in ``<svg><g>`` elements and
44
+ don't add a XML declaration and a doctype. If true, the `fontfamily`
45
+ and `fontsize` options are ignored. Defaults to ``False``.
46
+
47
+ `fontfamily`
48
+ The value to give the wrapping ``<g>`` element's ``font-family``
49
+ attribute, defaults to ``"monospace"``.
50
+
51
+ `fontsize`
52
+ The value to give the wrapping ``<g>`` element's ``font-size``
53
+ attribute, defaults to ``"14px"``.
54
+
55
+ `linenos`
56
+ If ``True``, add line numbers (default: ``False``).
57
+
58
+ `linenostart`
59
+ The line number for the first line (default: ``1``).
60
+
61
+ `linenostep`
62
+ If set to a number n > 1, only every nth line number is printed.
63
+
64
+ `linenowidth`
65
+ Maximum width devoted to line numbers (default: ``3*ystep``, sufficient
66
+ for up to 4-digit line numbers. Increase width for longer code blocks).
67
+
68
+ `xoffset`
69
+ Starting offset in X direction, defaults to ``0``.
70
+
71
+ `yoffset`
72
+ Starting offset in Y direction, defaults to the font size if it is given
73
+ in pixels, or ``20`` else. (This is necessary since text coordinates
74
+ refer to the text baseline, not the top edge.)
75
+
76
+ `ystep`
77
+ Offset to add to the Y coordinate for each subsequent line. This should
78
+ roughly be the text size plus 5. It defaults to that value if the text
79
+ size is given in pixels, or ``25`` else.
80
+
81
+ `spacehack`
82
+ Convert spaces in the source to ``&#160;``, which are non-breaking
83
+ spaces. SVG provides the ``xml:space`` attribute to control how
84
+ whitespace inside tags is handled, in theory, the ``preserve`` value
85
+ could be used to keep all whitespace as-is. However, many current SVG
86
+ viewers don't obey that rule, so this option is provided as a workaround
87
+ and defaults to ``True``.
88
+ """
89
+ name = 'SVG'
90
+ aliases = ['svg']
91
+ filenames = ['*.svg']
92
+
93
+ def __init__(self, **options):
94
+ Formatter.__init__(self, **options)
95
+ self.nowrap = get_bool_opt(options, 'nowrap', False)
96
+ self.fontfamily = options.get('fontfamily', 'monospace')
97
+ self.fontsize = options.get('fontsize', '14px')
98
+ self.xoffset = get_int_opt(options, 'xoffset', 0)
99
+ fs = self.fontsize.strip()
100
+ if fs.endswith('px'):
101
+ fs = fs[:-2].strip()
102
+ try:
103
+ int_fs = int(fs)
104
+ except ValueError:
105
+ int_fs = 20
106
+ self.yoffset = get_int_opt(options, 'yoffset', int_fs)
107
+ self.ystep = get_int_opt(options, 'ystep', int_fs + 5)
108
+ self.spacehack = get_bool_opt(options, 'spacehack', True)
109
+ self.linenos = get_bool_opt(options,'linenos',False)
110
+ self.linenostart = get_int_opt(options,'linenostart',1)
111
+ self.linenostep = get_int_opt(options,'linenostep',1)
112
+ self.linenowidth = get_int_opt(options,'linenowidth', 3*self.ystep)
113
+ self._stylecache = {}
114
+
115
+ def format_unencoded(self, tokensource, outfile):
116
+ """
117
+ Format ``tokensource``, an iterable of ``(tokentype, tokenstring)``
118
+ tuples and write it into ``outfile``.
119
+
120
+ For our implementation we put all lines in their own 'line group'.
121
+ """
122
+ x = self.xoffset
123
+ y = self.yoffset
124
+ if not self.nowrap:
125
+ if self.encoding:
126
+ outfile.write(f'<?xml version="1.0" encoding="{self.encoding}"?>\n')
127
+ else:
128
+ outfile.write('<?xml version="1.0"?>\n')
129
+ outfile.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" '
130
+ '"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/'
131
+ 'svg10.dtd">\n')
132
+ outfile.write('<svg xmlns="http://www.w3.org/2000/svg">\n')
133
+ outfile.write(f'<g font-family="{self.fontfamily}" font-size="{self.fontsize}">\n')
134
+
135
+ counter = self.linenostart
136
+ counter_step = self.linenostep
137
+ counter_style = self._get_style(Comment)
138
+ line_x = x
139
+
140
+ if self.linenos:
141
+ if counter % counter_step == 0:
142
+ outfile.write(f'<text x="{x+self.linenowidth}" y="{y}" {counter_style} text-anchor="end">{counter}</text>')
143
+ line_x += self.linenowidth + self.ystep
144
+ counter += 1
145
+
146
+ outfile.write(f'<text x="{line_x}" y="{y}" xml:space="preserve">')
147
+ for ttype, value in tokensource:
148
+ style = self._get_style(ttype)
149
+ tspan = style and '<tspan' + style + '>' or ''
150
+ tspanend = tspan and '</tspan>' or ''
151
+ value = escape_html(value)
152
+ if self.spacehack:
153
+ value = value.expandtabs().replace(' ', '&#160;')
154
+ parts = value.split('\n')
155
+ for part in parts[:-1]:
156
+ outfile.write(tspan + part + tspanend)
157
+ y += self.ystep
158
+ outfile.write('</text>\n')
159
+ if self.linenos and counter % counter_step == 0:
160
+ outfile.write(f'<text x="{x+self.linenowidth}" y="{y}" text-anchor="end" {counter_style}>{counter}</text>')
161
+
162
+ counter += 1
163
+ outfile.write(f'<text x="{line_x}" y="{y}" ' 'xml:space="preserve">')
164
+ outfile.write(tspan + parts[-1] + tspanend)
165
+ outfile.write('</text>')
166
+
167
+ if not self.nowrap:
168
+ outfile.write('</g></svg>\n')
169
+
170
+ def _get_style(self, tokentype):
171
+ if tokentype in self._stylecache:
172
+ return self._stylecache[tokentype]
173
+ otokentype = tokentype
174
+ while not self.style.styles_token(tokentype):
175
+ tokentype = tokentype.parent
176
+ value = self.style.style_for_token(tokentype)
177
+ result = ''
178
+ if value['color']:
179
+ result = ' fill="#' + value['color'] + '"'
180
+ if value['bold']:
181
+ result += ' font-weight="bold"'
182
+ if value['italic']:
183
+ result += ' font-style="italic"'
184
+ self._stylecache[otokentype] = result
185
+ return result