|
9 | 9 | from pygments.formatters.terminal import TerminalFormatter
|
10 | 10 | from pygments.formatters.terminal256 import Terminal256Formatter
|
11 | 11 | from pygments.lexer import Lexer
|
| 12 | +from pygments.lexers.data import JsonLexer |
12 | 13 | from pygments.lexers.special import TextLexer
|
13 | 14 | from pygments.lexers.text import HttpLexer as PygmentsHttpLexer
|
14 | 15 | from pygments.util import ClassNotFound
|
15 | 16 |
|
| 17 | +from ..lexers.json import EnhancedJsonLexer |
16 | 18 | from ...compat import is_windows
|
17 | 19 | from ...context import Environment
|
18 | 20 | from ...plugins import FormatterPlugin
|
@@ -60,6 +62,7 @@ def __init__(
|
60 | 62 | http_lexer = PygmentsHttpLexer()
|
61 | 63 | formatter = TerminalFormatter()
|
62 | 64 | else:
|
| 65 | + from ..lexers.http import SimplifiedHTTPLexer |
63 | 66 | http_lexer = SimplifiedHTTPLexer()
|
64 | 67 | formatter = Terminal256Formatter(
|
65 | 68 | style=self.get_style_class(color_scheme)
|
@@ -151,55 +154,12 @@ def get_lexer(
|
151 | 154 | else:
|
152 | 155 | lexer = pygments.lexers.get_lexer_by_name('json')
|
153 | 156 |
|
154 |
| - return lexer |
155 |
| - |
156 |
| - |
157 |
| -class SimplifiedHTTPLexer(pygments.lexer.RegexLexer): |
158 |
| - """Simplified HTTP lexer for Pygments. |
159 |
| -
|
160 |
| - It only operates on headers and provides a stronger contrast between |
161 |
| - their names and values than the original one bundled with Pygments |
162 |
| - (:class:`pygments.lexers.text import HttpLexer`), especially when |
163 |
| - Solarized color scheme is used. |
| 157 | + # Use our own JSON lexer: it supports JSON bodies preceded by non-JSON data |
| 158 | + # as well as legit JSON bodies. |
| 159 | + if isinstance(lexer, JsonLexer): |
| 160 | + lexer = EnhancedJsonLexer() |
164 | 161 |
|
165 |
| - """ |
166 |
| - name = 'HTTP' |
167 |
| - aliases = ['http'] |
168 |
| - filenames = ['*.http'] |
169 |
| - tokens = { |
170 |
| - 'root': [ |
171 |
| - # Request-Line |
172 |
| - (r'([A-Z]+)( +)([^ ]+)( +)(HTTP)(/)(\d+\.\d+)', |
173 |
| - pygments.lexer.bygroups( |
174 |
| - pygments.token.Name.Function, |
175 |
| - pygments.token.Text, |
176 |
| - pygments.token.Name.Namespace, |
177 |
| - pygments.token.Text, |
178 |
| - pygments.token.Keyword.Reserved, |
179 |
| - pygments.token.Operator, |
180 |
| - pygments.token.Number |
181 |
| - )), |
182 |
| - # Response Status-Line |
183 |
| - (r'(HTTP)(/)(\d+\.\d+)( +)(\d{3})( +)(.+)', |
184 |
| - pygments.lexer.bygroups( |
185 |
| - pygments.token.Keyword.Reserved, # 'HTTP' |
186 |
| - pygments.token.Operator, # '/' |
187 |
| - pygments.token.Number, # Version |
188 |
| - pygments.token.Text, |
189 |
| - pygments.token.Number, # Status code |
190 |
| - pygments.token.Text, |
191 |
| - pygments.token.Name.Exception, # Reason |
192 |
| - )), |
193 |
| - # Header |
194 |
| - (r'(.*?)( *)(:)( *)(.+)', pygments.lexer.bygroups( |
195 |
| - pygments.token.Name.Attribute, # Name |
196 |
| - pygments.token.Text, |
197 |
| - pygments.token.Operator, # Colon |
198 |
| - pygments.token.Text, |
199 |
| - pygments.token.String # Value |
200 |
| - )) |
201 |
| - ] |
202 |
| - } |
| 162 | + return lexer |
203 | 163 |
|
204 | 164 |
|
205 | 165 | class Solarized256Style(pygments.style.Style):
|
|
0 commit comments