From 791b137525a1d4dc1e7638a94c43526eeac0efd6 Mon Sep 17 00:00:00 2001 From: JinWang An Date: Tue, 5 Jan 2021 12:19:07 +0900 Subject: [PATCH] Imported Upstream version 2.4.1 --- CHANGES | 17 +++++++++++++++++ PKG-INFO | 29 +++++++++++++++-------------- Pygments.egg-info/PKG-INFO | 29 +++++++++++++++-------------- Pygments.egg-info/SOURCES.txt | 1 + pygments/__init__.py | 2 +- pygments/console.py | 2 +- pygments/formatters/html.py | 11 ++++++++--- pygments/lexers/_mapping.py | 4 ++-- pygments/lexers/asm.py | 6 ++++-- pygments/lexers/basic.py | 2 +- pygments/lexers/dotnet.py | 9 +++------ pygments/lexers/javascript.py | 2 +- pygments/lexers/objective.py | 2 +- pygments/lexers/prolog.py | 1 - pygments/lexers/shell.py | 2 +- pygments/lexers/theorem.py | 2 -- pygments/style.py | 4 +++- setup.py | 31 ++++++++++++++++--------------- tests/test_asm.py | 30 ++++++++++++++++++++++++++++++ tests/test_objectiveclexer.py | 13 ++++++++++++- tests/test_shell.py | 19 ++++++++++++++++++- tests/test_terminal_formatter.py | 10 +++++----- 22 files changed, 155 insertions(+), 73 deletions(-) create mode 100644 tests/test_asm.py diff --git a/CHANGES b/CHANGES index 9ebde07..2ecbb94 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,23 @@ Issue numbers refer to the tracker at pull request numbers to the requests at . +Version 2.4.1 +------------- +(released May 24, 2019) + +- Updated lexers: + + * Coq (#1430) + * MSDOS Session (PR#734) + * NASM (#1517) + * Objective-C (PR#813, #1508) + * Prolog (#1511) + * TypeScript (#1515) + +- Support CSS variables in stylesheets (PR#814, #1356) +- Fix F# lexer name (PR#709) +- Fix ``TerminalFormatter`` using bold for bright text (#1480) + Version 2.4.0 ------------- (released May 8, 2019) diff --git a/PKG-INFO b/PKG-INFO index e4f2e97..9e2824e 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,28 +1,29 @@ Metadata-Version: 1.2 Name: Pygments -Version: 2.4.0 +Version: 2.4.1 Summary: Pygments is a syntax highlighting package written in Python. Home-page: http://pygments.org/ Author: Georg Brandl Author-email: georg@python.org License: BSD License -Description: Pygments - ~~~~~~~~ +Description: + Pygments + ~~~~~~~~ - Pygments is a syntax highlighting package written in Python. + Pygments is a syntax highlighting package written in Python. - It is a generic syntax highlighter suitable for use in code hosting, forums, - wikis or other applications that need to prettify source code. Highlights - are: + It is a generic syntax highlighter suitable for use in code hosting, forums, + wikis or other applications that need to prettify source code. Highlights + are: - * a wide range of over 300 languages and other text formats is supported - * special attention is paid to details, increasing quality by a fair amount - * support for new languages and formats are added easily - * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences - * it is usable as a command-line tool and as a library + * a wide range of over 300 languages and other text formats is supported + * special attention is paid to details, increasing quality by a fair amount + * support for new languages and formats are added easily + * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences + * it is usable as a command-line tool and as a library - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. Keywords: syntax highlighting Platform: any diff --git a/Pygments.egg-info/PKG-INFO b/Pygments.egg-info/PKG-INFO index e4f2e97..9e2824e 100644 --- a/Pygments.egg-info/PKG-INFO +++ b/Pygments.egg-info/PKG-INFO @@ -1,28 +1,29 @@ Metadata-Version: 1.2 Name: Pygments -Version: 2.4.0 +Version: 2.4.1 Summary: Pygments is a syntax highlighting package written in Python. Home-page: http://pygments.org/ Author: Georg Brandl Author-email: georg@python.org License: BSD License -Description: Pygments - ~~~~~~~~ +Description: + Pygments + ~~~~~~~~ - Pygments is a syntax highlighting package written in Python. + Pygments is a syntax highlighting package written in Python. - It is a generic syntax highlighter suitable for use in code hosting, forums, - wikis or other applications that need to prettify source code. Highlights - are: + It is a generic syntax highlighter suitable for use in code hosting, forums, + wikis or other applications that need to prettify source code. Highlights + are: - * a wide range of over 300 languages and other text formats is supported - * special attention is paid to details, increasing quality by a fair amount - * support for new languages and formats are added easily - * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences - * it is usable as a command-line tool and as a library + * a wide range of over 300 languages and other text formats is supported + * special attention is paid to details, increasing quality by a fair amount + * support for new languages and formats are added easily + * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image formats that PIL supports and ANSI sequences + * it is usable as a command-line tool and as a library - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. Keywords: syntax highlighting Platform: any diff --git a/Pygments.egg-info/SOURCES.txt b/Pygments.egg-info/SOURCES.txt index 27d0122..0500f8e 100644 --- a/Pygments.egg-info/SOURCES.txt +++ b/Pygments.egg-info/SOURCES.txt @@ -397,6 +397,7 @@ scripts/vim2pygments.py tests/run.py tests/string_asserts.py tests/support.py +tests/test_asm.py tests/test_basic.py tests/test_basic_api.py tests/test_bibtex.py diff --git a/pygments/__init__.py b/pygments/__init__.py index 0da0649..f0043e5 100644 --- a/pygments/__init__.py +++ b/pygments/__init__.py @@ -29,7 +29,7 @@ import sys from pygments.util import StringIO, BytesIO -__version__ = '2.4.0' +__version__ = '2.4.1' __docformat__ = 'restructuredtext' __all__ = ['lex', 'format', 'highlight'] diff --git a/pygments/console.py b/pygments/console.py index e61744c..e9f30ad 100644 --- a/pygments/console.py +++ b/pygments/console.py @@ -30,7 +30,7 @@ light_colors = ["brightblack", "brightred", "brightgreen", "brightyellow", "brig x = 30 for d, l in zip(dark_colors, light_colors): codes[d] = esc + "%im" % x - codes[l] = esc + "%i;01m" % x + codes[l] = esc + "%im" % (60 + x) x += 1 del d, l, x diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index 99ab837..d65c09c 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -41,6 +41,11 @@ def escape_html(text, table=_escape_html_table): """Escape &, <, > as well as single and double quotes for HTML.""" return text.translate(table) +def webify(color): + if color.startswith('calc') or color.startswith('var'): + return color + else: + return '#' + color def _get_ttype_class(ttype): fname = STANDARD_TYPES.get(ttype) @@ -467,7 +472,7 @@ class HtmlFormatter(Formatter): name = self._get_css_class(ttype) style = '' if ndef['color']: - style += 'color: #%s; ' % ndef['color'] + style += 'color: %s; ' % webify(ndef['color']) if ndef['bold']: style += 'font-weight: bold; ' if ndef['italic']: @@ -475,9 +480,9 @@ class HtmlFormatter(Formatter): if ndef['underline']: style += 'text-decoration: underline; ' if ndef['bgcolor']: - style += 'background-color: #%s; ' % ndef['bgcolor'] + style += 'background-color: %s; ' % webify(ndef['bgcolor']) if ndef['border']: - style += 'border: 1px solid #%s; ' % ndef['border'] + style += 'border: 1px solid %s; ' % webify(ndef['border']) if style: t2c[ttype] = name # save len(ttype) to enable ordering the styles by diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index e4e8cf4..ce1b6df 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -153,7 +153,7 @@ LEXERS = { 'EvoqueLexer': ('pygments.lexers.templates', 'Evoque', ('evoque',), ('*.evoque',), ('application/x-evoque',)), 'EvoqueXmlLexer': ('pygments.lexers.templates', 'XML+Evoque', ('xml+evoque',), ('*.xml',), ('application/xml+evoque',)), 'EzhilLexer': ('pygments.lexers.ezhil', 'Ezhil', ('ezhil',), ('*.n',), ('text/x-ezhil',)), - 'FSharpLexer': ('pygments.lexers.dotnet', 'FSharp', ('fsharp',), ('*.fs', '*.fsi'), ('text/x-fsharp',)), + 'FSharpLexer': ('pygments.lexers.dotnet', 'F#', ('fsharp', 'f#'), ('*.fs', '*.fsi'), ('text/x-fsharp',)), 'FactorLexer': ('pygments.lexers.factor', 'Factor', ('factor',), ('*.factor',), ('text/x-factor',)), 'FancyLexer': ('pygments.lexers.ruby', 'Fancy', ('fancy', 'fy'), ('*.fy', '*.fancypack'), ('text/x-fancysrc',)), 'FantomLexer': ('pygments.lexers.fantom', 'Fantom', ('fan',), ('*.fan',), ('application/x-fantom',)), @@ -442,7 +442,7 @@ LEXERS = { 'UcodeLexer': ('pygments.lexers.unicon', 'ucode', ('ucode',), ('*.u', '*.u1', '*.u2'), ()), 'UniconLexer': ('pygments.lexers.unicon', 'Unicon', ('unicon',), ('*.icn',), ('text/unicon',)), 'UrbiscriptLexer': ('pygments.lexers.urbi', 'UrbiScript', ('urbiscript',), ('*.u',), ('application/x-urbiscript',)), - 'VBScriptLexer': ('pygments.lexers.basic', 'VBScript', (), ('*.vbs', '*.VBS'), ()), + 'VBScriptLexer': ('pygments.lexers.basic', 'VBScript', ('vbscript',), ('*.vbs', '*.VBS'), ()), 'VCLLexer': ('pygments.lexers.varnish', 'VCL', ('vcl',), ('*.vcl',), ('text/x-vclsrc',)), 'VCLSnippetLexer': ('pygments.lexers.varnish', 'VCLSnippets', ('vclsnippets', 'vclsnippet'), (), ('text/x-vclsnippet',)), 'VCTreeStatusLexer': ('pygments.lexers.console', 'VCTreeStatus', ('vctreestatus',), (), ()), diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py index b522450..3d2933d 100644 --- a/pygments/lexers/asm.py +++ b/pygments/lexers/asm.py @@ -468,9 +468,11 @@ class NasmLexer(RegexLexer): r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]') wordop = r'seg|wrt|strict' type = r'byte|[dq]?word' - directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|' + # Directives must be followed by whitespace, otherwise CPU will match + # cpuid for instance. + directives = (r'(?:BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|' r'ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|' - r'EXPORT|LIBRARY|MODULE') + r'EXPORT|LIBRARY|MODULE)\s+') flags = re.IGNORECASE | re.MULTILINE tokens = { diff --git a/pygments/lexers/basic.py b/pygments/lexers/basic.py index 1aa3274..f93d6d5 100644 --- a/pygments/lexers/basic.py +++ b/pygments/lexers/basic.py @@ -510,7 +510,7 @@ class VBScriptLexer(RegexLexer): .. versionadded:: 2.4 """ name = 'VBScript' - aliases = [] + aliases = ['vbscript'] filenames = ['*.vbs', '*.VBS'] flags = re.IGNORECASE diff --git a/pygments/lexers/dotnet.py b/pygments/lexers/dotnet.py index 27ae77c..1d3b1f3 100644 --- a/pygments/lexers/dotnet.py +++ b/pygments/lexers/dotnet.py @@ -541,16 +541,13 @@ class VbNetAspxLexer(DelegatingLexer): # Very close to functional.OcamlLexer class FSharpLexer(RegexLexer): """ - For the F# language (version 3.0). - - AAAAACK Strings - http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html#_Toc335818775 + For the `F# language `_ (version 3.0). .. versionadded:: 1.5 """ - name = 'FSharp' - aliases = ['fsharp'] + name = 'F#' + aliases = ['fsharp', 'f#'] filenames = ['*.fs', '*.fsi'] mimetypes = ['text/x-fsharp'] diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py index 0507375..57e1161 100644 --- a/pygments/lexers/javascript.py +++ b/pygments/lexers/javascript.py @@ -482,7 +482,7 @@ class TypeScriptLexer(RegexLexer): (r'[{(\[;,]', Punctuation, 'slashstartsregex'), (r'[})\].]', Punctuation), (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' - r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|void|of|' r'this)\b', Keyword, 'slashstartsregex'), (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' diff --git a/pygments/lexers/objective.py b/pygments/lexers/objective.py index 179928e..1be28c5 100644 --- a/pygments/lexers/objective.py +++ b/pygments/lexers/objective.py @@ -66,7 +66,7 @@ def objective(baselexer): 'copy', 'retain', 'assign', 'unsafe_unretained', 'atomic', 'nonatomic', 'readonly', 'readwrite', 'setter', 'getter', 'typeof', 'in', 'out', 'inout', 'release', 'class', '@dynamic', '@optional', - '@required', '@autoreleasepool'), suffix=r'\b'), + '@required', '@autoreleasepool', '@import'), suffix=r'\b'), Keyword), (words(('id', 'instancetype', 'Class', 'IMP', 'SEL', 'BOOL', 'IBOutlet', 'IBAction', 'unichar'), suffix=r'\b'), diff --git a/pygments/lexers/prolog.py b/pygments/lexers/prolog.py index 58e762b..daf8db9 100644 --- a/pygments/lexers/prolog.py +++ b/pygments/lexers/prolog.py @@ -31,7 +31,6 @@ class PrologLexer(RegexLexer): tokens = { 'root': [ - (r'^#.*', Comment.Single), (r'/\*', Comment.Multiline, 'nested-comment'), (r'%.*', Comment.Single), # character literal diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py index 31bc7e9..9fd6bf2 100644 --- a/pygments/lexers/shell.py +++ b/pygments/lexers/shell.py @@ -540,7 +540,7 @@ class MSDOSSessionLexer(ShellSessionBaseLexer): mimetypes = [] _innerLexerCls = BatchLexer - _ps1rgx = r'^([^>]+>)(.*\n?)' + _ps1rgx = r'^([^>]*>)(.*\n?)' _ps2 = 'More? ' diff --git a/pygments/lexers/theorem.py b/pygments/lexers/theorem.py index e84a398..e7619c3 100644 --- a/pygments/lexers/theorem.py +++ b/pygments/lexers/theorem.py @@ -98,7 +98,6 @@ class CoqLexer(RegexLexer): operators = r'[!$%&*+\./:<=>?@^|~-]' prefix_syms = r'[!?~]' infix_syms = r'[=<>@^|&+\*/$%-]' - primitives = ('unit', 'nat', 'bool', 'string', 'ascii', 'list') tokens = { 'root': [ @@ -115,7 +114,6 @@ class CoqLexer(RegexLexer): (r'\b([A-Z][\w\']*)', Name), (r'(%s)' % '|'.join(keyopts[::-1]), Operator), (r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator), - (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type), (r"[^\W\d][\w']*", Name), diff --git a/pygments/style.py b/pygments/style.py index 89766d8..aee23f9 100644 --- a/pygments/style.py +++ b/pygments/style.py @@ -73,9 +73,11 @@ class StyleMeta(type): if len(col) == 6: return col elif len(col) == 3: - return col[0]*2 + col[1]*2 + col[2]*2 + return col[0] * 2 + col[1] * 2 + col[2] * 2 elif text == '': return '' + elif text.startswith('var') or text.startswith('calc'): + return text assert False, "wrong color format %r" % text _styles = obj._styles = {} diff --git a/setup.py b/setup.py index bd54b0f..98259f5 100755 --- a/setup.py +++ b/setup.py @@ -1,23 +1,24 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -"""Pygments - ~~~~~~~~ +""" +Pygments +~~~~~~~~ - Pygments is a syntax highlighting package written in Python. +Pygments is a syntax highlighting package written in Python. - It is a generic syntax highlighter suitable for use in code hosting, forums, - wikis or other applications that need to prettify source code. Highlights - are: +It is a generic syntax highlighter suitable for use in code hosting, forums, +wikis or other applications that need to prettify source code. Highlights +are: - * a wide range of over 300 languages and other text formats is supported - * special attention is paid to details, increasing quality by a fair amount - * support for new languages and formats are added easily - * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image \ - formats that PIL supports and ANSI sequences - * it is usable as a command-line tool and as a library +* a wide range of over 300 languages and other text formats is supported +* special attention is paid to details, increasing quality by a fair amount +* support for new languages and formats are added easily +* a number of output formats, presently HTML, LaTeX, RTF, SVG, all image \ + formats that PIL supports and ANSI sequences +* it is usable as a command-line tool and as a library - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. +:copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. +:license: BSD, see LICENSE for details. """ try: @@ -48,7 +49,7 @@ else: setup( name = 'Pygments', - version = '2.4.0', + version = '2.4.1', url = 'http://pygments.org/', license = 'BSD License', author = 'Georg Brandl', diff --git a/tests/test_asm.py b/tests/test_asm.py new file mode 100644 index 0000000..8eaed24 --- /dev/null +++ b/tests/test_asm.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +""" + Basic ColdfusionHtmlLexer Test + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest +import os + +from pygments.token import Token +from pygments.lexers import NasmLexer + + +class NasmLexerTest(unittest.TestCase): + + def setUp(self): + self.lexer = NasmLexer() + + def testCPUID(self): + # CPU is a valid directive, and we don't want to parse this as + # cpu id, but as a single token. See bug #1517 + fragment = 'cpuid' + expected = [ + (Token.Name.Function, u'cpuid'), + (Token.Text, u'\n'), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) diff --git a/tests/test_objectiveclexer.py b/tests/test_objectiveclexer.py index aee7db6..faadb08 100644 --- a/tests/test_objectiveclexer.py +++ b/tests/test_objectiveclexer.py @@ -69,7 +69,7 @@ class ObjectiveCLexerTest(unittest.TestCase): ] self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) - def testLieralNumberBoolExpression(self): + def testLiteralNumberBoolExpression(self): fragment = u'@(YES);\n' expected = [ (Token.Literal, u'@('), @@ -79,3 +79,14 @@ class ObjectiveCLexerTest(unittest.TestCase): (Token.Text, u'\n'), ] self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) + + def testModuleImport(self): + fragment = u'@import ModuleA;\n' + expected = [ + (Token.Keyword, u'@import'), + (Token.Text, u' '), + (Token.Name, u'ModuleA'), + (Token.Punctuation, u';'), + (Token.Text, u'\n'), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) diff --git a/tests/test_shell.py b/tests/test_shell.py index e283793..1121240 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -10,7 +10,7 @@ import unittest from pygments.token import Token -from pygments.lexers import BashLexer, BashSessionLexer +from pygments.lexers import BashLexer, BashSessionLexer, MSDOSSessionLexer class BashTest(unittest.TestCase): @@ -140,3 +140,20 @@ class BashSessionTest(unittest.TestCase): ] self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) +class MSDOSSessionTest(unittest.TestCase): + + def setUp(self): + self.lexer = MSDOSSessionLexer() + + def testGtOnlyPrompt(self): + fragment = u'> py\nhi\n' + tokens = [ + (Token.Text, u''), + (Token.Generic.Prompt, u'>'), + (Token.Text, u' '), + (Token.Text, u'py'), + (Token.Text, u''), + (Token.Text, u'\n'), + (Token.Generic.Output, u'hi\n'), + ] + self.assertEqual(tokens, list(self.lexer.get_tokens(fragment))) diff --git a/tests/test_terminal_formatter.py b/tests/test_terminal_formatter.py index 1f44807..acc1516 100644 --- a/tests/test_terminal_formatter.py +++ b/tests/test_terminal_formatter.py @@ -90,13 +90,13 @@ async def function(a,b,c, *d, **kwarg:Bool)->Bool: def test_256esc_seq(self): """ - test that a few escape sequences are actualy used when using ansi<> color codes + test that a few escape sequences are actually used when using ansi<> color codes """ def termtest(x): return highlight(x, Python3Lexer(), Terminal256Formatter(style=MyStyle)) - self.assertTrue('32;41' in termtest('0x123')) - self.assertTrue('32;42' in termtest('123')) - self.assertTrue('30;01' in termtest('#comment')) - self.assertTrue('34;41' in termtest('"String"')) + self.assertTrue('32;101' in termtest('0x123')) + self.assertTrue('92;42' in termtest('123')) + self.assertTrue('90' in termtest('#comment')) + self.assertTrue('94;41' in termtest('"String"')) -- 2.34.1