From f53ac52dcf4e8dd1c8f27005f771ae8da83f3962 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 25 May 2021 11:20:54 +0200 Subject: docs: Use the Cython + IPython lexers that come with Pygments to avoid having to maintain our own ones. --- docs/conf.py | 7 - docs/sphinxext/cython_highlighting.py | 183 ------------------------- docs/sphinxext/ipython_console_highlighting.py | 77 ----------- 3 files changed, 267 deletions(-) delete mode 100644 docs/sphinxext/cython_highlighting.py delete mode 100644 docs/sphinxext/ipython_console_highlighting.py diff --git a/docs/conf.py b/docs/conf.py index a84e0b928..a57788a93 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,11 +21,6 @@ YEAR = datetime.date.today().strftime('%Y') # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('..')) -sys.path.append(os.path.abspath('sphinxext')) - -# Import support for ipython console session syntax highlighting (lives -# in the sphinxext directory defined above) -import ipython_console_highlighting # -- General configuration ----------------------------------------------------- @@ -39,8 +34,6 @@ highlight_language = 'cython' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ - 'ipython_console_highlighting', - 'cython_highlighting', 'sphinx.ext.imgmath', 'sphinx.ext.todo', 'sphinx.ext.intersphinx', diff --git a/docs/sphinxext/cython_highlighting.py b/docs/sphinxext/cython_highlighting.py deleted file mode 100644 index 06e11b891..000000000 --- a/docs/sphinxext/cython_highlighting.py +++ /dev/null @@ -1,183 +0,0 @@ -import re - -from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, \ - LexerContext, include, combined, do_insertions, bygroups, using -from pygments.token import Error, Text, \ - Comment, Operator, Keyword, Name, String, Number, Generic, Punctuation -from pygments.util import get_bool_opt, get_list_opt, shebang_matches -from pygments import unistring as uni - -from sphinx import highlighting - - -line_re = re.compile('.*?\n') - -class CythonLexer(RegexLexer): - """ - For `Cython `_ source code. - """ - - name = 'Cython' - aliases = ['cython', 'pyx'] - filenames = ['*.pyx', '*.pxd', '*.pxi'] - mimetypes = ['text/x-cython', 'application/x-cython'] - - tokens = { - 'root': [ - (r'\n', Text), - (r'^(\s*)("""(?:.|\n)*?""")', bygroups(Text, String.Doc)), - (r"^(\s*)('''(?:.|\n)*?''')", bygroups(Text, String.Doc)), - (r'[^\S\n]+', Text), - (r'#.*$', Comment), - (r'[]{}:(),;[]', Punctuation), - (r'\\\n', Text), - (r'\\', Text), - (r'(in|is|and|or|not)\b', Operator.Word), - (r'(<)([a-zA-Z0-9.?]+)(>)', - bygroups(Punctuation, Keyword.Type, Punctuation)), - (r'!=|==|<<|>>|[-~+/*%=<>&^|.?]', Operator), - (r'(from)(\d+)(<=)(\s+)(<)(\d+)(:)', - bygroups(Keyword, Number.Integer, Operator, Name, Operator, - Name, Punctuation)), - include('keywords'), - (r'(def|property)(\s+)', bygroups(Keyword, Text), 'funcname'), - (r'(cp?def)(\s+)', bygroups(Keyword, Text), 'cdef'), - (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'classname'), - (r'(from)(\s+)', bygroups(Keyword, Text), 'fromimport'), - (r'(c?import)(\s+)', bygroups(Keyword, Text), 'import'), - include('builtins'), - include('backtick'), - ('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'), - ("(?:[rR]|[uU][rR]|[rR][uU])'''", String, 'tsqs'), - ('(?:[rR]|[uU][rR]|[rR][uU])"', String, 'dqs'), - ("(?:[rR]|[uU][rR]|[rR][uU])'", String, 'sqs'), - ('[uU]?"""', String, combined('stringescape', 'tdqs')), - ("[uU]?'''", String, combined('stringescape', 'tsqs')), - ('[uU]?"', String, combined('stringescape', 'dqs')), - ("[uU]?'", String, combined('stringescape', 'sqs')), - include('name'), - include('numbers'), - ], - 'keywords': [ - (r'(assert|break|by|continue|ctypedef|del|elif|else|except\??|exec|' - r'finally|for|gil|global|if|include|lambda|nogil|pass|print|raise|' - r'return|try|while|yield|as|with)\b', Keyword), - (r'(DEF|IF|ELIF|ELSE)\b', Comment.Preproc), - ], - 'builtins': [ - (r'(?