3 pygments.lexers.email |
3 pygments.lexers.email |
4 ~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexer for the raw E-mail. |
6 Lexer for the raw E-mail. |
7 |
7 |
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 from pygments.lexer import RegexLexer, DelegatingLexer, bygroups |
12 from pygments.lexer import RegexLexer, DelegatingLexer, bygroups |
13 from pygments.lexers.mime import MIMELexer |
13 from pygments.lexers.mime import MIMELexer |
23 |
23 |
24 .. versionadded:: 2.5 |
24 .. versionadded:: 2.5 |
25 """ |
25 """ |
26 |
26 |
27 def __init__(self, **options): |
27 def __init__(self, **options): |
28 super(EmailHeaderLexer, self).__init__(**options) |
28 super().__init__(**options) |
29 self.highlight_x = get_bool_opt(options, "highlight-X-header", False) |
29 self.highlight_x = get_bool_opt(options, "highlight-X-header", False) |
30 |
30 |
31 def get_x_header_tokens(self, match): |
31 def get_x_header_tokens(self, match): |
32 if self.highlight_x: |
32 if self.highlight_x: |
33 # field |
33 # field |
34 yield match.start(1), Name.Tag, match.group(1) |
34 yield match.start(1), Name.Tag, match.group(1) |
35 |
35 |
36 # content |
36 # content |
37 default_actions = self.get_tokens_unprocessed( |
37 default_actions = self.get_tokens_unprocessed( |
38 match.group(2), stack=("root", "header")) |
38 match.group(2), stack=("root", "header")) |
39 for item in default_actions: |
39 yield from default_actions |
40 yield item |
|
41 else: |
40 else: |
42 # lowlight |
41 # lowlight |
43 yield match.start(1), Comment.Special, match.group(1) |
42 yield match.start(1), Comment.Special, match.group(1) |
44 yield match.start(2), Comment.Multiline, match.group(2) |
43 yield match.start(2), Comment.Multiline, match.group(2) |
45 |
44 |
147 aliases = ["email", "eml"] |
146 aliases = ["email", "eml"] |
148 filenames = ["*.eml"] |
147 filenames = ["*.eml"] |
149 mimetypes = ["message/rfc822"] |
148 mimetypes = ["message/rfc822"] |
150 |
149 |
151 def __init__(self, **options): |
150 def __init__(self, **options): |
152 super(EmailLexer, self).__init__( |
151 super().__init__(EmailHeaderLexer, MIMELexer, Comment, **options) |
153 EmailHeaderLexer, MIMELexer, Comment, **options |
|
154 ) |
|