diff options
| author | Matthäus G. Chajdas <dev@anteru.net> | 2021-08-08 16:29:55 +0200 |
|---|---|---|
| committer | Matthäus G. Chajdas <dev@anteru.net> | 2021-08-08 16:29:55 +0200 |
| commit | 215eeefbba0ba5b22151cfce6d0bbe6042986ce1 (patch) | |
| tree | f7ab8ae5c663334131052819819be545c7c01156 /pygments/lexers | |
| parent | 698007e1f374b3603ce488685aaf120fa13382ff (diff) | |
| parent | 6e60767915b2dd8d662a5304ce9192a33097aba5 (diff) | |
| download | pygments-git-215eeefbba0ba5b22151cfce6d0bbe6042986ce1.tar.gz | |
Merge branch 'feat/ascii-armored' of https://github.com/scop/pygments into scop-feat/ascii-armored
Diffstat (limited to 'pygments/lexers')
| -rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
| -rw-r--r-- | pygments/lexers/asc.py | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 4dc2615c..0e906c1d 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -41,6 +41,7 @@ LEXERS = { 'AppleScriptLexer': ('pygments.lexers.scripting', 'AppleScript', ('applescript',), ('*.applescript',), ()), 'ArduinoLexer': ('pygments.lexers.c_like', 'Arduino', ('arduino',), ('*.ino',), ('text/x-arduino',)), 'ArrowLexer': ('pygments.lexers.arrow', 'Arrow', ('arrow',), ('*.arw',), ()), + 'AscLexer': ('pygments.lexers.asc', 'ASCII armored', ('asc', 'pem'), ('*.asc', '*.pem', 'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', 'id_rsa'), ('application/pgp-keys', 'application/pgp-encrypted', 'application/pgp-signature')), 'AspectJLexer': ('pygments.lexers.jvm', 'AspectJ', ('aspectj',), ('*.aj',), ('text/x-aspectj',)), 'AsymptoteLexer': ('pygments.lexers.graphics', 'Asymptote', ('asymptote', 'asy'), ('*.asy',), ('text/x-asymptote',)), 'AugeasLexer': ('pygments.lexers.configs', 'Augeas', ('augeas',), ('*.aug',), ()), diff --git a/pygments/lexers/asc.py b/pygments/lexers/asc.py new file mode 100644 index 00000000..f775fd07 --- /dev/null +++ b/pygments/lexers/asc.py @@ -0,0 +1,51 @@ +""" + pygments.lexers.asc + ~~~~~~~~~~~~~~~~~~~ + + Lexer for various ASCII armored files. + + :copyright: Copyright 2021 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +import re + +from pygments.lexer import RegexLexer, bygroups +from pygments.token import Comment, Generic, Name, Operator, String, Whitespace + +__all__ = ['AscLexer'] + + +class AscLexer(RegexLexer): + """ + Lexer for ASCII armored files, containing `-----BEGIN/END ...-----` wrapped base64 data. + + .. versionadded:: 2.10 + """ + name = 'ASCII armored' + aliases = ['asc', 'pem'] + filenames = [ + '*.asc', # PGP; *.gpg, *.pgp, and *.sig too, but those can be binary + '*.pem', # X.509; *.cer, *.crt, *.csr, and key etc too, but those can be binary + 'id_dsa', 'id_ecdsa', 'id_ecdsa_sk', 'id_ed25519', 'id_ed25519_sk', 'id_rsa', # SSH private keys + ] + mimetypes = ['application/pgp-keys', 'application/pgp-encrypted', 'application/pgp-signature'] + + flags = re.MULTILINE + + tokens = { + 'root': [ + (r'\s+', Whitespace), + (r'^-----BEGIN [^\n]+-----$', Generic.Heading, 'data'), + (r'\S+', Comment), + ], + 'data': [ + (r'\s+', Whitespace), + (r'^([^:]+)(:)([ \t]+)(.*)', bygroups(Name.Attribute, Operator, Whitespace, String)), + (r'^-----END [^\n]+-----$', Generic.Heading, 'root'), + (r'\S+', String), + ], + } + + def analyse_text(text): + if re.search(r'^-----BEGIN [^\n]+-----\r?\n', text): + return True |
